我在这里使用简单的教程代码https://www.oreilly.com/learning/hello-tensorflow
这是我的版本:
import tensorflow as tf
x = tf.constant(1.0, name='input')
w = tf.Variable(0.8, name='weight')
y = tf.mul(w, x, name='output')
y_ = tf.constant(0.0, name='correct_value')
loss = tf.pow(y - y_, 2, name='loss')
train_step = tf.train.GradientDescentOptimizer(0.025).minimize(loss)
summary_y = tf.scalar_summary('output', loss)
sess = tf.Session()
sess.run(tf.initialize_all_variables())
summary_writer = tf.train.SummaryWriter('outs')
for i in range(1000):
summary_writer.add_summary(sess.run(summary_y), i)
sess.run(train_step)
之后,我在张量板中只有914个1000步。这是一次检查:
tensorboard --inspect --logdir=outs
======================================================================
Processing event files... (this can take a few minutes)
======================================================================
Found event files in:
outs
These tags are in outs:
audio -
histograms -
images -
scalars
output
======================================================================
Event statistics for outs:
audio -
graph -
histograms -
images -
scalars
first_step 0
last_step 913
max_step 913
min_step 0
num_steps 914
outoforder_steps []
sessionlog:checkpoint -
sessionlog:start -
sessionlog:stop -
======================================================================
如果我打开tensorboard,我会看到正确的914步(从0到913)的图。 无论步数多少,都会发生这种情况。例如,如果我采取100步,则总结中只保存93个。
我正在使用Fedora 23(4.6.5-200.fc23.x86_64 GNU / Linux)。 Tensorflow是虚拟环境中的最新安装
pip list | grep tensorflow
tensorflow (0.10.0rc0)
最后一次迭代丢失的想法是什么?
答案 0 :(得分:1)
tf.train.SummaryWriter
对象在内部缓冲摘要,因此在退出之前调用summary_writer.close()
很重要。您还可以调用summary_writer.flush()
以确保已将最近编写的摘要写入事件日志。以下对训练循环的简单修改应该有效:
summary_writer = tf.train.SummaryWriter('outs')
for i in range(1000):
summary_writer.add_summary(sess.run(summary_y), i)
sess.run(train_step)
summary_writer.close()