- class ignite.metrics.Average(output_transform=<function Average.<lambda>>, device=device(type='cpu'))#
Helper class to compute arithmetic average of a single variable.
updatemust receive output of the form x.
x can be a number or torch.Tensor.
Number of samples is updated following the rule:
+1 if input is a number
+1 if input is a 1D torch.Tensor
+batch_size if input is an ND torch.Tensor. Batch size is the first dimension (shape).
For input x being an ND torch.Tensor with N > 1, the first dimension is seen as the number of samples and is summed up and added to the accumulator: accumulator += x.sum(dim=0)
output_transform (Callable) – a callable that is used to transform the
process_function’s output into the form expected by the metric. This can be useful if, for example, you have a multi-output model and you want to compute the metric with respect to one of the outputs.
device (Union[str, torch.device]) – specifies which device updates are accumulated on. Setting the metric’s device to be the same as your
updatearguments ensures the
updatemethod is non-blocking. By default, CPU.
evaluator = ... custom_var_mean = Average(output_transform=lambda output: output['custom_var']) custom_var_mean.attach(evaluator, 'mean_custom_var') state = evaluator.run(dataset) # state.metrics['mean_custom_var'] -> average of output['custom_var']
Computes the metric based on it's accumulated state.