Training dashboards
Monitor losses and metrics during model training.
Keras · Class
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().
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.
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)| Name | Type | Description |
|---|---|---|
log_dir | string | Directory for TensorBoard event files. |
histogram_freq | integer | Epoch interval for computing weight histograms; 0 disables them. |
write_graph | boolean | Whether to visualize the model graph. |
write_images | boolean | Whether to write model weights as images. |
write_steps_per_second | boolean | Whether to log training steps per second. |
update_freq | string or integer | Logging frequency: "batch", "epoch", or an integer. |
profile_batch | integer | Batch or epoch range to profile; 0 disables profiling. |
embeddings_freq | integer | Frequency for embedding visualization. |
embeddings_metadata | string or mapping | Metadata associated with embeddings. |
A TensorBoard callback instance.
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.
Monitor losses and metrics during model training.
Inspect model structure and parameter distributions.
Measure training throughput and selected execution behavior.
Visualize learned representations from embedding layers.
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.
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.
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.Callbackkeras.callbacks.ModelCheckpointkeras.callbacks.EarlyStoppingmodel.fit()