rpx_benchmark.metrics.grounding

Visual grounding metric calculators.

 1"""Visual grounding metric calculators."""
 2
 3from __future__ import annotations
 4
 5from typing import Dict
 6
 7from ..api import TaskType, VisualGroundingGroundTruth, VisualGroundingPrediction
 8from ..exceptions import MetricError
 9from .registry import MetricCalculator, register_metric
10
11
12@register_metric(TaskType.VISUAL_GROUNDING)
13class GroundingIoU(MetricCalculator):
14    """Top-1 IoU and accuracy at a threshold for a single referred object.
15
16    Parameters
17    ----------
18    iou_threshold : float
19        IoU threshold for the ``grounding_acc`` indicator. Default
20        0.5, matching standard referring expression comprehension
21        protocols.
22    """
23
24    name = "grounding_iou"
25
26    def __init__(self, iou_threshold: float = 0.5) -> None:
27        self.iou_threshold = iou_threshold
28
29    def compute(
30        self,
31        prediction: VisualGroundingPrediction,
32        ground_truth: VisualGroundingGroundTruth,
33    ) -> Dict[str, float]:
34        if not isinstance(prediction, VisualGroundingPrediction):
35            raise MetricError(
36                f"GroundingIoU expected VisualGroundingPrediction, got {type(prediction).__name__}",
37            )
38        if not isinstance(ground_truth, VisualGroundingGroundTruth):
39            raise MetricError(
40                f"GroundingIoU expected VisualGroundingGroundTruth, got "
41                f"{type(ground_truth).__name__}",
42            )
43        from ..evaluators import grounding_metrics
44
45        return grounding_metrics(
46            pred_boxes=prediction.boxes,
47            gt_boxes=ground_truth.boxes,
48            iou_threshold=self.iou_threshold,
49        )
@register_metric(TaskType.VISUAL_GROUNDING)
class GroundingIoU(rpx_benchmark.metrics.registry.MetricCalculator):
13@register_metric(TaskType.VISUAL_GROUNDING)
14class GroundingIoU(MetricCalculator):
15    """Top-1 IoU and accuracy at a threshold for a single referred object.
16
17    Parameters
18    ----------
19    iou_threshold : float
20        IoU threshold for the ``grounding_acc`` indicator. Default
21        0.5, matching standard referring expression comprehension
22        protocols.
23    """
24
25    name = "grounding_iou"
26
27    def __init__(self, iou_threshold: float = 0.5) -> None:
28        self.iou_threshold = iou_threshold
29
30    def compute(
31        self,
32        prediction: VisualGroundingPrediction,
33        ground_truth: VisualGroundingGroundTruth,
34    ) -> Dict[str, float]:
35        if not isinstance(prediction, VisualGroundingPrediction):
36            raise MetricError(
37                f"GroundingIoU expected VisualGroundingPrediction, got {type(prediction).__name__}",
38            )
39        if not isinstance(ground_truth, VisualGroundingGroundTruth):
40            raise MetricError(
41                f"GroundingIoU expected VisualGroundingGroundTruth, got "
42                f"{type(ground_truth).__name__}",
43            )
44        from ..evaluators import grounding_metrics
45
46        return grounding_metrics(
47            pred_boxes=prediction.boxes,
48            gt_boxes=ground_truth.boxes,
49            iou_threshold=self.iou_threshold,
50        )

Top-1 IoU and accuracy at a threshold for a single referred object.

Parameters

iou_threshold : float IoU threshold for the grounding_acc indicator. Default 0.5, matching standard referring expression comprehension protocols.

GroundingIoU(iou_threshold: float = 0.5)
27    def __init__(self, iou_threshold: float = 0.5) -> None:
28        self.iou_threshold = iou_threshold
name = 'grounding_iou'
iou_threshold
def compute( self, prediction: rpx_benchmark.api.VisualGroundingPrediction, ground_truth: rpx_benchmark.api.VisualGroundingGroundTruth) -> Dict[str, float]:
30    def compute(
31        self,
32        prediction: VisualGroundingPrediction,
33        ground_truth: VisualGroundingGroundTruth,
34    ) -> Dict[str, float]:
35        if not isinstance(prediction, VisualGroundingPrediction):
36            raise MetricError(
37                f"GroundingIoU expected VisualGroundingPrediction, got {type(prediction).__name__}",
38            )
39        if not isinstance(ground_truth, VisualGroundingGroundTruth):
40            raise MetricError(
41                f"GroundingIoU expected VisualGroundingGroundTruth, got "
42                f"{type(ground_truth).__name__}",
43            )
44        from ..evaluators import grounding_metrics
45
46        return grounding_metrics(
47            pred_boxes=prediction.boxes,
48            gt_boxes=ground_truth.boxes,
49            iou_threshold=self.iou_threshold,
50        )

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.