From 62feff20098bdd5f6ad92eb324ac5838cf670120 Mon Sep 17 00:00:00 2001 From: Sadra Barikbin Date: Tue, 16 Jul 2024 19:26:02 +0330 Subject: [PATCH] Initial commit --- ignite/metrics/metric_group.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 ignite/metrics/metric_group.py diff --git a/ignite/metrics/metric_group.py b/ignite/metrics/metric_group.py new file mode 100644 index 00000000000..fdbba17ad5c --- /dev/null +++ b/ignite/metrics/metric_group.py @@ -0,0 +1,20 @@ +from typing import Any, Dict + +from ignite.metrics import Metric + + +class MetricGroup(Metric): + def __init__(self, metrics: Dict[str, Metric]): + self.metrics = metrics + super(MetricGroup, self).__init__() + + def reset(self): + for m in self.metrics.values(): + m.reset() + + def update(self, output): + for m in self.metrics.values(): + m.update(m._output_transform(output)) + + def compute(self) -> Dict[str, Any]: + return {k: m.compute() for k, m in self.metrics.items()}