我一直在阅读有关标量的张量文档,我在张量板中显示它有问题。
我在windows 10中有pip install tensorflow
我的代码如下:
import tensorflow as tf
a = tf.constant(7, name='test_variable')
tf.summary.scalar('variable', a)
with tf.Session() as sess:
tf.summary.FileWriter('my_folder', graph=sess.graph)
X = tf.global_variables_initializer()
sess.run(X)
我看到my_folder
在命令提示符下:tensorboard --logdir=my_folder --port 6006
出:
C:\Users\MM>tensorboard --logdir=my_folder --port 6006
Starting TensorBoard b'54' at http://DESKTOP-9S2D9VF:6006
(Press CTRL+C to quit)
当我打开浏览器时,我得到:
No scalar data was found.
Probable causes: etc. etc.
答案 0 :(得分:2)
您需要运行summary_op
并将结果传递给FileWriter
。
例如:
import tensorflow as tf
a = tf.constant(7, name='test_variable')
tf.summary.scalar('variable', a)
summary_op = tf.summary.merge_all()
with tf.Session() as sess:
summary_writer = tf.summary.FileWriter('/tmp/summary', graph=sess.graph)
X = tf.global_variables_initializer()
sess.run(X)
summary = sess.run(summary_op)
summary_writer.add_summary(summary)
来自官方documentation:
然后,您可以运行合并的摘要op,它将生成一个序列化的Summary protobuf对象,其中包含给定步骤中的所有摘要数据。最后,要将此摘要数据写入磁盘,请将摘要protobuf传递给
tf.summary.FileWriter
。