0

I'm working with a Tensorflow object detection model with a config file similar to this tensorflow/research/object_detection/samples/configs/ file. However, when I plot the results in Tensorboard, I only see one graph for the loss/precision etc. I want to display both the training and validation loss in order to better evaluate the result, but I am relatively new to working with Tensorflow and thus need some guidance as to where/how this has to be written.

I've looked into tensorboard/tensorboard/plugins/custom_scalar/custom_scalar_demo.py as well as this stackoverflow post, however I am still a bit confused as to where this functionality should be written.

fendrbud
  • 89
  • 1
  • 11

1 Answers1

0

Please refer below sample code to plot both validation and training loss

import os

import tqdm
import tensorflow as tf


def tb_test():
    sess = tf.Session()

    x = tf.placeholder(dtype=tf.float32)
    summary = tf.summary.scalar('Values', x)
    merged = tf.summary.merge_all()

    sess.run(tf.global_variables_initializer())

    writer_1 = tf.summary.FileWriter(os.path.join('tb_summary', 'train_loss'))
    writer_2 = tf.summary.FileWriter(os.path.join('tb_summary', 'validation_loss'))

    for i in tqdm.tqdm(range(200)):
        # train
        summary_1 = sess.run(merged, feed_dict={x: i-10})
        writer_1.add_summary(summary_1, i)
        # eval
        summary_2 = sess.run(merged, feed_dict={x: i+10})            
        writer_2.add_summary(summary_2, i)

    writer_1.close()
    writer_2.close()


if __name__ == '__main__':
    tb_test()

%load_ext tensorboard
%tensorboard --logdir=tb_summary/ 
bsquare
  • 943
  • 5
  • 10