Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plot multiple graphs in one plot using Tensorboard

I am using Keras with Tensorflow backend. My work involves comparing the performances of several models such as Inception, VGG, Resnet etc on my dataset. I would like to plot the training accuracies of several models in one graph. I am trying to do this in Tensorboard, but it is not working.

Is there a way of plotting multiple graphs in one plot using Tensorboard or is there some other way I can do this?

Thank you

like image 261
Kavitha Devan Avatar asked Feb 23 '18 15:02

Kavitha Devan


Video Answer


2 Answers

If you are using the SummaryWriter from tensorboardX or pytorch 1.2, you have a method called add_scalars:

Call it like this:

my_summary_writer.add_scalars(f'loss/check_info', {     'score': score[iteration],     'score_nf': score_nf[iteration], }, iteration) 

And it will show up like this:

tensorboard image


Be careful that add_scalars will mess with the organisation of your runs: it will add mutliple entries to this list (and thus create confusion):

tensorboard image

I would recommend that instead you just do:

my_summary_writer.add_scalar(f'check_info/score',    score[iter],    iter) my_summary_writer.add_scalar(f'check_info/score_nf', score_nf[iter], iter) 
like image 89
Benjamin Crouzier Avatar answered Oct 17 '22 05:10

Benjamin Crouzier


  • You can definitely plot scalars like the loss & validation accuracy : tf.summary.scalar("loss", cost) where cost is a tensor cost = tf.reduce_mean(-tf.reduce_sum(y*tf.log(pred), reduction_indices=1))

  • Now you write summary for plotting all the values and then you may want to merge all these summary to a single summary by: merged_summary_op = tf.summary.merge_all()

  • Next step will be to run this summary in the session by summary = sess.run(merged_summary_op)

  • After you run the merged_summary_op you have to write the summary using summary_writer : summary_writer.add_summary(summary, epoch_number) where summary_writer = tf.summary.FileWriter(logs_path, graph=tf.get_default_graph())

  • Now open the terminal or cmd and run the following command: "Run the command tensorboard --logdir="logpath"

  • Then open http://0.0.0.0:6006/ into your web browser

  • You can refer the following link: https://github.com/jayshah19949596/Tensorboard-Visualization-Freezing-Graph

  • Other things you can plot are the weights, inputs

  • You can also display the images on tensorboard

  • I think if you are using keras with tensorflow 1.5 then using tensorboard is easy because in tensorflow 1.5 keras is included as their official high level api

  • I am sure you can plot different accuracy on the same graph for the same model with different hyper-paramters by using different FileWriter instances with different log path

  • Check the image below: enter image description here

  • I don't know if you can plot different accuracy of different models on the same graph... But you can write a program that does that

  • May be you can write the summary information of different models to different directories and then point tensor-board to the parent directory to plot the accuracy of different models on the same graph as suggested in the comment by @RobertLugg

==================== UPDATED =================

I have tried saving accuracy and loss of different models to different directories and then making tensorboard to point to the parent directory and it works, you will get results of different models in the same graph. I have tried this myself and it works.

like image 25
Jai Avatar answered Oct 17 '22 05:10

Jai