rpx_benchmark.metrics.detection

Object detection + open-vocab detection metric calculators.

 1"""Object detection + open-vocab detection metric calculators."""
 2
 3from __future__ import annotations
 4
 5from typing import Dict
 6
 7from ..api import DetectionGroundTruth, DetectionPrediction, TaskType
 8from ..exceptions import MetricError
 9from .registry import MetricCalculator, register_metric
10
11
12@register_metric(TaskType.OBJECT_DETECTION)
13@register_metric(TaskType.OPEN_VOCAB_DETECTION)
14class DetectionMetrics(MetricCalculator):
15    """Precision / recall / F1 at a single IoU threshold.
16
17    Parameters
18    ----------
19    iou_threshold : float
20        Minimum IoU (0.0–1.0) for a prediction to count as a true
21        positive. Defaults to 0.5, the COCO baseline.
22
23    Notes
24    -----
25    Greedy matching by descending prediction score. A GT box is
26    consumed after the first predicted box matches it, so subsequent
27    predictions for the same object register as false positives
28    (standard VOC/COCO evaluation rule).
29    """
30
31    name = "detection_metrics"
32
33    def __init__(self, iou_threshold: float = 0.5) -> None:
34        self.iou_threshold = iou_threshold
35
36    def compute(
37        self,
38        prediction: DetectionPrediction,
39        ground_truth: DetectionGroundTruth,
40    ) -> Dict[str, float]:
41        if not isinstance(prediction, DetectionPrediction):
42            raise MetricError(
43                f"DetectionMetrics expected DetectionPrediction, got {type(prediction).__name__}",
44            )
45        if not isinstance(ground_truth, DetectionGroundTruth):
46            raise MetricError(
47                f"DetectionMetrics expected DetectionGroundTruth, got "
48                f"{type(ground_truth).__name__}",
49            )
50
51        from ..evaluators import detection_metrics
52
53        return detection_metrics(
54            pred_boxes=prediction.boxes,
55            pred_scores=prediction.scores,
56            pred_labels=prediction.labels,
57            gt_boxes=ground_truth.boxes,
58            gt_labels=ground_truth.labels,
59            iou_threshold=self.iou_threshold,
60        )
@register_metric(TaskType.OBJECT_DETECTION)
@register_metric(TaskType.OPEN_VOCAB_DETECTION)
class DetectionMetrics(rpx_benchmark.metrics.registry.MetricCalculator):
13@register_metric(TaskType.OBJECT_DETECTION)
14@register_metric(TaskType.OPEN_VOCAB_DETECTION)
15class DetectionMetrics(MetricCalculator):
16    """Precision / recall / F1 at a single IoU threshold.
17
18    Parameters
19    ----------
20    iou_threshold : float
21        Minimum IoU (0.0–1.0) for a prediction to count as a true
22        positive. Defaults to 0.5, the COCO baseline.
23
24    Notes
25    -----
26    Greedy matching by descending prediction score. A GT box is
27    consumed after the first predicted box matches it, so subsequent
28    predictions for the same object register as false positives
29    (standard VOC/COCO evaluation rule).
30    """
31
32    name = "detection_metrics"
33
34    def __init__(self, iou_threshold: float = 0.5) -> None:
35        self.iou_threshold = iou_threshold
36
37    def compute(
38        self,
39        prediction: DetectionPrediction,
40        ground_truth: DetectionGroundTruth,
41    ) -> Dict[str, float]:
42        if not isinstance(prediction, DetectionPrediction):
43            raise MetricError(
44                f"DetectionMetrics expected DetectionPrediction, got {type(prediction).__name__}",
45            )
46        if not isinstance(ground_truth, DetectionGroundTruth):
47            raise MetricError(
48                f"DetectionMetrics expected DetectionGroundTruth, got "
49                f"{type(ground_truth).__name__}",
50            )
51
52        from ..evaluators import detection_metrics
53
54        return detection_metrics(
55            pred_boxes=prediction.boxes,
56            pred_scores=prediction.scores,
57            pred_labels=prediction.labels,
58            gt_boxes=ground_truth.boxes,
59            gt_labels=ground_truth.labels,
60            iou_threshold=self.iou_threshold,
61        )

Precision / recall / F1 at a single IoU threshold.

Parameters

iou_threshold : float Minimum IoU (0.0–1.0) for a prediction to count as a true positive. Defaults to 0.5, the COCO baseline.

Notes

Greedy matching by descending prediction score. A GT box is consumed after the first predicted box matches it, so subsequent predictions for the same object register as false positives (standard VOC/COCO evaluation rule).

DetectionMetrics(iou_threshold: float = 0.5)
34    def __init__(self, iou_threshold: float = 0.5) -> None:
35        self.iou_threshold = iou_threshold
name = 'detection_metrics'
iou_threshold
def compute( self, prediction: rpx_benchmark.api.DetectionPrediction, ground_truth: rpx_benchmark.api.DetectionGroundTruth) -> Dict[str, float]:
37    def compute(
38        self,
39        prediction: DetectionPrediction,
40        ground_truth: DetectionGroundTruth,
41    ) -> Dict[str, float]:
42        if not isinstance(prediction, DetectionPrediction):
43            raise MetricError(
44                f"DetectionMetrics expected DetectionPrediction, got {type(prediction).__name__}",
45            )
46        if not isinstance(ground_truth, DetectionGroundTruth):
47            raise MetricError(
48                f"DetectionMetrics expected DetectionGroundTruth, got "
49                f"{type(ground_truth).__name__}",
50            )
51
52        from ..evaluators import detection_metrics
53
54        return detection_metrics(
55            pred_boxes=prediction.boxes,
56            pred_scores=prediction.scores,
57            pred_labels=prediction.labels,
58            gt_boxes=ground_truth.boxes,
59            gt_labels=ground_truth.labels,
60            iou_threshold=self.iou_threshold,
61        )

Return a dict of metric name → scalar for one sample.

Parameters

prediction : Any Task-specific Prediction dataclass (e.g. DepthPrediction). The concrete type is whatever the calculator is designed for. ground_truth : Any Task-specific GroundTruth dataclass (e.g. DepthGroundTruth).

Returns

dict[str, float] Metric values. Keys should be short snake_case names; values must be numeric so the runner can average them.

Raises

MetricError When inputs have the wrong shape/type/content.