chainer.training.extensions.ParameterStatistics¶
-
class
chainer.training.extensions.
ParameterStatistics
(links, statistics={'max': <function amax at 0x7fedd0f40400>, 'mean': <function mean at 0x7fedd0f40950>, 'min': <function amin at 0x7fedd0f40488>, 'percentile': <function ParameterStatistics.<lambda> at 0x7fedc55fcb70>, 'std': <function std at 0x7fedd0f409d8>, 'zeros': <function ParameterStatistics.<lambda> at 0x7fedc55fcae8>}, report_params=True, report_grads=True, prefix=None, trigger=(1, 'epoch'))[source]¶ Trainer extension to report parameter statistics.
Statistics are collected and reported for a given
Link
or an iterable ofLink
s. If a link contains child links, the statistics are reported separately for each child.Any function that takes a one-dimensional
numpy.ndarray
or acupy.ndarray
and outputs a single or multiple real numbers can be registered to handle the collection of statistics, e.g.numpy.ndarray.mean()
.The keys of reported statistics follow the convention of link name followed by parameter name, attribute name and function name, e.g.
VGG16Layers/conv1_1/W/data/mean
. They are prepended with an optional prefix and appended with integer indices if the statistics generating function return multiple values.Parameters: - links (Link or iterable of ~chainer.Link) – Link(s) containing
the parameters to observe. The link is expected to have a
name
attribute which is used as a part of the report key. - statistics (dict) – Dictionary with function name to function mappings. The name is a string and is used as a part of the report key. The function is responsible for generating the statistics.
- report_params (bool) – If
True
, report statistics for parameter values such as weights and biases. - report_grads (bool) – If
True
, report statistics for parameter gradients. - prefix (str) – Optional prefix to prepend to the report keys.
- trigger – Trigger that decides when to aggregate the results and report the values.
Methods
-
__call__
(trainer)[source]¶ Execute the statistics extension.
Collect statistics for the current state of parameters.
Note that this method will merely update its statistic summary, unless the internal trigger is fired. If the trigger is fired, the summary will also be reported and then reset for the next accumulation.
Parameters: trainer (Trainer) – Associated trainer that invoked this extension.
-
initialize
(trainer)[source]¶ Initializes up the trainer state.
This method is called before entering the training loop. An extension that modifies the state of
Trainer
can override this method to initialize it.When the trainer has been restored from a snapshot, this method has to recover an appropriate part of the state of the trainer.
For example,
ExponentialShift
extension changes the optimizer’s hyperparameter at each invocation. Note that the hyperparameter is not saved to the snapshot; it is the responsibility of the extension to recover the hyperparameter. TheExponentialShift
extension recovers it in itsinitialize
method if it has been loaded from a snapshot, or just setting the initial value otherwise.Parameters: trainer (Trainer) – Trainer object that runs the training loop.
-
register_statistics
(name, function)[source]¶ Register a function to compute a certain statistic.
The registered function will be called each time the extension runs and the results will be included in the report.
Parameters: - name (str) – Name of the statistic.
- function – Function to generate the statistic. Any function that
takes a one-dimensional
numpy.ndarray
or acupy.ndarray
and outputs a single or multiple real numbers is allowed.
- links (Link or iterable of ~chainer.Link) – Link(s) containing
the parameters to observe. The link is expected to have a