pytorch_pfn_extras.reporting.report#

pytorch_pfn_extras.reporting.report(values, observer=None)#

Reports observed values with the current reporter object.

Any reporter object can be set current by the with statement. This function calls the Reporter.report() method of the current reporter. If no reporter object is current, this function does nothing.

Example

The most typical example is a use within nn.Module. Suppose that a module is registered to the current reporter as an observer (for example, the target module of the optimizer is automatically registered to the main reporter. We can report some values from the link as follows:

class MyRegressor:
    def __init__(self, predictor):
        super().__init__(predictor=predictor)

    def __call__(self, x, y):
        # This chain just computes the mean absolute and squared
        # errors between the prediction and y.
        pred = self.predictor(x)
        abs_error = F.sum(abs(pred - y)) / len(x)
        loss = F.mean_squared_error(pred, y)

        # Report the mean absolute and squared errors.
        reporter.report({
            'abs_error': abs_error,
            'squared_error': loss,
        }, self)

        return loss

If the module is named 'main' in the hierarchy these reported values are named 'main/abs_error' and 'main/squared_error'.

Parameters:
  • values (dict) – Dictionary of observed values.

  • observer (Optional[Module]) – Observer object. Its object ID is used to retrieve the observer name, which is used as the prefix of the registration name of the observed value.

Return type:

None