Add auditable SAM roof label refinement
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
SCRIPT = Path(__file__).parents[2] / "scripts" / "build_regional_yolo_dataset.py"
|
||||
SPEC = importlib.util.spec_from_file_location("regional_yolo_dataset", SCRIPT)
|
||||
assert SPEC and SPEC.loader
|
||||
MODULE = importlib.util.module_from_spec(SPEC)
|
||||
SPEC.loader.exec_module(MODULE)
|
||||
|
||||
|
||||
def test_select_paths_is_region_and_split_safe() -> None:
|
||||
manifest = {
|
||||
"samples": [
|
||||
{"sample_slug": "f-train", "region": "flanders", "split": "train"},
|
||||
{"sample_slug": "f-val", "region": "flanders", "split": "val"},
|
||||
{"sample_slug": "f-test", "region": "flanders", "split": "test"},
|
||||
{"sample_slug": "w-train", "region": "wallonia", "split": "train"},
|
||||
]
|
||||
}
|
||||
summary = {
|
||||
"tiles": [
|
||||
{"sample_slug": "f-train", "split": "train", "image_path": "/f-train.png"},
|
||||
{"sample_slug": "f-val", "split": "val", "image_path": "/f-val.png"},
|
||||
{"sample_slug": "f-test", "split": "val", "image_path": "/f-test.png"},
|
||||
{"sample_slug": "w-train", "split": "train", "image_path": "/w-train.png"},
|
||||
]
|
||||
}
|
||||
train, val = MODULE.select_paths(summary, manifest, "flanders")
|
||||
assert train == ["/f-train.png"]
|
||||
assert val == ["/f-val.png"]
|
||||
@@ -0,0 +1,23 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
SCRIPT = Path(__file__).parents[2] / "scripts" / "refine_yolo_labels_with_sam.py"
|
||||
SPEC = importlib.util.spec_from_file_location("sam_roof_refinement", SCRIPT)
|
||||
assert SPEC and SPEC.loader
|
||||
MODULE = importlib.util.module_from_spec(SPEC)
|
||||
SPEC.loader.exec_module(MODULE)
|
||||
|
||||
|
||||
def test_plausible_refinement_is_fail_closed() -> None:
|
||||
source = (10.0, 10.0, 30.0, 30.0)
|
||||
assert MODULE.plausible_refinement(source, (8.0, 9.0, 31.0, 32.0), min_iou=0.15, min_area_ratio=0.25, max_area_ratio=4.0)
|
||||
assert not MODULE.plausible_refinement(source, (100.0, 100.0, 120.0, 120.0), min_iou=0.15, min_area_ratio=0.25, max_area_ratio=4.0)
|
||||
assert not MODULE.plausible_refinement(source, (0.0, 0.0, 100.0, 100.0), min_iou=0.15, min_area_ratio=0.25, max_area_ratio=4.0)
|
||||
|
||||
|
||||
def test_yolo_round_trip_shape() -> None:
|
||||
line = MODULE.yolo_line((10.0, 20.0, 30.0, 40.0), 100, 100)
|
||||
assert line == "0 0.20000000 0.30000000 0.20000000 0.20000000"
|
||||
Reference in New Issue
Block a user