Python Tensorboard语法错误:无效语法

Python Tensorboard语法错误:无效语法,python,path,tensorflow,tensorboard,Python,Path,Tensorflow,Tensorboard,当我尝试制作tensorboard时,语法错误出现了。尽管有开源代码,我还是无法理解。我试图搜索tensorboard的代码,但不清楚 就连我也不擅长python。我这样写路径,C:\\Users\\jh902\\Documents\\.logs,因为我使用的是Windows 10,但我不确定。(我使用了双反斜杠,但在这个监视器中它看起来像一个斜杠) 如果我这样编码 tensorboard --logdir="C:\Users\\jh902\\Documents\\.logs" this err

当我尝试制作tensorboard时,语法错误出现了。尽管有开源代码,我还是无法理解。我试图搜索tensorboard的代码,但不清楚

就连我也不擅长python。我这样写路径,
C:\\Users\\jh902\\Documents\\.logs
,因为我使用的是Windows 10,但我不确定。(我使用了双反斜杠,但在这个监视器中它看起来像一个斜杠)

如果我这样编码

tensorboard --logdir="C:\Users\\jh902\\Documents\\.logs"
this error message comes out
  File "<ipython-input-32-4b130bd6177b>", line 1
    tensorboard --logdir="C:\Users\\jh902\\Documents\\.logs"
                                                            ^
SyntaxError: can't assign to operator
tensorboard--logdir=“C:\Users\\jh902\\Documents\\.logs”
此错误消息将显示
文件“”,第1行
tensorboard--logdir=“C:\Users\\jh902\\Documents\\.logs”
^
SyntaxError:无法分配给运算符
有什么问题吗

# cost/loss function
cost = tf.reduce_mean(tf.square(hypothesis - Y))

# Minimize/Optimizer
optimizer = tf.train.AdamOptimizer(learning_rate=1e-5)
train = optimizer.minimize(cost)

# Launch the graph in a session.
sess = tf.Session()

w2_hist=tf.summary.histogram("weight2",W2)
cost_summ=tf.summary.scalar("cost",cost)

summary=tf.summary.merge_all()

#Create Summary writer
writer=tf.summary.FileWriter("C:\\Users\\jh902\\Documents\\.logs")
writer.add_graph(sess.graph)

# Initializes global variables in the graph.
sess.run(tf.global_variables_initializer())

# Fit the Line with new training data
for step in range(1001):
    s, cost_val, hy_val, _ = sess.run([summary, cost, hypothesis, train], feed_dict={X: x_data, Y: y_data})
    writer.add_summary(s, global_step=step)

    if step % 100 == 0:
        print(step, "Cost: ", cost_val, "Prediction: ", hy_val)

tensorboard --logdir=C:\\Users\\jh902\\Documents\\.logs

  File "<ipython-input-29-82d09538d544>", line 1
    tensorboard --logdir=C:\\Users\\jh902\\Documents\\.logs
                          ^
SyntaxError: invalid syntax
#成本/损失函数
成本=tf.减少平均值(tf.平方(假设-Y))
#最小化/优化程序
优化器=tf.train.AdamOptimizer(学习率=1e-5)
列车=优化器。最小化(成本)
#在会话中启动图形。
sess=tf.Session()
w2_hist=tf.summary.直方图(“权重2”,w2)
成本总和=tf.summary.scalar(“成本”,成本)
summary=tf.summary.merge_all()
#创建摘要编写器
writer=tf.summary.FileWriter(“C:\\Users\\jh902\\Documents\\.logs”)
writer.add_图(sess.graph)
#初始化图形中的全局变量。
sess.run(tf.global\u variables\u initializer())
#使用新的培训数据调整生产线
对于步进范围(1001):
s、 cost_val,hy_val,_=sess.run([摘要,成本,假设,训练],提要{X:X_数据,Y:Y_数据})
writer.add_摘要(s,全局_步骤=步骤)
如果步骤%100==0:
打印(步骤,“成本:”,成本值,“预测:”,成本值)
tensorboard--logdir=C:\\Users\\jh902\\Documents\\.log
文件“”,第1行
tensorboard--logdir=C:\\Users\\jh902\\Documents\\.log
^
SyntaxError:无效语法

问题可能是,在
C:
尝试:


是一个控制台命令,您必须从窗口的cmd运行它。

尝试在Python中定义变量,例如

logs\u path=/tmp/logs/1

那么就这样定义你的作者

writer=tf.summary.FileWriter(logs\u path,graph=tf.get\u default\u graph())

然后在命令提示符下运行命令


tensorboard--logdir=/tmp/logs/1

我在康达环境中也遇到过同样的问题

启动anaconda终端并键入以下内容:

conda env list
conda activate path\to\your\environment
tensorboard --logdir "path/to/logs" 
在培训期间/之后运行此项

在chrome中,转到http://localhost:6006

tensorboard --logdir=C:\\Users\\jh902\\Documents\\.logs
conda env list
conda activate path\to\your\environment
tensorboard --logdir "path/to/logs"