Verify YOLO heatmap generation in deep acceptance

This commit is contained in:
2026-06-30 13:52:00 +08:00
parent cf920e97c3
commit 43ed767b4f
4 changed files with 58 additions and 9 deletions

View File

@@ -100,6 +100,29 @@ def _yolo_tiny_train_snippet(root: Path, weight: Path) -> str:
)
def _yolo_heatmap_snippet(root: Path) -> str:
script_path = settings.source_root / "Seg_All_In_One_YoloModel" / "yolo_predict_visualize_nn.py"
return (
"from pathlib import Path; "
"import importlib.util, shutil, sys, types; "
"fake=types.ModuleType('yolo_config'); "
"fake.MODEL_CONFIGS={'YOLO11n-seg': {}}; "
"fake.TEST_IMAGE_DIR=''; fake.PREDICT_BEST_MODEL_DIR=Path('.'); fake.show_config_summary=lambda: None; "
"sys.modules['yolo_config']=fake; "
f"script=Path({str(script_path)!r}); "
"spec=importlib.util.spec_from_file_location('yolo_heatmap_mod', script); "
"mod=importlib.util.module_from_spec(spec); spec.loader.exec_module(mod); "
f"root=Path({str(root)!r}); "
"base=root/'runs'/'tiny'; "
"heatmap_root=base/'HeartMap_Visual'; "
"shutil.rmtree(heatmap_root, ignore_errors=True); "
"mod.visualize_nn_comprehensive(str(base/'weights'/'best.pt'), str(root/'images'/'val'/'sample.jpg'), base, 'best.pt', 'GradCAM', 'model.model.model[9]', 'YOLO11n-seg'); "
"outputs=sorted(heatmap_root.rglob('*.jpg')); "
"assert len(outputs) >= 2; "
"print('heatmaps', len(outputs), [str(item.relative_to(base)) for item in outputs[:4]])"
)
def _mmseg_train_step_snippet(config_path: Path) -> str:
return (
"import torch; "
@@ -329,23 +352,43 @@ def run_deep_acceptance() -> dict[str, Any]:
yolo_weight = settings.source_root / "Seg_All_In_One_YoloModel" / "yolo11n-seg.pt"
mmseg_config = settings.source_root / "Seg_All_In_One_MMSeg" / "configs" / "fcn" / "fcn_r18-d8_4xb2-80k_cityscapes-512x1024.py"
yolo_root = fixture_root / "yolo_tiny"
checks = [
{
"name": "segmodel_tiny_train_step",
"passed": False,
"detail": _run_snippet(SEGMODEL_TRAIN_STEP_SNIPPET, timeout=90),
},
{
"name": "yolo_tiny_segment_train_epoch",
"passed": False,
"detail": _run_snippet(_yolo_tiny_train_snippet(fixture_root / "yolo_tiny", yolo_weight), timeout=180),
},
]
yolo_train = {
"name": "yolo_tiny_segment_train_epoch",
"passed": False,
"detail": _run_snippet(_yolo_tiny_train_snippet(yolo_root, yolo_weight), timeout=180),
}
checks.append(yolo_train)
if yolo_train["detail"].get("passed"):
checks.append(
{
"name": "yolo_tiny_heatmap_generation",
"passed": False,
"detail": _run_snippet(_yolo_heatmap_snippet(yolo_root), timeout=90),
}
)
else:
checks.append(
{
"name": "yolo_tiny_heatmap_generation",
"passed": False,
"detail": {"passed": False, "error": "skipped because yolo_tiny_segment_train_epoch failed"},
}
)
checks.append(
{
"name": "mmseg_tiny_train_step",
"passed": False,
"detail": _run_conda_snippet(settings.mmseg_conda_env, _mmseg_train_step_snippet(mmseg_config), timeout=120),
},
]
}
)
for check in checks:
check["passed"] = bool(check["detail"].get("passed"))