I have a TensorFlow model, and one part of this model evaluates the accuracy. The
tf.scalar_summary("Training Accuracy", accuracy)
summary_op = tf.merge_all_summaries()
writer = tf.train.SummaryWriter('/me/mydir/', graph=sess.graph)
for n in xrange(1000):
summary, ..., ... = sess.run([summary_op, ..., ...], feed_dict)
You can reuse the the accuracy node but you need to use two different SummaryWriters, one for the training runs and one for the test data. Also you have to assign the scalar summary for accuracy to a variable.
accuracy_summary = tf.scalar_summary("Training Accuracy", accuracy) tf.scalar_summary("SomethingElse", foo) summary_op = tf.merge_all_summaries() summaries_dir = '/me/mydir/' train_writer = tf.train.SummaryWriter(summaries_dir + '/train', sess.graph) test_writer = tf.train.SummaryWriter(summaries_dir + '/test')
Then in your training loop you have the normal training and record your summaries with the train_writer. In addition you run the graph on the test set each 100th iteration and record only the accuracy summary with the test_writer.
# Record train set summaries, and train summary, _ = sess.run([summary_op, train_step], feed_dict=...) train_writer.add_summary(summary, n) if n % 100 == 0: # Record summaries and test-set accuracy summary, acc = sess.run([accuracy_summary, accuracy], feed_dict=...) test_writer.add_summary(summary, n) print('Accuracy at step %s: %s' % (n, acc))
You can then point TensorBoard to the parent directory (summaries_dir) and it will load both data sets.
This can be also found in the TensorFlow HowTo's https://www.tensorflow.org/versions/r0.11/how_tos/summaries_and_tensorboard/index.html