Balance YOLO label QA coverage
GeoIntel CI / docs-smoke (push) Has been cancelled
GeoIntel CI / contract-smoke (push) Has been cancelled

This commit is contained in:
Codex
2026-07-12 23:53:18 +02:00
parent 0f49c980ba
commit 3266c6578d
6 changed files with 117 additions and 9 deletions
@@ -1,5 +1,6 @@
from __future__ import annotations
import importlib.util
import json
import subprocess
import sys
@@ -11,6 +12,48 @@ from PIL import Image, ImageDraw
ROOT = Path(__file__).resolve().parents[2]
def load_renderer():
script_path = ROOT / "scripts" / "render_operator_yolo_label_qa_contact_sheets.py"
spec = importlib.util.spec_from_file_location("operator_label_qa_renderer", script_path)
assert spec is not None
assert spec.loader is not None
module = importlib.util.module_from_spec(spec)
sys.modules[spec.name] = module
spec.loader.exec_module(module)
return module
def test_contact_sheet_selection_balances_source_samples_before_dense_repeats() -> None:
module = load_renderer()
tiles = [
{
"sample_slug": "dense",
"split": "train",
"tile_index": index,
"label_count": 100 - index,
"is_negative": False,
"kept": True,
}
for index in range(5)
]
tiles.extend(
[
{"sample_slug": "medium", "split": "train", "tile_index": 0, "label_count": 20, "is_negative": False, "kept": True},
{"sample_slug": "small", "split": "val", "tile_index": 0, "label_count": 5, "is_negative": False, "kept": True},
{"sample_slug": "background", "split": "train", "tile_index": 0, "label_count": 0, "is_negative": True, "kept": True},
]
)
selected = module.select_tiles(tiles, max_tiles=4)
assert {tile["sample_slug"] for tile in selected} == {
"dense",
"medium",
"small",
"background",
}
def write_patterned_image(path: Path, color: tuple[int, int, int]) -> None:
image = Image.new("RGB", (64, 64), color=color)
draw = ImageDraw.Draw(image)