Skip to content

Commit 1bb5a41

Browse files
committed
Plot Visual Comparison
1 parent 1b9a873 commit 1bb5a41

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
@@ -162,6 +162,34 @@
162162
"\n",
163163
" return results"
164164
]
165+
},
166+
{
167+
"cell_type": "code",
168+
"execution_count": 7,
169+
"id": "01752cc6",
170+
"metadata": {},
171+
"outputs": [],
172+
"source": [
173+
"# ------------------------------------------------------------\n",
174+
"# 4. Plot Visual Comparison\n",
175+
"# ------------------------------------------------------------\n",
176+
"def plot_gradcam_comparison(image_path: Path, results):\n",
177+
" \"\"\"Plot baseline vs fine-tuned Grad-CAM overlays side by side.\"\"\"\n",
178+
" fig, axes = plt.subplots(1, len(results) + 1, figsize=(12, 4))\n",
179+
"\n",
180+
" original = np.array(Image.open(image_path))\n",
181+
" axes[0].imshow(original)\n",
182+
" axes[0].set_title('Original Image')\n",
183+
" axes[0].axis('off')\n",
184+
"\n",
185+
" for i, (label, heatmap, overlay) in enumerate(results, start=1):\n",
186+
" axes[i].imshow(cv2.cvtColor(overlay, cv2.COLOR_BGR2RGB))\n",
187+
" axes[i].set_title(label.replace('_', ' ').title())\n",
188+
" axes[i].axis('off')\n",
189+
"\n",
190+
" plt.tight_layout()\n",
191+
" plt.show()"
192+
]
165193
}
166194
],
167195
"metadata": {

0 commit comments

Comments
 (0)