Skip to content

Commit 1b9a873

Browse files
committed
Implement Visual Comparison Utility
1 parent f69a0c1 commit 1b9a873

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

notebooks/04_gradcam_refinement.ipynb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,34 @@
134134
" heatmap = heatmap.astype(np.float32) / 255.0\n",
135135
" return heatmap"
136136
]
137+
},
138+
{
139+
"cell_type": "code",
140+
"execution_count": 6,
141+
"id": "6bda37ff",
142+
"metadata": {},
143+
"outputs": [],
144+
"source": [
145+
"# ------------------------------------------------------------\n",
146+
"# 3. Visual Comparison Utility\n",
147+
"# ------------------------------------------------------------\n",
148+
"def compare_models(image_path: Path, model_paths: list):\n",
149+
" \"\"\"Compare Grad-CAM results from multiple model checkpoints.\"\"\"\n",
150+
" results = []\n",
151+
" for path in model_paths:\n",
152+
" heatmap = generate_cam(image_path, path)\n",
153+
" img = cv2.imread(str(image_path))\n",
154+
" overlay = GradCAM.overlay_heatmap(heatmap, img)\n",
155+
"\n",
156+
" out_name = f\"{image_path.stem}_{path.stem}_overlay.png\"\n",
157+
" out_path = output_dir / out_name\n",
158+
" cv2.imwrite(str(out_path), overlay)\n",
159+
"\n",
160+
" results.append((path.stem, heatmap, overlay))\n",
161+
" print(f\"Saved overlay: {out_path.name}\")\n",
162+
"\n",
163+
" return results"
164+
]
137165
}
138166
],
139167
"metadata": {

0 commit comments

Comments
 (0)