TensorBoard Distributions and Histograms with Keras and fit_generator

Jonathan Roth picture Jonathan Roth · Feb 23, 2017 · Viewed 10.6k times · Source

I'm using Keras to train a CNN using the fit_generator function.

It seems to be a known issue that TensorBoard doesn't show histograms and distributions in this setup.

Did anybody figure out a way to make it work anyway?

Answer

bartgras picture bartgras · Feb 27, 2017

There is no easy way to just plug it in with one line of code, you have to write your summaries by hand.

The good news is that it's not difficult and you can use the TensorBoard callback code in Keras as a reference. (There is also a version 2 ready for TensorFlow 2.x.)

Basically, write a function e.g. write_summaries(model) and call it whenever you want to write your summaries (e.g. just after your fit_generator())

Inside your write_summaries(model) function use tf.summary, histogram_summary and other summary functions to log data you want to see on tensorboard.

If you don't know exactly how to check official tutorial: and this great example of MNIST with summaries.