correct overlapping checkpoint evaluation
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
from pathlib import Path
|
||||
|
||||
from PIL import Image
|
||||
|
||||
from scripts.derive_yolo_nonoverlap_evaluation_view import (
|
||||
image_has_low_visual_variance,
|
||||
select_nonoverlap_tiles,
|
||||
)
|
||||
|
||||
|
||||
def tile(name: str, index: int, split: str = "val") -> dict[str, object]:
|
||||
return {
|
||||
"image_path": f"/data/sample_{index:04d}_{name}.png",
|
||||
"tile_index": index,
|
||||
"sample_slug": "sample",
|
||||
"split": split,
|
||||
"kept": True,
|
||||
}
|
||||
|
||||
|
||||
def test_select_nonoverlap_tiles_keeps_complete_512_grid() -> None:
|
||||
tiles = [
|
||||
tile("r0_c0", 0),
|
||||
tile("r0_c256", 1),
|
||||
tile("r0_c512", 2),
|
||||
tile("r256_c0", 3),
|
||||
tile("r256_c256", 4),
|
||||
tile("r256_c512", 5),
|
||||
tile("r512_c0", 6),
|
||||
tile("r512_c256", 7),
|
||||
tile("r512_c512", 8),
|
||||
tile("r0_c0", 9, split="train"),
|
||||
]
|
||||
|
||||
selected = select_nonoverlap_tiles(tiles, 512)
|
||||
|
||||
assert [item["tile_index"] for item in selected] == [0, 2, 6, 8]
|
||||
|
||||
|
||||
def test_image_has_low_visual_variance_rejects_blank_no_data(tmp_path: Path) -> None:
|
||||
blank = tmp_path / "blank.png"
|
||||
real = tmp_path / "real.png"
|
||||
Image.new("L", (8, 8), color=255).save(blank)
|
||||
image = Image.new("L", (8, 8), color=100)
|
||||
image.putpixel((0, 0), 120)
|
||||
image.save(real)
|
||||
|
||||
assert image_has_low_visual_variance(blank, 3) is True
|
||||
assert image_has_low_visual_variance(real, 3) is False
|
||||
@@ -17,7 +17,8 @@ def test_dataset_overlap_evidence_marks_repeated_validation_rows(
|
||||
|
||||
assert evidence["status"] == "overlapping"
|
||||
assert evidence["overlap_pixels"] == 256
|
||||
assert evidence["validation_rows_independent"] is False
|
||||
assert evidence["validation_tiles_non_overlapping"] is False
|
||||
assert evidence["statistical_independence_established"] is False
|
||||
|
||||
|
||||
def test_dataset_overlap_evidence_is_explicit_when_summary_missing(
|
||||
@@ -26,4 +27,21 @@ def test_dataset_overlap_evidence_is_explicit_when_summary_missing(
|
||||
evidence = dataset_overlap_evidence(tmp_path / "dataset.yaml")
|
||||
|
||||
assert evidence["status"] == "unavailable"
|
||||
assert evidence["validation_rows_independent"] is None
|
||||
assert evidence["validation_tiles_non_overlapping"] is None
|
||||
assert evidence["statistical_independence_established"] is False
|
||||
|
||||
|
||||
def test_nonoverlap_does_not_overclaim_statistical_independence(
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
dataset_yaml = tmp_path / "dataset.yaml"
|
||||
dataset_yaml.write_text("path: .\nval: images/val\n", encoding="utf-8")
|
||||
(tmp_path / "yolo_tile_dataset_summary.json").write_text(
|
||||
json.dumps({"tile_size": 512, "stride": 512}), encoding="utf-8"
|
||||
)
|
||||
|
||||
evidence = dataset_overlap_evidence(dataset_yaml)
|
||||
|
||||
assert evidence["validation_tiles_non_overlapping"] is True
|
||||
assert evidence["statistical_independence_established"] is False
|
||||
assert "not established" in evidence["interpretation"]
|
||||
|
||||
Reference in New Issue
Block a user