Skip to content

simet.metrics.base.metric

simet.metrics.base.metric

Metric

Bases: ABC

Abstract interface for evaluation metrics computed from a DatasetLoader.

This generic base class defines the minimal contract every metric must implement: a human-readable name and a compute(loader) method that returns a result of type T (e.g., float, tuple[float, float], or a small dataclass).

Class Type Parameters:

Name Bound or Constraints Description Default
T

The result type returned by :meth:compute. Examples: float for scalar scores (FID, ROC AUC) or tuple[float, float] for multi-valued metrics (precision, recall).

required
Example

class Accuracy(Metric[float]): ... @property ... def name(self) -> str: ... return "Accuracy" ... ... def compute(self, loader: DatasetLoader) -> float: ... # compute accuracy from loader ... ... return 0.95

name abstractmethod property

name

Human-readable metric name (used in logs and reports).

compute abstractmethod

compute(loader)

Compute the metric using data/features from loader.

Implementations may pull precomputed features from the loader or run their own forward passes as needed.

Parameters:

Name Type Description Default
loader DatasetLoader

Source of datasets/dataloaders and (optionally) precomputed feature arrays.

required

Returns:

Name Type Description
T T

The metric result (scalar or structured), as defined by the

T

concrete metric implementation.

Source code in simet/metrics/base/metric.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
@abstractmethod
def compute(self, loader: DatasetLoader) -> T:
    """Compute the metric using data/features from `loader`.

    Implementations may pull precomputed features from the loader or run
    their own forward passes as needed.

    Args:
        loader (DatasetLoader): Source of datasets/dataloaders and (optionally)
            precomputed feature arrays.

    Returns:
        T: The metric result (scalar or structured), as defined by the
        concrete metric implementation.
    """
    pass