Monitor scalar metrics
Track loss, accuracy, learning rates, or other numeric signals across training steps.
TensorFlow · Module
tf.summary provides TensorFlow’s public API for writing training and evaluation summaries. It includes writers and functions for recording values such as scalars, images, histograms, and text.
The module exposes TensorFlow’s summary-writing API for producing data that tools such as TensorBoard can visualize. Create or select a SummaryWriter, then call type-specific functions inside its context and provide a monotonic step when needed.
tf.summary| Name | Type | Description |
|---|---|---|
logdir | str | Directory in which the event file is written. |
max_queue | int | None | Maximum number of queued summaries before flushing; defaults to 10. |
flush_millis | int | None | Maximum interval between automatic flushes. |
filename_suffix | str | None | Optional suffix appended to the event filename. |
name | str | None | Optional name for the writer operation. |
experimental_trackable | bool | Whether to make the writer trackable. |
experimental_mesh | Any | Optional experimental mesh configuration. |
A SummaryWriter object.
import tensorflow as tf
writer = tf.summary.create_file_writer("logs")
with writer.as_default(), tf.summary.record_if(True):
tf.summary.scalar("loss", 0.42, step=1)
writer.flush()Creates an event writer, records a scalar at step 1, and flushes buffered data to storage.
Track loss, accuracy, learning rates, or other numeric signals across training steps.
Inspect predictions, generated samples, or intermediate activations visually.
Capture textual metadata, notes, or model-related annotations for later analysis.
tf.summary is the public API namespace for writing summaries such as scalars, images, histograms, audio, and text. These summaries are associated with steps and are intended for later visualization or analysis.
Follow-up: How would you prevent summary work during selected iterations? Use tf.summary.record_if with a boolean, scalar boolean Tensor, or callable condition.
Create a writer with tf.summary.create_file_writer, make it current with its as_default context, and invoke summary functions inside that context. The writer can then be flushed to send buffered event data to storage.
Follow-up: What happens without a current writer? A summary write can be skipped; use a file writer context when output is required.
Summary-writing functions use an explicit int64-castable monotonic step, or the current experimental default step when step is omitted. The default step must not be None.
Follow-up: How can a writer supply the step conveniently? SummaryWriter.as_default(step=...) sets the default step used by summary-writing functions in that context.
tf.summary.SummaryWritertf.summary.create_file_writertf.summary.create_noop_writertf.summary.scalartf.summary.imagetf.summary.histogramtf.summary.texttf.summary.record_if