python - Tensorboard语法错误: invalid syntax

标签 python path tensorflow 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

有什么问题吗?

# 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

最佳答案

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

logs_path =/tmp/logs/1

然后像这样定义你的作家

writer = tf.summary.FileWriter(logs_path,graph=tf.get_default_graph())

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

tensorboard --logdir = /tmp/logs/1

关于python - Tensorboard语法错误: invalid syntax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44038584/

相关文章:

python - 测试 Python 中是否存在可执行文件?

url - 要使用可点击的网页链接启动/激活/运行 Chrome 扩展程序?

tensorflow - `batch` 在 Tensorflow 数据集管道创建中解决了什么问题以及它如何与训练中使用的(迷你)批量大小交互?

python - 使用 python/django 关闭套接字并避免 Errno 10054 的正确方法是什么

python - 获得 kolmogorov-smirnov 检验所需的临界值

python - Pandas :分别对每一列进行排序

python - Tensorflow 在忽略范围名称或进入新范围名称时恢复

python - 在每个任务中分析 python fabric 命令

java - Windows 路径变量中 Java 的 "bin"目录混淆 - 如何解决此问题?

python - 如何使用 set_random_seed 获得相同的结果