Suppress duplicate YOLO tile detections
This commit is contained in:
@@ -94,6 +94,7 @@ def test_env_example_uses_runtime_env_names_read_by_backend_and_frontend() -> No
|
||||
assert "YOLO_CONFIG_DIR=./storage/ultralytics" in env_example
|
||||
assert "YOLO_MAX_TILES=100" in env_example
|
||||
assert "YOLO_MAX_DETECTIONS=1000" in env_example
|
||||
assert "YOLO_DUPLICATE_IOU_THRESHOLD=0.5" in env_example
|
||||
assert "ENABLE_YOLO" not in env_example
|
||||
assert "ENABLE_SAM" not in env_example
|
||||
assert "VITE_API_BASE_URL=" in env_example
|
||||
@@ -247,4 +248,5 @@ def test_unraid_deploy_passes_ai_build_arg_and_yolo_runtime_env() -> None:
|
||||
assert '-e YOLO_MODEL_PATH="$YOLO_MODEL_PATH"' in run_script
|
||||
assert '-e YOLO_MAX_TILES="$YOLO_MAX_TILES"' in run_script
|
||||
assert '-e YOLO_MAX_DETECTIONS="$YOLO_MAX_DETECTIONS"' in run_script
|
||||
assert '-e YOLO_DUPLICATE_IOU_THRESHOLD="$YOLO_DUPLICATE_IOU_THRESHOLD"' in run_script
|
||||
assert "-v \"${GEOINTEL_MODELS_PATH}:/app/models\"" in run_script
|
||||
|
||||
@@ -18,7 +18,11 @@ def test_detection_calibration_sweep_reuses_real_data_workflow_and_reports_qa_me
|
||||
assert "REAL_RASTER_PATH" in script
|
||||
assert "REAL_REFERENCE_VECTOR_PATH" in script
|
||||
assert "/api/v1/projects/${project_id}/quality-checks" in script
|
||||
assert "/api/v1/detection/runs/${analysis_run_id}" in script
|
||||
assert "quality_check_id" in script
|
||||
assert "raw_detection_count" in script
|
||||
assert "suppressed_detection_count" in script
|
||||
assert "duplicate_iou_threshold" in script
|
||||
assert "false_positives" in script
|
||||
assert "false_negatives" in script
|
||||
assert "quality_score" in script
|
||||
|
||||
@@ -24,7 +24,11 @@ def test_detection_quality_matrix_compares_models_tiles_and_thresholds() -> None
|
||||
assert "REAL_RASTER_PATH" in script
|
||||
assert "REAL_REFERENCE_VECTOR_PATH" in script
|
||||
assert "/api/v1/projects/${project_id}/quality-checks" in script
|
||||
assert "/api/v1/detection/runs/${analysis_run_id}" in script
|
||||
assert "quality_matrix_summary.json" in script
|
||||
assert "raw_detection_count" in script
|
||||
assert "suppressed_detection_count" in script
|
||||
assert "duplicate_iou_threshold" in script
|
||||
assert "best_by_score" in script
|
||||
assert "best_by_recall" in script
|
||||
assert "best_by_precision" in script
|
||||
|
||||
@@ -66,6 +66,8 @@ def test_multi_sample_detection_quality_matrix_runs_existing_matrix_for_each_sam
|
||||
assert "best_overall_by_score" in script
|
||||
assert "best_by_sample" in script
|
||||
assert "sample_slug" in script
|
||||
assert "raw_detection_count" in script
|
||||
assert "suppressed_detection_count" in script
|
||||
assert "demo/workflow" not in script
|
||||
assert "fixture_mode" not in script
|
||||
assert "will_download_models" not in script
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user