Plot multiple graphs in one plot using Tensorboard

2019-02-21 17:55发布

问题:

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

回答1:

Just save each runs in different folders under a main folder and open tensorboard on the main folder.

for i in range(x):
    tensorboard = TensorBoard(log_dir='./logs/' + 'run' + str(i), histogram_freq=0,
                                     write_graph=True, write_images=False)

    model.fit(X, Y, epochs=150, batch_size=10, callbacks=[tensorboard])

From the terminal, run tensorboard as such:

tensorboard --logdir=logs


回答2:

  • 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:
  • 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.