Suppress duplicate YOLO tile detections
GeoIntel CI / docs-smoke (push) Has been cancelled
GeoIntel CI / contract-smoke (push) Has been cancelled

This commit is contained in:
Codex
2026-07-09 10:55:45 +02:00
parent 638534f011
commit 3f5ca4c85e
24 changed files with 266 additions and 39 deletions
@@ -89,6 +89,25 @@ class MixedCaseYoloAdapter(MockYoloAdapter):
]
class OverlappingTileYoloAdapter(MockYoloAdapter):
def predict_tile(self, model, tile_path: Path, confidence_threshold: float) -> list[dict]:
tile_index = int(tile_path.stem.split("_")[-1])
if tile_index == 0:
bbox = [10.0, 20.0, 30.0, 40.0]
confidence = 0.82
else:
bbox = [11.0, 21.0, 31.0, 41.0]
confidence = 0.91
return [
{
"class_name": "building",
"confidence": confidence,
"bbox": bbox,
"properties": {"adapter": "overlap"},
}
]
class RecordingPredictModel:
def __init__(self) -> None:
self.seen_sources: list[dict] = []
@@ -383,6 +402,37 @@ def test_yolo_class_filter_is_case_insensitive_and_persists_canonical_class(tmp_
assert detections[0].properties_json["model_class_name"] == "Building"
def test_yolo_run_suppresses_cross_tile_duplicate_detections(tmp_path: Path) -> None:
db, project_id, dataset_id = _project_and_dataset()
model_path = tmp_path / "model.pt"
model_path.write_bytes(b"local weights")
settings = _settings(tmp_path, yolo_model_path=str(model_path), yolo_duplicate_iou_threshold=0.5)
manifest_path = _manifest(tmp_path, tile_count=2)
result = DetectionService.run_detection(
db=db,
project_id=project_id,
dataset_id=dataset_id,
model_id="yolo-configured",
confidence_threshold=0.5,
class_filter=["building"],
tile_manifest_path=str(manifest_path),
settings=settings,
yolo_adapter_class=OverlappingTileYoloAdapter,
)
detections = [item for item in db.added if isinstance(item, Detection)]
runs = [item for item in db.added if isinstance(item, AnalysisRun)]
assert result.status == "success"
assert result.detection_count == 1
assert detections[0].confidence == 0.91
assert detections[0].source_tile_path.endswith("tile_0001.tif")
assert runs[0].result_json["raw_detection_count"] == 2
assert runs[0].result_json["suppressed_detection_count"] == 1
assert runs[0].result_json["duplicate_iou_threshold"] == 0.5
def test_yolo_adapter_converts_single_band_tiles_to_rgb_before_prediction(tmp_path: Path) -> None:
Image = pytest.importorskip("PIL.Image")
tile_path = tmp_path / "single_band_tile.tif"