rpx_benchmark.tasks.segmentation

Object (instance) segmentation.

 1"""Object (instance) segmentation."""
 2
 3from __future__ import annotations
 4
 5from dataclasses import dataclass
 6
 7from ..api import TaskType
 8from ._pipeline import PipelineResult, TaskRunConfig, run_pipeline
 9from .registry import TaskSpec, register_task
10
11PRIMARY_METRIC = "miou"
12
13
14@dataclass
15class SegmentationRunConfig(TaskRunConfig):
16    pass
17
18
19def run_segmentation(cfg: SegmentationRunConfig) -> PipelineResult:
20    return run_pipeline(
21        task=TaskType.OBJECT_SEGMENTATION,
22        primary_metric=PRIMARY_METRIC,
23        cfg=cfg,
24        compute_ts=True,
25    )
26
27
28def _temporal_stability_hook(predictions, samples, camera_poses):
29    from ..deployment import compute_temporal_stability_seg
30
31    return compute_temporal_stability_seg([p.mask for p in predictions], camera_poses)
32
33
34def _geometric_coherence_hook(predictions, samples):
35    """SGC needs paired mask + depth. Depth arrives via sample.metadata."""
36    import numpy as np
37
38    from ..deployment import compute_sgc
39
40    pairs = [
41        (p.mask, s.metadata["depth_map"])
42        for p, s in zip(predictions, samples, strict=False)
43        if s.metadata and s.metadata.get("depth_map") is not None
44    ]
45    if not pairs:
46        return None
47    masks = [m for m, _ in pairs]
48    depths = [np.asarray(d, dtype=np.float32) for _, d in pairs]
49    return compute_sgc(masks, depths)
50
51
52TASK_SPEC = TaskSpec(
53    task=TaskType.OBJECT_SEGMENTATION,
54    display_name="Object Segmentation",
55    description="Instance mask from a single RGB frame; scored with mIoU.",
56    primary_metric=PRIMARY_METRIC,
57    required_modalities=["rgb", "mask"],
58    higher_is_better=True,
59    run=run_segmentation,
60    temporal_stability_fn=_temporal_stability_hook,
61    geometric_coherence_fn=_geometric_coherence_hook,
62)
63
64register_task(TASK_SPEC)
PRIMARY_METRIC = 'miou'
@dataclass
class SegmentationRunConfig(rpx_benchmark.tasks._pipeline.TaskRunConfig):
15@dataclass
16class SegmentationRunConfig(TaskRunConfig):
17    pass

SegmentationRunConfig(model: 'Optional[BenchmarkableModel]' = None, split: 'Difficulty | str' = , repo_id: 'Optional[str]' = None, cache_dir: 'Optional[str]' = None, revision: 'Optional[str]' = '51432e5d48895bbafb490ae7c5e34e0f6b7da7d6', batch_size: 'int' = 1, require_cuda: 'bool' = False, skip_flops: 'bool' = False, max_samples: 'Optional[int]' = None, manifest_path: 'Optional[str]' = None, device: 'str' = 'cuda', output_dir: 'Optional[str]' = None, progress: 'Optional[ProgressCallback]' = None, metric_suite: 'Optional[MetricSuite]' = None, upload_to_box: 'bool' = False, box_folder_id: 'Optional[str]' = None)

SegmentationRunConfig( model: Optional[rpx_benchmark.adapters.BenchmarkableModel] = None, split: rpx_benchmark.api.Difficulty | str = <Difficulty.HARD: 'hard'>, repo_id: Optional[str] = None, cache_dir: Optional[str] = None, revision: Optional[str] = '51432e5d48895bbafb490ae7c5e34e0f6b7da7d6', batch_size: int = 1, require_cuda: bool = False, skip_flops: bool = False, max_samples: Optional[int] = None, manifest_path: Optional[str] = None, device: str = 'cuda', output_dir: Optional[str] = None, progress: Optional[Callable[[int, Optional[int], str], NoneType]] = None, metric_suite: Optional[rpx_benchmark.metrics.MetricSuite] = None, upload_to_box: bool = False, box_folder_id: Optional[str] = None)
def run_segmentation( cfg: SegmentationRunConfig) -> Tuple[rpx_benchmark.metrics.registry.BenchmarkResult, rpx_benchmark.deployment.DeploymentReadinessReport, Dict[str, pathlib.Path]]:
20def run_segmentation(cfg: SegmentationRunConfig) -> PipelineResult:
21    return run_pipeline(
22        task=TaskType.OBJECT_SEGMENTATION,
23        primary_metric=PRIMARY_METRIC,
24        cfg=cfg,
25        compute_ts=True,
26    )
TASK_SPEC = TaskSpec(task=<TaskType.OBJECT_SEGMENTATION: 'object_segmentation'>, display_name='Object Segmentation', primary_metric='miou', required_modalities=['rgb', 'mask'], run=<function run_segmentation>, higher_is_better=True, description='Instance mask from a single RGB frame; scored with mIoU.', temporal_stability_fn=<function _temporal_stability_hook>, geometric_coherence_fn=<function _geometric_coherence_hook>)