MetricGroup#
- class ignite.metrics.metric_group.MetricGroup(metrics, output_transform=<function MetricGroup.<lambda>>)[source]#
A class for grouping metrics so that user could manage them easier.
- Parameters
Examples
We construct a group of metrics, attach them to the engine at once and retrieve their result.
import torch metric_group = MetricGroup({'acc': Accuracy(), 'precision': Precision(), 'loss': Loss(nn.NLLLoss())}) metric_group.attach(default_evaluator, "eval_metrics") y_true = torch.tensor([1, 0, 1, 1, 0, 1]) y_pred = torch.tensor([1, 0, 1, 0, 1, 1]) state = default_evaluator.run([[y_pred, y_true]]) # Metrics individually available in `state.metrics` state.metrics["acc"], state.metrics["precision"], state.metrics["loss"] # And also altogether state.metrics["eval_metrics"]
Methods
Computes the metric based on its accumulated state.
Resets the metric to its initial state.
Updates the metric's state using the passed batch output.
- compute()[source]#
Computes the metric based on its accumulated state.
By default, this is called at the end of each epoch.
- Returns
- the actual quantity of interest. However, if a
Mapping
is returned, it will be (shallow) flattened into engine.state.metrics whencompleted()
is called. - Return type
Any
- Raises
NotComputableError – raised when the metric cannot be computed.