Tensorboard scalar plotting with epoch number on the horizontal axis
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
TensorBoard plots scalars against a step value, not against a special built-in epoch axis. If you want epoch numbers on the horizontal axis, the practical solution is to log your metric once per epoch and use the epoch index as the summary step.
Understand What TensorBoard Uses on the X Axis
TensorBoard's scalar dashboard always has a step-like x-axis. In many training setups that step is the global batch step, which is why loss curves often look very dense.
To make the x-axis represent epochs instead, you do not change TensorBoard itself. You change the step value you write with the summary.
That means the rule is:
- one summary event per batch gives batch-step plots
- one summary event per epoch with
step=epochgives epoch-based plots
Log Epoch Metrics Manually with tf.summary
A direct TensorFlow example makes this clear.
When you start TensorBoard on this log directory, the x-axis for loss_by_epoch will show the epoch index because that is the step value you provided.
Use a Keras Callback for Cleaner Training Loops
If you already train with model.fit, a callback is often the cleanest way to log epoch-level metrics.
Then pass it to training:
This keeps the training code simple while ensuring that the x-axis in TensorBoard corresponds to epochs.
Be Consistent Across Runs
If you compare several experiments, the step semantics must be consistent. If one run logs per batch and another logs per epoch using the same tag name, the comparison becomes misleading.
A good convention is to make the tag reflect the logging granularity, for example:
- '
loss_batch' - '
loss_epoch' - '
val_accuracy_epoch'
That removes ambiguity when several dashboards and runs are open.
Keras History Versus TensorBoard Logs
Some developers assume that because Keras reports one loss value per epoch in History, TensorBoard will automatically plot against epoch number. That only happens if the summaries are written at epoch boundaries with epoch-based steps.
TensorBoard is not inferring "epoch" from your training loop. It is reading whatever numeric step you wrote into the event file.
That is why explicit control of the step is the reliable answer.
Common Pitfalls
- Expecting TensorBoard to have a special epoch axis independent of the summary step.
- Logging every batch while still expecting the x-axis to represent epochs.
- Mixing per-batch and per-epoch metrics under the same tag name.
- Forgetting to flush the writer, which can make new points appear late or not at all during short runs.
- Comparing runs where the same metric tag uses different step semantics.
Summary
- TensorBoard scalar plots use the summary step for the x-axis.
- To show epoch numbers, log once per epoch and set
step=epoch. - '
tf.summary.scalarand a Keras callback are both good ways to do this.' - Keep tag names and step semantics consistent across runs.
- TensorBoard does not infer epochs automatically; it only displays the steps you write.
Related reading
- tensorboard with numpy array
- Tensorboard without fit using keras and tf
- Tensorflow-GPU import tensorflow ImportError Could not find 'cudnn64_7.dll
- Tensorflow-gpu issue CUDA runtime error device kernel image is invalid
- TensorBoard What's the difference between the time series and scalars tabs?
- Tensorboard/tensorflow with s3 logdir - curl returned error code 6
- TensorFlow - numpy-like tensor indexing
- TensorFlow - Pad unknown size tensor to a specific size?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.