read_tensorboard_scalars
read_tensorboard_scalars(
logdir
*
tags=None
runs=None
smoothing=DEFAULT_SMOOTHING
max_points=DEFAULT_MAX_POINTS
)Read the scalar charts of a TensorBoard log directory.
One chart per tag, as TensorBoard’s Scalars dashboard draws it: the step along the x axis, the value along the y axis, and one line per run.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| logdir | str or os.PathLike | The directory TensorBoard would be started with (--logdir), such as the log_dir given to Keras’s TensorBoard callback. |
required |
| tags | iterable of str | Only these tags, in this order. By default every scalar tag, sorted. | None |
| runs | iterable of str | Only these runs, such as ["train", "validation"]. |
None |
| smoothing | float | TensorBoard’s smoothing weight, from 0 up to but not including 1. Above 0, each run is drawn twice: as logged, and smoothed, under the run’s name followed by (smoothed), as TensorBoard shows both. 0 draws the values as logged only. |
0.6 |
| max_points | int or None | At most this many points per line, evenly spaced over the steps and always keeping the first and last, so a long run stays quick to walk. None keeps every point. |
1000 |
Returns
| Name | Type | Description |
|---|---|---|
| list of TensorBoardChart | One per tag. Pass one to :func:maidr.show, :func:maidr.render or :func:maidr.save_html. |
Raises
| Name | Type | Description |
|---|---|---|
| FileNotFoundError | If logdir is not a directory. |
|
| ValueError | If smoothing is not in [0, 1) or max_points is below 2. |
Notes
Read: scalars written by Keras’s TensorBoard callback, tf.summary.scalar in TensorFlow 1 and 2, PyTorch’s torch.utils.tensorboard.SummaryWriter and tensorboardX. Histograms are read by :func:read_tensorboard_histograms and a Keras model’s graph by :func:read_tensorboard_graph; distributions, images and the other dashboards are not read yet.
Smoothing is TensorBoard’s: an exponential moving average, corrected so the first values are not pulled toward zero. It is computed over every value logged, before max_points thins the line. A value that is not finite, such as a loss that became NaN, is a gap in the line and is left out of the average, as TensorBoard leaves it out.
A damaged event file is read up to the damage, with a warning, wherever the damage reaches a record’s length. Damage inside a record’s data is not detected, since checking it would mean a checksum over every image and histogram the log directory holds, and reads as the damaged value.
Examples
>>> import maidr
>>> charts = maidr.read_tensorboard_scalars("logs/fit", tags=["epoch_loss"])
>>> maidr.save_html(charts[0], "loss.html")