top of page

TensorBoard for TensorFlow


About TensorBoard

TensorBoard helps in visualizing and analyzing our TensorFlow based AI/ML model runs and graphs.

Initial Setup

We will understand, how the initial setup is done, so that model visualization can be performed using

TensorBoard.

The first step is to create a log file for storing data for the purpose of TensorBoard visualization. In this case we are storing this in google storage

import datetime
log_dir = "gs://ai-mod-6-pathology-dataset/AI-MODULE-6/logsdn" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
tensorboard_callback = 
tf.keras.callbacks.TensorBoard(log_dir=log_dir)

tf.keras.callback specifies where the logs should be stored

callbacks_list = [lr_schedule,tensorboard_callback]
history = model.fit(train_dataset,
                    epochs=EPOCHS,
                    callbacks=callbacks_list,
                    steps_per_epoch=STEPS_PER_EPOCH,
                    validation_data=valid_dataset)

Callback is then passed to model.fit during the model training. After training the model with the above code, the logs will be available in the designated folder, namely logsdn20230528-094952

After transferring the data from google storage to the local system, we can launch TensorBoard with

 tensorboard --logdir=./logsdn20230528-094952

when we launch the tensorboard, a web link is provided as

copy paste this in a browser to visualize the results.

Categorical accuracy and loss of the DenseNet model are shown here. From the picture it is clear that there are more analysis options with TensorBoard such as Training accuracy/loss and Validation accuracy/loss, learning rate. If there is bias in the model, it can be quickly identified and corrective measures can be taken.


DenseNet model accuracy and loss - TensorBoard

EfficientNet model accuracy and loss - TensorBoard

Additional Reference Material

  1. https://www.tensorflow.org/tensorboard/get_started

  2. https://github.com/tensorflow/tensorboard/blob/master/README.md


bottom of page