pytorch_pfn_extras.reporting.Reporter

class pytorch_pfn_extras.reporting.Reporter

Object to which observed values are reported.

Reporter is used to collect values that users want to watch. The reporter object holds a mapping from value names to the actually observed values. We call this mapping observations.

When a value is passed to the reporter, an object called observer can be optionally attached. In this case, the name of the observer is added as the prefix of the value name. The observer name should be registered beforehand.

See the following example:

>>> from pytorch_pfn_extras.reporting import Reporter, report, report_scope
>>>
>>> reporter = Reporter()
>>> observer = object()  # it can be an arbitrary (reference) object
>>> reporter.add_observer('my_observer', observer)
>>> observation = {}
>>> with reporter.scope(observation):
...     reporter.report({'x': 1}, observer)
...
>>> observation
{'my_observer/x': 1}

There are also a global API to add values:

>>> reporter = Reporter()
>>> observation = {}
>>> with reporter:
...     with report_scope(observation):
...         report({'x': 1})
...
>>> observation
{'x': 1}

The most important application of Reporter is to report observed values from each link or chain in the training and validation procedures. and some extensions prepare their own Reporter object with the hierarchy of the target module registered as observers. We can use report() function inside any nn.Module to report the observed values (e.g., training loss, accuracy, activation statistics, etc.).

observation

Dictionary of observed values.

__init__()

Methods

__init__()

add_observer(name, observer)

Registers an observer of values.

add_observers(prefix, observers)

Registers multiple observers at once.

report(values[, observer])

Reports observed values.

scope(observation)

Creates a scope to report observed values to observation.