世界,
我想更熟悉Tensorboard API。
我研究了我在这里找到的脚本:
https://www.tensorflow.org/code/tensorflow/examples/tutorials/mnist/mnist_with_summaries.py
它在我的笔记本电脑上运行良好。
对我来说很有意义。
所以,我写了一个简单的tensorflow演示:
import tensorflow as tf
sess = tf.Session()
with tf.name_scope('scope0'):
y1 = tf.Variable(1.1)
# I should intialize:
sess.run(tf.initialize_all_variables())
tf.scalar_summary('y1summary', y1)
merged = tf.merge_all_summaries()
train_writer = tf.train.SummaryWriter('/tmp/tb4',sess.graph)
step_i = 0
summary,out1 = sess.run([merged,y1])
train_writer.add_summary(summary, step_i)
step_i += 1
y1 = y1 - 1.1
summary,out1 = sess.run([merged,y1])
train_writer.add_summary(summary, step_i)
step_i += 1
y1 = y1 + 2.1
summary,out1 = sess.run([merged,y1])
train_writer.add_summary(summary, step_i)
train_writer.close()
所以,我使用这个shell命令运行上面的脚本:
python tensorboard_demo4.py
它运行时没有错误。
接下来我运行Tensorboard:
tensorboard --log=/tmp/tb4
它运行时没有错误。
但是当我查看事件标签时, Tensorboard显示y1summary的常量值。
所以,我不明白Tensorboard的基本原理。
如何增强上述脚本,以便Tensorboard通过y1summary显示对y1的更改?
答案 0 :(得分:1)
试试这个
import tensorflow as tf
sess = tf.Session()
with tf.name_scope('scope0'):
y1 = tf.Variable(1.1)
# I should intialize:
sess.run(tf.initialize_all_variables())
tf.scalar_summary('y1summary', y1)
merged = tf.merge_all_summaries()
train_writer = tf.train.SummaryWriter('/tmp/tb4',sess.graph)
step_i = 0
summary,out1 = sess.run([merged,y1])
train_writer.add_summary(summary, step_i)
step_i += 1
sess.run(y1.assign(y1 - 1.1))
summary,out1 = sess.run([merged,y1])
train_writer.add_summary(summary, step_i)
step_i += 1
sess.run(y1.assign(y1 + 2.1))
summary,out1 = sess.run([merged,y1])
train_writer.add_summary(summary, step_i)
train_writer.close()
基本上,您需要将新值分配给您正在捕获摘要的变量(在本例中为y1)。