Add fail-closed Belgian training loop
GeoIntel release gates / Compile, test, contracts and builds (push) Canceled after 0s
GeoIntel release gates / Python and npm vulnerability policy (push) Canceled after 0s
GeoIntel release gates / GIS image, SBOM and container scan (push) Canceled after 0s

This commit is contained in:
Jens
2026-07-27 02:29:14 +02:00
parent 3325b94d59
commit e607cbe724
11 changed files with 424 additions and 4 deletions
@@ -0,0 +1,24 @@
from __future__ import annotations
import importlib.util
from pathlib import Path
SCRIPT = Path(__file__).parents[2] / "scripts" / "evaluate_belgium_building_candidate.py"
SPEC = importlib.util.spec_from_file_location("candidate_evaluation", SCRIPT)
assert SPEC and SPEC.loader
MODULE = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(MODULE)
def test_iou_and_one_to_one_matching() -> None:
reference = [(0.0, 0.0, 10.0, 10.0)]
predictions = [((0.0, 0.0, 10.0, 10.0), 0.9), ((0.0, 0.0, 10.0, 10.0), 0.8)]
assert MODULE.iou(reference[0], reference[0]) == 1.0
assert MODULE.match_boxes(predictions, reference, confidence=0.25, match_iou=0.5) == (1, 1, 0)
def test_empty_reference_counts_false_positives() -> None:
predictions = [((0.0, 0.0, 10.0, 10.0), 0.4)]
assert MODULE.match_boxes(predictions, [], confidence=0.25, match_iou=0.5) == (0, 1, 0)
assert MODULE.match_boxes(predictions, [], confidence=0.5, match_iou=0.5) == (0, 0, 0)
@@ -0,0 +1,26 @@
from __future__ import annotations
import importlib.util
from pathlib import Path
SCRIPT = Path(__file__).parents[2] / "scripts" / "assess_belgium_building_training_iteration.py"
SPEC = importlib.util.spec_from_file_location("iteration_assessment", SCRIPT)
assert SPEC and SPEC.loader
MODULE = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(MODULE)
def test_calibration_selection_prefers_worst_region_then_aggregate() -> None:
report = {
"sweeps": [
{"threshold": 0.1, "pure_empty_false_positives": 0, "aggregate": {"f1": 0.8}, "regions": {"a": {"f1": 0.2}}},
{"threshold": 0.2, "pure_empty_false_positives": 0, "aggregate": {"f1": 0.6}, "regions": {"a": {"f1": 0.5}}},
]
}
assert MODULE.select_calibration_threshold(report)["threshold"] == 0.2
def test_threshold_lookup_is_exact() -> None:
report = {"sweeps": [{"threshold": 0.25, "aggregate": {}}]}
assert MODULE.find_threshold(report, 0.25)["threshold"] == 0.25
@@ -19,10 +19,10 @@ def test_portfolio_covers_every_region_split_and_context_family() -> None:
assert len({aoi.slug for aoi in module.AOIS}) == len(module.AOIS)
counts = Counter((aoi.region, aoi.split) for aoi in module.AOIS)
for region in module.REGION_CONTRACT:
assert counts[(region, "train")] >= 6
assert counts[(region, "train")] >= 10
assert counts[(region, "val")] >= 2
assert counts[(region, "calibration")] >= 2
assert counts[(region, "test")] >= 2
assert counts[(region, "calibration")] >= 3
assert counts[(region, "test")] >= 3
assert counts[(region, "background-test")] >= 2