Files
geointel/tests/test_building_proposal_classifier.py
T
Jens 68099b4a4e
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
Add hard-negative proposal classifier pipeline
2026-07-30 01:38:39 +02:00

41 lines
1.4 KiB
Python

from __future__ import annotations
import importlib.util
from pathlib import Path
import pytest
ROOT = Path(__file__).resolve().parents[1]
def load(name: str):
path = ROOT / "scripts" / f"{name}.py"
spec = importlib.util.spec_from_file_location(name, path)
assert spec and spec.loader
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
miner = load("build_building_proposal_classifier_dataset")
trainer = load("train_building_proposal_classifier")
def test_classify_proposals_consumes_reference_once() -> None:
reference = [(0.0, 0.0, 10.0, 10.0)]
proposals = [((0.0, 0.0, 10.0, 10.0), 0.9), ((0.0, 0.0, 10.0, 10.0), 0.8)]
assert [item[0] for item in miner.classify_proposals(proposals, reference, 0.25)] == ["positive", "negative"]
def test_eligible_tiles_rejects_protected_manifest_split() -> None:
manifest = {"samples": [{"sample_slug": "x", "region": "flanders", "split": "test"}]}
summary = {"tiles": [{"sample_slug": "x", "split": "train", "image_path": "x.png"}]}
with pytest.raises(ValueError, match="protected"):
miner.eligible_tiles(summary, manifest, "flanders")
def test_binary_metrics() -> None:
result = trainer.binary_metrics([0.9, 0.8, 0.2, 0.1], [1, 0, 1, 0])
assert result == {"tp": 1, "fp": 1, "fn": 1, "precision": 0.5, "recall": 0.5, "f1": 0.5}