Tensorboard is an interactive visualization tool that reads log files and helps you track experiment metrics.
For it to work with Keras's model.fit()
method you need to add Tensorboard callback to model.fit()
method.
log_dir="logs/fit/" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
tensorboard_callback = tf.keras.callbacks.TensorBoard(
log_dir=log_dir,
histogram_freq=1)
model.fit(x=x_train,
y=y_train,
epochs=5,
validation_data=(x_test, y_test),
callbacks=[tensorboard_callback])
When you have your own training loop you can define a summary writer and use it to write a summary like this:
current_time = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
train_log_dir = 'logs/gradient_tape/' + current_time + '/train'
test_log_dir = 'logs/gradient_tape/' + current_time + '/test'
train_summary_writer = tf.summary.create_file_writer(train_log_dir)
test_summary_writer = tf.summary.create_file_writer(test_log_dir)
for epoch in range(EPOCHS):
for (x_train, y_train) in train_dataset:
train_step(model, optimizer, x_train, y_train)
with train_summary_writer.as_default():
tf.summary.scalar('loss', train_loss.result(), step=epoch)
tf.summary.scalar('accuracy', train_accuracy.result(), step=epoch)
In any case, you will need to provide a log directory to run Tensorboard. (It doesn't pop up by itself when you train your network. You will have to run it separately. You can run it while training to monitor metrics at the end of each loop).
tensorboard --logdir yourmodel/logs/dir
If you want to make it work with Jupyter notebook you will have to load the Extention and then run magic command %tensorboard --logdir yourmodel/logs/dir
The code is taken from Tensorboard's getting started link. I hope it helps you understand how it works. Otherwise, you can visit these links. 1, 2