我省略了不必要的代码段以保持问题详细信息的清晰。我试图绘制训练和测试模型曲线。我能够存储训练损失和准确度曲线。但是,在使用test_writer编写时,我收到以下错误:
test_writer.add_summary(test_summary,step*batch_size)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/summary/writer/writer.py", line 123, in add_summary
for value in summary.value:
AttributeError: 'list' object has no attribute 'value'
代码:
accuracy = tf.reduce_mean(correct_prediction)
#Summary
tf.summary.scalar("loss",cross_entropy)
accuracy_summary = tf.summary.scalar("accuracy",accuracy)
merged_summary_op = tf.summary.merge_all()
train_writer = tf.summary.FileWriter(graph_location)
train_writer.add_graph(tf.get_default_graph())
test_writer = tf.summary.FileWriter(location)
test_writer.add_graph(tf.get_default_graph())
with tf.Session() as sess:
print "STARTED TENSORLFOW SESSION"
sess.run(tf.initialize_all_variables())
while step*batch_size < training_iters:
if count <= 900:
_,summary = sess.run([train_step,merged_summary_op], feed_dict={x:batch_xs, j:batch_js, y_:batch_ys, keep_prob:dropout})
train_writer.add_summary(summary, step*batch_size)
else:
test_summary = sess.run([accuracy_summary], feed_dict={x:test_xs,j:test_js,y_:test_ys, keep_prob: 0.5})
test_writer.add_summary(test_summary,step*batch_size)
我的训练曲线很好。如果我将其更改为,我的测试曲线会起作用
test_summary = sess.run([train_step,merged_summary_op], feed_dict={x:test_xs,j:test_js,y_:test_ys, keep_prob: 0.5})
但它没有意义,因为我不想通过提供测试集来训练我的优化器。
我在这里失踪的是什么?
答案 0 :(得分:12)
我认为你应该从
重写倒数第二行test_summary = sess.run([accuracy_summary], feed_dict={x:test_xs,j:test_js,y_:test_ys, keep_prob: 0.5})
到
test_summary = sess.run(accuracy_summary, feed_dict={x:test_xs,j:test_js,y_:test_ys, keep_prob: 0.5})
为了得到标量输出而不是列表。