So I am using tensorboard within keras. In tensorflow one could use two different summarywriters for train and validation scalars so that tensorboard could plot them in a same figure. Something like the figure in
TensorBoard - Plot training and validation losses on the same graph?
Is there a way to do this in keras?
Thanks.
To handle the validation logs with a separate writer, you can write a custom callback that wraps around the original
TensorBoard
methods.__init__
, two subdirectories are set up for training and validation logsset_model
, a writerself.val_writer
is created for the validation logson_epoch_end
, the validation logs are separated from the training logs and written to file withself.val_writer
Using the MNIST dataset as an example:
You can then visualize the two curves on a same figure in TensorBoard.
EDIT: I've modified the class a bit so that it can be used with eager execution.
The biggest change is that I use
tf.keras
in the following code. It seems that theTensorBoard
callback in standalone Keras does not support eager mode yet.The idea is the same --
TensorBoard
callbackAgain, you can use the MNIST data to test it,