Prove unique label coverage during retiling
This commit is contained in:
@@ -62,19 +62,21 @@ def main() -> int:
|
||||
|
||||
summary = json.loads(args.summary.read_text(encoding="utf-8"))
|
||||
output_tiles: list[dict[str, Any]] = []
|
||||
kept_labels = dropped_labels = 0
|
||||
kept_labels = dropped_labels = source_labels = uniquely_kept_labels = 0
|
||||
for source_tile in summary["tiles"]:
|
||||
with Image.open(source_tile["image_path"]) as opened:
|
||||
source = opened.convert("RGB")
|
||||
width, height = source.size
|
||||
boxes = read_boxes(Path(source_tile["label_path"]), width, height)
|
||||
source_labels += len(boxes)
|
||||
covered_source_labels: set[int] = set()
|
||||
for top in tile_starts(height, args.tile_size, args.overlap):
|
||||
for left in tile_starts(width, args.tile_size, args.overlap):
|
||||
right, bottom = min(width, left+args.tile_size), min(height, top+args.tile_size)
|
||||
if right-left < args.tile_size or bottom-top < args.tile_size:
|
||||
continue
|
||||
local = []
|
||||
for x1, y1, x2, y2 in boxes:
|
||||
for box_index, (x1, y1, x2, y2) in enumerate(boxes):
|
||||
cx, cy = (x1+x2)/2, (y1+y2)/2
|
||||
if not (left <= cx < right and top <= cy < bottom):
|
||||
continue
|
||||
@@ -85,6 +87,7 @@ def main() -> int:
|
||||
continue
|
||||
local.append((ix1-left, iy1-top, ix2-left, iy2-top))
|
||||
kept_labels += 1
|
||||
covered_source_labels.add(box_index)
|
||||
split = source_tile["split"]
|
||||
stem = f"{Path(source_tile['image_path']).stem}_z{top}_{left}"
|
||||
image_path = args.output_dir / "images" / split / f"{stem}.png"
|
||||
@@ -102,6 +105,7 @@ def main() -> int:
|
||||
"label_count":len(local), "source_tile":source_tile["image_path"],
|
||||
"retile_window":[left,top,right,bottom]})
|
||||
output_tiles.append(tile)
|
||||
uniquely_kept_labels += len(covered_source_labels)
|
||||
|
||||
args.output_dir.mkdir(parents=True, exist_ok=True)
|
||||
output_summary = dict(summary)
|
||||
@@ -118,6 +122,8 @@ def main() -> int:
|
||||
"overlap":args.overlap,
|
||||
"min_visible_ratio":args.min_visible_ratio, "output_tile_count":len(output_tiles),
|
||||
"kept_label_count":kept_labels, "dropped_label_count":dropped_labels,
|
||||
"source_label_count":source_labels, "unique_kept_source_label_count":uniquely_kept_labels,
|
||||
"uncovered_source_label_count":source_labels-uniquely_kept_labels,
|
||||
"summary":str(summary_path), "summary_sha256":sha256(summary_path)}
|
||||
(args.output_dir/"retile-evidence.json").write_text(json.dumps(evidence,indent=2),encoding="utf-8")
|
||||
print(json.dumps(evidence,indent=2))
|
||||
|
||||
Reference in New Issue
Block a user