I'm training a fairly deep convolutional neural network and I want to see the loss and accuracy curves in real-time instead of just reading the terminal logs. I heard TensorBoard is the tool for this, but I'm not sure how to integrate the callback into model.fit(). Do I need to write custom logging code, or is there a built-in way to save the logs to a directory for visualization?
3 answers
Just use the TensorBoard callback in model.fit(callbacks=[...]). It creates a logs folder that you can point the TensorBoard dashboard to for nice visual graphs.
It is actually very straightforward with the Keras API. You just need to define the callback: tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir='logs/fit'). Then, pass it into the callbacks list in model.fit(). Once the training starts, open your terminal, navigate to the project folder, and run tensorboard --logdir logs/fit. You will get a local URL (usually localhost:6006) where you can view interactive graphs, histograms of weights, and even the model architecture graph itself.
Are you also interested in visualizing the actual images during training, or are you strictly looking to track scalar metrics like precision, recall, and validation loss?
Jason, tracking images is a bit more involved but very useful for GANs or Segmentation. To do that, Jennifer would need to use tf.summary.image within a custom callback. But for standard classification, the default TensorBoard callback already provides the 'Images' tab if she enables histogram logging. It helps immensely in seeing if your weights are exploding or vanishing early on.
I agree with Brandon. The best part is the 'Scalars' tab. It makes it so much easier to compare different runs when you're tuning hyperparameters like the learning rate!