ML Community Day is November 9! Join us for updates from TensorFlow, JAX, and more Learn more


Enable visualizations for TensorBoard.

Inherits From: Callback

Used in the notebooks

Used in the guide Used in the tutorials

TensorBoard is a visualization tool provided with TensorFlow.

This callback logs events for TensorBoard, including:

  • Metrics summary plots
  • Training graph visualization
  • Activation histograms
  • Sampled profiling

When used in Model.evaluate, in addition to epoch summaries, there will be a summary that records evaluation metrics vs Model.optimizer.iterations written. The metric names will be prepended with evaluation, with Model.optimizer.iterations being the step in the visualized TensorBoard.

If you have installed TensorFlow with pip, you should be able to launch TensorBoard from the command line:

tensorboard --logdir=path_to_your_logs

You can find more information about TensorBoard here.

log_dir the path of the directory where to save the log files to be parsed by TensorBoard. e.g. log_dir = os.path.join(working_dir, 'logs') This directory should not be reused by any other callbacks.
histogram_freq frequency (in epochs) at which to compute activation and weight histograms for the layers of the model. If set to 0, histograms won't be computed. Validation data (or split) must be specified for histogram visualizations.
write_graph whether to visualize the graph in TensorBoard. The log file can become quite large when write_graph is set to True.
write_images whether to write model weights to visualize as image in TensorBoard.
write_steps_per_second whether to log the training steps per second into Tensorboard. This supports both epoch and batch frequency logging.
update_freq 'batch' or 'epoch' or integer. When using 'batch', writes the losses and metrics to TensorBoard after each batch. The same applies for 'epoch'. If using an integer, let's say 1000, the callback will write the metrics and losses to TensorBoard every 1000 batches. Note that writing too frequently to TensorBoard can slow down your training.
profile_batch Profile the batch(es) to sample compute characteristics. profile_batch must be a non-negative integer or a tuple of integers. A pair of positive integers signify a range of batches to profile. By default, it will profile the second batch. Set profile_batch=0 to disable profiling.
embeddings_freq frequency (in epochs) at which embedding layers will be visualized. If set to 0, embeddings won't be visualized.
embeddings_metadata Dictionary which maps embedding layer names to the filename of a file in which to save metadata for the embedding layer. In case the same metadata file is to be used for all embedding layers, a single filename can be passed.


Basic usage:

tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir="./logs"), y_train, epochs=2, callbacks=[tensorboard_callback])
# Then run the tensorboard command to view the visualizations.

Custom batch-level summaries in a subclassed Model: