Skip to content

simet.parser.simple.metric

simet.parser.simple.metric

MetricType

Bases: StrEnum

Enum of supported metric identifiers (string-valued).

Values

FID: Frechet Inception Distance. PRECISIONRECALL: Precision/Recall in feature space. ROCAUC: ROC AUC score.

Notes
  • StrEnum (Python 3.11+) ensures enum values are strings, so they can be compared directly to input strings.

get_metric staticmethod

get_metric(metric_type)

Construct a metric instance for the given MetricType.

Parameters:

Name Type Description Default
metric_type MetricType

Enum value indicating which metric to build.

required

Returns:

Name Type Description
Metric Metric

An instance of the corresponding metric implementation.

Raises:

Type Description
ValueError

If the metric type is unknown (logged and re-raised).

Source code in simet/parser/simple/metric.py
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
@staticmethod
def get_metric(metric_type: "MetricType") -> Metric:
    """Construct a metric instance for the given `MetricType`.

    Args:
        metric_type (MetricType): Enum value indicating which metric to build.

    Returns:
        Metric: An instance of the corresponding metric implementation.

    Raises:
        ValueError: If the metric type is unknown (logged and re-raised).
    """
    try:
        match metric_type:
            case MetricType.FID:
                return FID()
            case MetricType.PRECISIONRECALL:
                return PrecisionRecall()
            case MetricType.ROCAUC:
                return RocAuc()
    except ValueError as e:
        logger.error(f"Unknown metric type: {metric_type}")
        raise ValueError(f"Unknown metric type: {metric_type}") from e

SimpleMetricParser

Factory wrapper that instantiates metric objects from strings.

Converts a user-provided metric name into a MetricType enum and delegates to MetricType.get_metric(...) to construct the corresponding metric instance.

Example

SimpleMetricParser.parse_metric("FID").class.name 'FID' SimpleMetricParser.parse_metric("PrecisionRecall").class.name 'PrecisionRecall'

parse_metric staticmethod

parse_metric(metric)

Parse a metric name and return a concrete metric instance.

Parameters:

Name Type Description Default
metric str

Case-sensitive name matching MetricType values, e.g., "FID", "PrecisionRecall", or "RocAuc".

required

Returns:

Name Type Description
Metric Metric

An instance of the corresponding metric class

Metric

(e.g., FID(), PrecisionRecall(), RocAuc()).

Raises:

Type Description
ValueError

If metric does not correspond to a known MetricType.

Source code in simet/parser/simple/metric.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
@staticmethod
def parse_metric(metric: str) -> Metric:
    """Parse a metric name and return a concrete metric instance.

    Args:
        metric (str): Case-sensitive name matching `MetricType` values,
            e.g., `"FID"`, `"PrecisionRecall"`, or `"RocAuc"`.

    Returns:
        Metric: An instance of the corresponding metric class
        (e.g., `FID()`, `PrecisionRecall()`, `RocAuc()`).

    Raises:
        ValueError: If `metric` does not correspond to a known `MetricType`.
    """
    metric_type = MetricType(metric)
    return MetricType.get_metric(metric_type)