49 lines
1.8 KiB
Python
49 lines
1.8 KiB
Python
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
from typing import Any, Protocol
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class SegmentationAdapterResult:
|
|
class_name: str
|
|
confidence: float | None
|
|
geometry: dict[str, Any]
|
|
bbox_json: dict[str, Any] | None = None
|
|
mask_path: str | None = None
|
|
source_tile_path: str | None = None
|
|
tile_index: int | None = None
|
|
properties_json: dict[str, Any] | None = None
|
|
provenance_json: dict[str, Any] | None = None
|
|
area_m2: float | None = None
|
|
|
|
|
|
class SegmentationAdapter(Protocol):
|
|
def segment(self, *args: Any, **kwargs: Any) -> list[SegmentationAdapterResult]:
|
|
"""Future segmentation adapters must local-import model dependencies inside execution paths."""
|
|
|
|
|
|
class FixtureSegmentationAdapter:
|
|
def segment(self, raw_segmentations: Any) -> list[SegmentationAdapterResult]:
|
|
if not isinstance(raw_segmentations, list):
|
|
return []
|
|
results: list[SegmentationAdapterResult] = []
|
|
for raw in raw_segmentations:
|
|
if not isinstance(raw, dict):
|
|
continue
|
|
results.append(
|
|
SegmentationAdapterResult(
|
|
class_name=str(raw.get("class_name") or ""),
|
|
confidence=float(raw["confidence"]) if raw.get("confidence") is not None else None,
|
|
geometry=raw.get("geometry"),
|
|
bbox_json=raw.get("bbox_json"),
|
|
mask_path=raw.get("mask_path"),
|
|
source_tile_path=raw.get("source_tile_path"),
|
|
tile_index=raw.get("tile_index"),
|
|
properties_json=raw.get("properties_json"),
|
|
provenance_json=raw.get("provenance_json"),
|
|
area_m2=raw.get("area_m2"),
|
|
)
|
|
)
|
|
return results
|