Tensorboard SyntaxError: invalid syntax

独自空忆成欢 提交于 2019-12-24 10:13:40

问题


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.

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).

If I code like this,

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

What's the problem?

# 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

回答1:


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())

Then in Command Prompt run command

tensorboard --logdir = /tmp/logs/1




回答2:


the problem could be, you are missing an extra slash '\' after C: try:

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



回答3:


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

Is a console command, you will have to run it from window's cmd.



来源:https://stackoverflow.com/questions/44038584/tensorboard-syntaxerror-invalid-syntax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!