Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

TensorFlow · Class

callbacks.TensorBoard

Logs Keras training information for visualization in TensorBoard. It can record metrics, the graph, weight histograms, throughput, profiling data, and embeddings.

How it works

TensorBoard is a Keras callback that writes training information to event files for visualization. Configure its log directory and optional logging frequencies, then pass the callback to a model-training method such as fit.

Syntax

tf.keras.callbacks.TensorBoard(log_dir='logs', histogram_freq=0, write_graph=True, write_images=False, write_steps_per_second=False, update_freq='epoch', profile_batch=0, embeddings_freq=0, embeddings_metadata=None)

Parameters

NameTypeDescription
log_dirstrDirectory in which TensorBoard log files are written.
histogram_freqintEpoch interval for computing layer weight histograms; zero disables them.
write_graphboolWhether to write the model graph.
write_imagesboolWhether to write model weights for image visualization.
write_steps_per_secondboolWhether to log training steps per second.
update_freqstr or intLogging cadence: "batch", "epoch", or an integer batch interval.
profile_batchint or strBatches to profile; the documented default is 0.
embeddings_freqintFrequency in epochs for embedding visualization.
embeddings_metadatastr or dictMetadata associated with embeddings.

Returns

A TensorBoard callback instance that can be passed to Keras model methods through their callbacks argument.

Key points

  • The class connects Keras training with TensorBoard visualization.
  • It writes TensorBoard events covering several training diagnostics.
  • Logged metrics can be displayed as summary plots.
  • The model's training graph can be visualized when graph writing is enabled.
  • write_steps_per_second=True adds training throughput information to the TensorBoard logs.

Common mistakes

  • The callback depends on TensorFlow being installed; it is not usable in an environment without TensorFlow.
  • histogram_freq=0 disables weight-histogram computation, so set a positive epoch frequency when those histograms are needed.
  • With the default epoch update mode, losses and metrics are emitted only after each epoch rather than after every batch.

Example: Log Keras training for TensorBoard

import tensorflow as tf

(x_train, y_train), _ = tf.keras.datasets.mnist.load_data()
x_train = x_train[..., None].astype("float32") / 255.0

model = tf.keras.Sequential([
    tf.keras.layers.Flatten(input_shape=(28, 28, 1)),
    tf.keras.layers.Dense(10, activation="softmax"),
])
model.compile(optimizer="adam", loss="sparse_categorical_crossentropy", metrics=["accuracy"])

callback = tf.keras.callbacks.TensorBoard(log_dir="./logs")
model.fit(x_train, y_train, epochs=2, callbacks=[callback])

Creates TensorBoard event logs while fitting a Keras model; launch TensorBoard with tensorboard --logdir=./logs to inspect them.

When to use it

Monitor training progress

You need loss and metric charts while training a Keras model.

Visualize graph and weights

You want to inspect model structure and layer-weight distributions.

Profile selected batches

You need to investigate training throughput or execution performance.

Inspect embeddings

You want to examine learned representations.

Interview questions

QWhat does tf.keras.callbacks.TensorBoard do?

TensorBoard is a visualization tool, and this callback logs metrics summary plots, the training graph, weight histograms, and sampled profiling information. The callback is supplied to Keras training through the callbacks argument.

Follow-up: How would you inspect performance? Set profile_batch to select batches for profiling, then open the resulting logs in TensorBoard's profiling view.

QHow is the output location and logging cadence configured?

log_dir identifies the directory where TensorBoard-readable log files are saved. A typical setup creates the callback with tf.keras.callbacks.TensorBoard(log_dir="./logs") and passes it to model.fit.

Follow-up: How can logging frequency be changed? Use update_freq="batch", "epoch", or an integer such as 1000 for periodic batch-based logging.

QWhat controls weight-histogram logging?

histogram_freq is measured in epochs and controls how often layer weight histograms are computed. A value of zero turns histogram computation off.

Follow-up: What additional image logging is available? Set write_images=True to write model weights for visualization as images in TensorBoard.

  • tf.keras.callbacks.Callback
  • tf.keras.Model.fit
  • TensorBoard

Source: tf.keras.callbacks.TensorBoard | TensorFlow. Checked 2026-10-15.