Tensorboard SyntaxError:语法无效 [英] Tensorboard SyntaxError: invalid syntax

查看:237
本文介绍了Tensorboard SyntaxError:语法无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试制作张量板时,出现语法错误.尽管有开源代码,但我还是听不懂.我试图搜索有关张量板的代码,但目前尚不清楚.

When I try to make tensorboard, Syntax error comes out. I can not understand in spite of open source code. I tried to search about code for tensorboard but It's unclear.

即使我也不擅长python.我以这种方式写路径C:\\Users\\jh902\\Documents\\.logs,因为我使用的是Windows 10,但不确定. (我使用了双反斜杠,但在此显示器中好像是一个斜杠).

Even I'm not good at python. I write the path in this way, C:\\Users\\jh902\\Documents\\.logs because I'm using Windows 10 but I'm not sure. (I used double back slash but in this monitor it seems like one slash).

如果我这样编码,

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中定义变量,例如

Try define variable in Python something like

logs_path =/tmp/logs/1

然后像这样定义您的作家

Then define your writer like this

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

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

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

Then in Command Prompt run command

tensorboard --logdir = /tmp/logs/1

tensorboard --logdir = /tmp/logs/1

这篇关于Tensorboard SyntaxError:语法无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆