TensorBoard 不显示标量 [英] TensorBoard does not show scalars
问题描述
我正在玩 TensorBoard,无法制作简单的示例.计算只是简单地添加两个常量.
I am playing TensorBoard and cannot make a simple example work. The computation is simply adding two constants.
import tensorflow as tf
sess = tf.Session()
a = tf.constant(1, name = "const1")
b = tf.constant(10, name = "const2")
c = a + b
asum = tf.summary.scalar("g1" , a)
bsum = tf.summary.scalar("g2", b)
csum = tf.summary.scalar("gsum", c)
merged = tf.summary.merge_all()
train_writer = tf.summary.FileWriter('.\logs',sess.graph)
summary, _ = sess.run([merged, c])
train_writer.add_summary(summary, 0)
然后我先编译了:
>python filename.py
一切看起来都不错.
然后:
>tensorboard --logdir=".\logs" --inspect
奇怪的事情发生了:没有标量!
The weird thing occurred: there were no scalars!
Found event files in:
.\logs
These tags are in .\logs:
audio -
histograms -
images -
scalars -
tensor -
======================================================================
Event statistics for .\logs:
audio -
graph
first_step 0
last_step 0
max_step 0
min_step 0
num_steps 1
outoforder_steps []
histograms -
images -
scalars -
sessionlog:checkpoint -
sessionlog:start -
sessionlog:stop -
tensor -
======================================================================
TensorFlow 的版本是:1.2.1
Version of TensorFlow is: 1.2.1
Python 版本:3.5.2
Python version: 3.5.2
推荐答案
FileWriter
对象缓冲它收集的事件,然后,一旦缓冲区已满,将它们写入磁盘.一次调用 FileWriter
对象不足以填充缓冲区,因此您强制 FileWriter
刷新缓冲区并将内容写入磁盘.为此,只需在 add_summary
操作之后调用 .close()
.
The FileWriter
object buffers the event it collects and then, once the buffer is full, write them on the disk.
A single call of the FileWriter
object isn't enough the fill the buffer, thus you to force the FileWriter
to flush the buffer and write the content on the disk. To do that, just call .close()
after the add_summary
operation.
train_writer.add_summary(summary, 0)
train_writer.close()
这将关闭 train_writer
对象,您将无法再使用它.
This will close the train_writer
object and you can't use it anymore.
如果您只想刷新缓冲区而不关闭文件,您可以使用 .flush()
方法.
If you, instead, want to just flush the buffer without closing the file, you can use the .flush()
method.
这篇关于TensorBoard 不显示标量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!