Add Krea2 atlas gap plans

This commit is contained in:
2026-06-29 04:12:54 +02:00
parent 06525c42a3
commit 5a5d5dd6fe
3 changed files with 62 additions and 1 deletions
+51
View File
@@ -95,6 +95,12 @@ def _is_background_or_control_folder(folder_name: str) -> bool:
)
def _sample_pngs(folder: Path, limit: int) -> list[str]:
if not folder.is_dir() or limit <= 0:
return []
return [str(path) for path in sorted(folder.glob("*.png"), key=lambda path: path.name.lower())[:limit]]
def atlas_folder_rows(atlas_root: str | Path | None = None) -> list[dict[str, Any]]:
root = Path(atlas_root) if atlas_root is not None else _catalog_atlas_root()
if not root.is_dir():
@@ -137,6 +143,34 @@ def atlas_coverage_summary(atlas_root: str | Path | None = None) -> dict[str, An
}
def _suggested_variant_key(folder_name: str) -> str:
normalized = "".join(char if char.isalnum() else "_" for char in folder_name.lower()).strip("_")
while "__" in normalized:
normalized = normalized.replace("__", "_")
return f"pov_{normalized}_candidate" if normalized else "pov_unmapped_candidate"
def atlas_gap_plans(atlas_root: str | Path | None = None, sample_limit: int = 3) -> list[dict[str, Any]]:
root = Path(atlas_root) if atlas_root is not None else _catalog_atlas_root()
plans: list[dict[str, Any]] = []
for row in atlas_folder_rows(atlas_root=root):
if row.get("mapped"):
continue
folder_name = str(row.get("folder") or "")
folder_path = root / folder_name
control_folder = Path(str(row.get("control_folder") or ""))
plans.append(
{
"folder": folder_name,
"suggested_variant_key": _suggested_variant_key(folder_name),
"image_count": int(row.get("image_count") or 0),
"sample_images": _sample_pngs(folder_path, sample_limit),
"control_images": _sample_pngs(control_folder, sample_limit),
}
)
return plans
def next_test_plans() -> list[dict[str, Any]]:
rows_by_key = {str(row.get("key")): row for row in coverage_rows()}
plans: list[dict[str, Any]] = []
@@ -218,4 +252,21 @@ def markdown_report(atlas_root: str | Path | None = None) -> str:
)
if unmapped:
lines.extend(["", "Unmapped atlas folders:", *[f"- {folder}" for folder in unmapped]])
gap_plans = atlas_gap_plans(atlas_root=atlas_root)
if gap_plans:
lines.extend(["", "## Atlas Gap Plans"])
for plan in gap_plans:
sample_images = plan["sample_images"]
control_images = plan["control_images"]
lines.extend(
[
"",
f"### {plan['folder']}",
"",
f"- Suggested key: {plan['suggested_variant_key']}",
f"- Pose images: {plan['image_count']}",
f"- Samples: {', '.join(sample_images) or 'none'}",
f"- Controls: {', '.join(control_images) or 'none'}",
]
)
return "\n".join(lines)