utils.tensorboard

Writes scalar and image data to tensorboard.

class utils.tensorboard.HDFData(path: str = None, key: str = None, buffer: dict = None)

Reads HDF5 data logged to disk by DataAccumulatorHook.

Parameters:
  • path (str, optional) – Path to HDF5 data file.

  • key (str, optional) – Specific key to read from HDF5. If not provided, the entire file will be read.

  • buffer (dict, optional) – For initializing an HDFData object with a preexisting dictionary, e.g. to save hyperparameters computed at runtime.

Warning

This class assumes that the HDF5 file only contains labeled datasets, not groups, in accordance with the current implementation of DataAccumulatorHook. A generalized data loading protocol is being developed.

read()

Extracts desired datasets and/or fields from HDF5 file and adds them to the buffer.

class utils.tensorboard.TensorboardWriter(log_dir: str)

Reusable SummaryWriter instance endowed with methods handling tensorboard file I/O given a data object.

For ease of use, write() can be called with a multi-data buffer, e.g. in cases where the same plotting settings apply to all objects.

Parameters:

log_dir (str) – Path to target tensorboard directory.

heatmap(name: str, attr: str, array: ndarray, settings: dict)

Adds 2D numeric data to tensorboard as a heatmap.

hparam(name: str, attr: str, array: ndarray, settings: dict)

Writes singleton hyperparameters, such as configurable attributes, to tensorboard.

If you would like to visualize non-singleton configurable attributes (e.g., synaptic delays), please use one of the other plotting methods.

Warning

Tensorboard’s add_hparams() will not allow writing different hparams sequentially (after the first one, they turn into scalars). It also cannot handle writing of a hyperparameter without an accompanying metric.

Any workaround will likely require patching tensorboard, a task left to the intrepid maintainer. For now, configurable attributes can be logged as scalars for easy viewing of parameter value distributions.

Sapicore may end up using a better maintained data visualization library.

raster(name: str, array: ndarray | Tensor, settings: dict)

Adds 1D integer binary data to tensorboard as a raster plot.

trace(name: str, attr: str, array: ndarray, settings: dict)

Adds 1D numeric trace data to tensorboard as a scalar plot or an image.

write(data: HDFData, key: str, **settings)

Writes data to tensorboard using settings.

Parameters:
  • data (HDFData) – Object holding buffered data as a dictionary.

  • key (str) – Key of configurable or loggable to process in this iteration.

  • settings

    The following optional arguments control how data is visualized:

    kind: str

    Kind of plot or data to write, currently supports “raster”, “trace”, “heatmap”, “hparam”.

    format: str

    Whether to write a 2D time series as an “image” or a “scalar” data to tensorboard. Will default to image for 3D time series (e.g., weight matrix + time).

    size: tuple of int

    Two-item tuple specifying figure size to be passed on to plt.rcParams[“figure.figsize”].

    step: int

    Where applicable, size of skip step when plotting a time series on an interactive slider plot. E.g., we don’t want to plot a weight matrix for every 1.0 ms simulation step, so we set step=10.

    time_axis: int

    Specify which axis of the array corresponds to time steps. Used for stacking images in interactive tensorboard slider plots.