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:
-
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:
-
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, andnum_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.
-
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, andnum_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.
Utility functions¶
-
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: Returns: A tile image.
Return type: tile_image (ndarray)
-
nnabla.monitor.
plot_series
(filename, plot_kwargs=None)[source]¶ Plot series data from MonitorSeries output text file.
Parameters: - filename (str) – Path to *.series.txt file produced by
MonitorSeries
class. - plot_kwags (dict, optional) – Keyward arguments passed to :function:`matplotlib.pyplot.plot`.
Note
matplotlib package is required.
- filename (str) – Path to *.series.txt file produced by