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

Keras · Class

callbacks.TensorBoard

keras.callbacks.TensorBoard records Keras training events for TensorBoard, including metrics, graphs, weight histograms, and profiling data. Configure its log directory and logging options, then pass it to model.fit().

How it works

TensorBoard is a Keras callback that records training information as TensorBoard events while model methods run. Configure the log directory and optional logging features, then pass the callback to fit(); TensorFlow is required to use it.

Syntax

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_dirstringDirectory for TensorBoard event files.
histogram_freqintegerEpoch interval for computing weight histograms; 0 disables them.
write_graphbooleanWhether to visualize the model graph.
write_imagesbooleanWhether to write model weights as images.
write_steps_per_secondbooleanWhether to log training steps per second.
update_freqstring or integerLogging frequency: "batch", "epoch", or an integer.
profile_batchintegerBatch or epoch range to profile; 0 disables profiling.
embeddings_freqintegerFrequency for embedding visualization.
embeddings_metadatastring or mappingMetadata associated with embeddings.

Returns

A TensorBoard callback instance.

Key points

  • The callback connects Keras training with TensorBoard visualizations.
  • Logged event categories include metric summaries, the training graph, weight histograms, and sampled profiling.
  • log_dir specifies where TensorBoard-readable log files are stored.
  • histogram_freq sets the epoch interval for computing layer weight histograms.
  • write_graph determines whether the model graph is included in TensorBoard.
  • write_images controls whether model weights are exported as TensorBoard images.
  • write_steps_per_second records training throughput in steps per second.
  • update_freq accepts batch-based, epoch-based, or integer-based logging intervals.

Common mistakes

  • TensorFlow must be installed before using this callback.
  • Enabling graph logging can substantially increase log-file size.
  • Step-rate logging can use either epoch or batch update frequencies.

Example: Log training with TensorBoard

import keras

model = keras.Sequential([
    keras.layers.Input(shape=(4,)),
    keras.layers.Dense(8, activation="relu"),
    keras.layers.Dense(1),
])
model.compile(optimizer="adam", loss="mse")
model.fit(
    [[0, 1, 2, 3], [1, 2, 3, 4]],
    [0, 1],
    epochs=2,
    callbacks=[keras.callbacks.TensorBoard(log_dir="logs")],
)

Trains a compiled Keras model while writing TensorBoard event data to the logs directory.

When to use it

Training dashboards

Monitor losses and metrics during model training.

Graph and weight inspection

Inspect model structure and parameter distributions.

Performance profiling

Measure training throughput and selected execution behavior.

Embedding exploration

Visualize learned representations from embedding layers.

Interview questions

QWhat does keras.callbacks.TensorBoard provide?

TensorBoard writes training events such as metric summaries, graph information, weight histograms, and profiling data. The callback is passed to a model training call through its callbacks list.

Follow-up: How would you control logging granularity? Set update_freq to "batch", "epoch", or an integer interval.

QWhat is log_dir used for?

log_dir identifies the directory whose event files TensorBoard reads. The default is "logs", but an explicit directory is usually clearer when running multiple experiments.

Follow-up: How do you inspect those events? Launch TensorBoard with the directory, for example tensorboard --logdir=logs.

QHow do histogram_freq and update_freq differ?

histogram_freq controls how often, in epochs, layer weight histograms are computed; zero disables them. update_freq independently controls when losses and metrics are written, using "batch", "epoch", or an integer.

Follow-up: What trade-off can graph logging introduce? write_graph=True can make the log file quite large.

  • keras.callbacks.Callback
  • keras.callbacks.ModelCheckpoint
  • keras.callbacks.EarlyStopping
  • model.fit()

Source: keras.io · api · callbacksTensorBoard - Keras. Checked 2026-10-15.