Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to store the accuracy using tf.summary() for test set

I have omitted unnecessary code snippets to keep the question details clean. I am trying to plot both training and test model curves. I am able to store the training loss and accuracy curves. But, when writing using test_writer, I am getting the following error:

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'

Code:

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)

My training curves are plotted fine. My testing curves work if I change it to test_summary = sess.run([train_step,merged_summary_op], feed_dict={x:test_xs,j:test_js,y_:test_ys, keep_prob: 0.5}) but it doesn't make sense as I would not want to train my optimizer by feeding the test set.

What is it that I am missing here?

like image 773
deeplearning Avatar asked Oct 05 '17 14:10

deeplearning


1 Answers

I think you should just rewrite the penultimate line from

test_summary = sess.run([accuracy_summary], feed_dict={x:test_xs,j:test_js,y_:test_ys, keep_prob: 0.5})

to

test_summary = sess.run(accuracy_summary, feed_dict={x:test_xs,j:test_js,y_:test_ys, keep_prob: 0.5})

in order to have a scalar output and not a list.

like image 64
Pop Avatar answered Nov 18 '22 23:11

Pop