rpx_benchmark.metrics.sparse_depth

Sparse depth metric calculators (RGB + sparse GT depth points).

 1"""Sparse depth metric calculators (RGB + sparse GT depth points)."""
 2
 3from __future__ import annotations
 4
 5from typing import Dict
 6
 7from ..api import SparseDepthGroundTruth, SparseDepthPrediction, TaskType
 8from ..exceptions import MetricError
 9from .registry import MetricCalculator, register_metric
10
11
12@register_metric(TaskType.SPARSE_DEPTH)
13class SparseDepthError(MetricCalculator):
14    """AbsRel + RMSE computed only at the provided sparse GT locations.
15
16    Parameters
17    ----------
18    radius : float
19        Maximum pixel distance between a prediction point and the
20        matched GT point. Predictions outside this radius contribute a
21        full-magnitude error, which penalises models that fail to
22        localise the sparse points.
23    """
24
25    name = "sparse_depth_error"
26
27    def __init__(self, radius: float = 2.0) -> None:
28        self.radius = radius
29
30    def compute(
31        self,
32        prediction: SparseDepthPrediction,
33        ground_truth: SparseDepthGroundTruth,
34    ) -> Dict[str, float]:
35        if not isinstance(prediction, SparseDepthPrediction):
36            raise MetricError(
37                f"SparseDepthError expected SparseDepthPrediction, got {type(prediction).__name__}",
38            )
39        if not isinstance(ground_truth, SparseDepthGroundTruth):
40            raise MetricError(
41                f"SparseDepthError expected SparseDepthGroundTruth, got "
42                f"{type(ground_truth).__name__}",
43            )
44        from ..evaluators import sparse_depth_metrics
45
46        return sparse_depth_metrics(
47            pred_coords=prediction.coordinates,
48            pred_depths=prediction.depths,
49            gt_coords=ground_truth.coordinates,
50            gt_depths=ground_truth.depths,
51            radius=self.radius,
52        )
@register_metric(TaskType.SPARSE_DEPTH)
class SparseDepthError(rpx_benchmark.metrics.registry.MetricCalculator):
13@register_metric(TaskType.SPARSE_DEPTH)
14class SparseDepthError(MetricCalculator):
15    """AbsRel + RMSE computed only at the provided sparse GT locations.
16
17    Parameters
18    ----------
19    radius : float
20        Maximum pixel distance between a prediction point and the
21        matched GT point. Predictions outside this radius contribute a
22        full-magnitude error, which penalises models that fail to
23        localise the sparse points.
24    """
25
26    name = "sparse_depth_error"
27
28    def __init__(self, radius: float = 2.0) -> None:
29        self.radius = radius
30
31    def compute(
32        self,
33        prediction: SparseDepthPrediction,
34        ground_truth: SparseDepthGroundTruth,
35    ) -> Dict[str, float]:
36        if not isinstance(prediction, SparseDepthPrediction):
37            raise MetricError(
38                f"SparseDepthError expected SparseDepthPrediction, got {type(prediction).__name__}",
39            )
40        if not isinstance(ground_truth, SparseDepthGroundTruth):
41            raise MetricError(
42                f"SparseDepthError expected SparseDepthGroundTruth, got "
43                f"{type(ground_truth).__name__}",
44            )
45        from ..evaluators import sparse_depth_metrics
46
47        return sparse_depth_metrics(
48            pred_coords=prediction.coordinates,
49            pred_depths=prediction.depths,
50            gt_coords=ground_truth.coordinates,
51            gt_depths=ground_truth.depths,
52            radius=self.radius,
53        )

AbsRel + RMSE computed only at the provided sparse GT locations.

Parameters

radius : float Maximum pixel distance between a prediction point and the matched GT point. Predictions outside this radius contribute a full-magnitude error, which penalises models that fail to localise the sparse points.

SparseDepthError(radius: float = 2.0)
28    def __init__(self, radius: float = 2.0) -> None:
29        self.radius = radius
name = 'sparse_depth_error'
radius
def compute( self, prediction: rpx_benchmark.api.SparseDepthPrediction, ground_truth: rpx_benchmark.api.SparseDepthGroundTruth) -> Dict[str, float]:
31    def compute(
32        self,
33        prediction: SparseDepthPrediction,
34        ground_truth: SparseDepthGroundTruth,
35    ) -> Dict[str, float]:
36        if not isinstance(prediction, SparseDepthPrediction):
37            raise MetricError(
38                f"SparseDepthError expected SparseDepthPrediction, got {type(prediction).__name__}",
39            )
40        if not isinstance(ground_truth, SparseDepthGroundTruth):
41            raise MetricError(
42                f"SparseDepthError expected SparseDepthGroundTruth, got "
43                f"{type(ground_truth).__name__}",
44            )
45        from ..evaluators import sparse_depth_metrics
46
47        return sparse_depth_metrics(
48            pred_coords=prediction.coordinates,
49            pred_depths=prediction.depths,
50            gt_coords=ground_truth.coordinates,
51            gt_depths=ground_truth.depths,
52            radius=self.radius,
53        )

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.