Monitors

The Monitor API provides helpers for logging the progress of neural network training.

class nnabla.monitor.Monitor(save_path)[source]

This class is created to setup the output directory of the monitoring logs. The created nnabla.monitor.Monitor instance is passed to classes in the following Monitors.

List of Monitors

class nnabla.monitor.MonitorSeries(name, monitor=None, interval=1, verbose=True)[source]

Logs a series of values.

The values are displayed and/or output to the file <name>-series.txt.

Example:

mons = MonitorSeries('mon', interval=2)
for i in range(10):
    mons.add(i, i * 2)
Parameters:
  • name (str) – Name of the monitor. Used in the log.
  • monitor (Monitor) – Monitor class instance.
  • interval (int) – Interval of flush the outputs. The values added by .add() are averaged during interval.
  • verbose (bool) – Output to screen.
add(index, value)[source]

Add a value to the series.

Parameters:
  • index (int) – Index.
  • value (float) – Value.
class nnabla.monitor.MonitorTimeElapsed(name, monitor=None, interval=100, verbose=True)[source]

Logs the elapsed time.

The values are displayed and/or output to the file <name>-timer.txt.

Example:

import time
mont = MonitorTimeElapsed("time", interval=2)
for i in range(10):
    time.sleep(1)
    mont.add(i)
Parameters:
  • name (str) – Name of the monitor. Used in the log.
  • monitor (Monitor) – Monitor class instance.
  • interval (int) – Interval of flush the outputs. The elapsed time is calculated within the interval.
  • verbose (bool) – Output to screen.
add(index)[source]

Calculate time elapsed from the point previously called this method or this object is created to this is called.

Parameters:index (int) – Index to be displayed, and be used to take intervals.
class nnabla.monitor.MonitorImage(name, monitor, interval=1000, verbose=True, num_images=16, normalize_method=None)[source]

Saves a series of images.

The .add() method takes a (N,..., C, H, W) array as an input, and num_images of [H, W, :min(3, C)] are saved into the monitor folder for each interval.

The values are displayed and/or output to the file <name>/{iter}-{image index}.png.

Example:

import numpy as np
m = Monitor('tmp.monitor')
mi = MonitorImage('noise', m, interval=2, num_images=2)
x = np.random.randn(10, 3, 8, 8)
for i in range(10):
    mi.add(i, x)
Parameters:
  • name (str) – Name of the monitor. Used in the log.
  • monitor (Monitor) – Monitor class instance.
  • interval (int) – Interval of flush the outputs.
  • num_images (int) – Number of images to be saved in each iteration.
  • normalize_method (function) – A function that takes a NCHW format image minibatch as numpy.ndarray. The function should define a normalizer which map any inputs to a range of [0, 1]. The default normalizer normalizes the images into min-max normalization.
add(index, var)[source]

Add a minibatch of images to the monitor.

Parameters:
  • index (int) – Index.
  • var (Variable, NdArray, or ndarray) – A minibatch of images with (N, ..., C, H, W) format. If C == 2, blue channel is appended with ones. If C > 3, the array will be sliced to remove C > 3 sub-array.
class nnabla.monitor.MonitorImageTile(name, monitor, interval=1000, verbose=True, num_images=16, normalize_method=None)[source]

Saving a series of images.

The .add() method takes a (N,..., C, H, W) array as an input, and num_images tiled (H, W, :min(3, C)) images are saved into the monitor folder for each interval.

The values are displayed and/or output to the file <name>/{iter}-{image index}.png.

Example:

import numpy as np
m = Monitor('tmp.monitor')
mi = MonitorImageTile('noise_noise', m, interval=2, num_images=4)
x = np.random.randn(10, 3, 8, 8)
for i in range(10):
    mi.add(i, x)
Parameters:
  • name (str) – Name of the monitor. Used in the log.
  • monitor (Monitor) – Monitor class instance.
  • interval (int) – Interval of flush the outputs.
  • num_images (int) – Number of images tiled to be saved into a single image in each iteration.
  • normalize_method (function) – A function that takes a NCHW format image minibatch as numpy.ndarray. The function should define a normalizer which map any inputs to a range of [0, 1]. The default normalizer normalizes the images into min-max normalization.
add(index, var)[source]

Add a minibatch of images to the monitor.

Parameters:
  • index (int) – Index.
  • var (Variable, NdArray, or ndarray) – A minibatch of images with (N, ..., C, H, W) format. If C == 2, blue channel is appended with ones. If C > 3, the array will be sliced to remove C > 3 sub-array.
nnabla.monitor.tile_images(data, padsize=1, padval=0)[source]

Convert an array with shape of (B, C, H, W) into a tiled image.

Parameters:
  • data (ndarray) – An array with shape of (B, C, H, W).
  • padsize (int) – Each tile has padding with this size.
  • padval (float) – Padding pixels are filled with this value.
Returns:

A tile image.

Return type:

tile_image (ndarray)