SummaryWriter不会将摘要写入文件
问题描述:
我正在尝试使用tensorflow的SummaryWriter,但它似乎没有将事件,图像或直方图写入文件。但是它会将图形写入文件(我可以在张力板中看到),至少表明tensorboard和SummaryWriter知道我的logdir在哪里。SummaryWriter不会将摘要写入文件
这是我的(简化的)码,通过省略代码块打碎:
sess = tf.Session()
W_conv1 = tf.Variable(tf.truncated_normal([5,5,3, hidden1_size], stddev = 0.01), name = 'W_conv1')
b_conv1 = tf.Variable(tf.constant(0.01, shape=[hidden1_size]), name = 'b_conv1')
#to visualize the weights of the first layer...
sum2 = tf.image_summary('first layer weights', tf.transpose(W_conv1, perm = [3, 0, 1, 2]), max_images = 16)
h_conv1 = tf.nn.relu(b_conv1 + conv(x, W_conv1))
#to visualize how many dead relu's we have
sum1 = tf.scalar_summary('conv1', tf.nn.zero_fraction(h_conv1))
....更多层
softmax = {}
cross_entropy = tf.Variable(0.0)
softmax[0] = tf.nn.softmax(fc_out)
cross_entropy += -tf.reduce_sum(y_*tf.log(softmax[0]))
.... Reccurrent部分
sum3 = tf.histogram_summary('cross entropy', cross_entropy)
lr = tf.Variable(tf.constant(1e-3))
lr_change = tf.assign(lr, tf.mul(.1, lr))
train_step = tf.train.AdamOptimizer(lr).minimize(cross_entropy)
merged=tf.merge_all_summaries()
writer = tf.train.SummaryWriter("./logs", sess.graph_def, flush_secs = 5)
sess.run(tf.initialize_all_variables())
....然后训练码:
for i in range(train_iter):
batch_i = np.random.randint(0, len(X_t), [batch_size])
X_batch = X_t[batch_i]
y_batch = y_t[batch_i]
summary_str, _, loss = sess.run([merged, train_step, cross_entropy], feed_dict = {x: X_batch, y_: y_batch})
writer.add_summary(summary_str, i)
writer.flush()
saver.save(sess, 'RNN_model.ckpt', global_step = i)
然后当我加载tensorboard,并期待在事件选项卡上,我看到了以下错误:
No scalar summary tags were found.
Maybe data hasn't loaded yet, or maybe you need to add some >tf.scalar_summary ops to your graph, and serialize them using the >tf.training.summary_io.SummaryWriter.
我增加了writer.flush()语句,因为在GitHub上的两个堆叠交换搜索后,这是一个常见的建议。问题没有解决。
在我的日志文件中,只写入了graph_def,在训练期间没有其他文件被写入。
我在mac 0SX el-capitan上使用tensorflow'0.7.1'。
谢谢!
答
我知道这是一个旧帖子,但我在运行TensorFlow 1.1.0的虚拟环境中遇到了同样的情况。运行版本1.2.1我似乎没有这个问题。您可以在命令行执行以下命令以确定您正在运行的是哪个版本的TensorFlow:
python -c "import tensorflow as tf; print(tf.__version__)"
希望它可以帮助那里的人!
干杯,
-Maashu
你TensorBoard /简要用法看起来是正确的。 您确定只有graph_def正在写入事件文件吗?你可以上传吗?然后我可以检查是否有直方图摘要等写入,并确定问题是否与TensorBoard或事件编写代码相关。 – dandelion
当然,非常感谢! https://drive.google.com/file/d/0B5GqMWTiEZZAR2gyU3RiWDFzMVE/view?usp=sharing ps.s.我认为这只是图表BC。它只在定义网络时写入一次文件,但从不在培训期间。 –
我从[openai/InfoGAN](https://github.com/openai/InfoGAN#running-experiment)运行示例Docker实验注意到了相同的情况。 它只在开始时输出日志,但在训练后不输出。 – NHDaly