read_tensorboard_histograms

read_tensorboard_histograms(
    logdir
    *
    tags=None
    runs=None
    bins=DEFAULT_BINS
    max_steps=DEFAULT_MAX_STEPS
)

Read the histogram charts of a TensorBoard log directory, as ridgelines.

One chart per tag and run, as TensorBoard’s Histograms dashboard draws them: the tensor’s values along the x axis, and one ridge per logged step, the earliest at the bottom.

Parameters

Name Type Description Default
logdir str or os.PathLike The directory TensorBoard would be started with (--logdir), such as the log_dir of Keras’s TensorBoard callback with histogram_freq=1. required
tags iterable of str Only these tags, in this order. By default every histogram tag, sorted. None
runs iterable of str Only these runs. None
bins int How many equal bins every step is counted in. 30
max_steps int or None At most this many steps per chart, evenly spaced and always keeping the first and last. None keeps every step. 51

Returns

Name Type Description
list of TensorBoardChart One per tag and run. 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 bins is below 1 or max_steps below 2.

Notes

Read: histograms written by tf.summary.histogram in TensorFlow 1 and 2, Keras’s TensorBoard callback with histogram_freq set, and PyTorch’s SummaryWriter.add_histogram.

Each writer buckets the values its own way, and a step’s buckets need not line up with the next step’s: PyTorch’s default writes hundreds of unevenly wide ones. So every step is counted again in the same bins equal bins, spanning every value the chart’s steps logged, with a bucket’s count shared among the bins it overlaps in proportion to the overlap. Moving from one step to the next then lands on the same bin, and the counts compare.

Up and Down move between steps, Up to a later one, holding the bin; Left and Right move along one step’s distribution.

Examples

>>> import maidr
>>> for chart in maidr.read_tensorboard_histograms("logs/fit"):
...     maidr.save_html(chart, f"{chart.tag.replace('/', '_')}.html")