Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a summary of accuracy of the whole train/test dataset in Tensorflow

Tags:

tensorflow

I am trying to use Tensorboard to visualize my training procedure. My purpose is, when every epoch completed, I would like to test the network's accuracy using the whole validation dataset, and store this accuracy result into a summary file, so that I can visualize it in Tensorboard.

I know Tensorflow has summary_op to do it, however it seems only work for one batch when running the code sess.run(summary_op). I need to calculate the accuracy for the whole dataset. How?

Is there any example to do it?

like image 960
C. Wang Avatar asked Jan 05 '23 00:01

C. Wang


1 Answers

Define a tf.scalar_summary that accepts a placeholder:

accuracy_value_ = tf.placeholder(tf.float32, shape=())
accuracy_summary = tf.scalar_summary('accuracy', accuracy_value_)

Then calculate the accuracy for the whole dataset (define a routine that calculates the accuracy for every batch in the dataset and extract the mean value) and save it into a python variable, let's call it va.

Once you have the value of va, just run the accuracy_summary op, feeding the accuracy_value_ placeholder:

sess.run(accuracy_summary, feed_dict={accuracy_value_: va})
like image 135
nessuno Avatar answered Jan 13 '23 09:01

nessuno