Update app.py
Browse files
app.py
CHANGED
|
@@ -127,11 +127,17 @@ def vit_attention_rollout(outputs):
|
|
| 127 |
# Overlay Helper
|
| 128 |
# ---------------------------
|
| 129 |
def overlay_attention(pil_img, attention_map):
|
|
|
|
| 130 |
heatmap = (attention_map * 255).astype(np.uint8)
|
| 131 |
heatmap = cv2.applyColorMap(heatmap, cv2.COLORMAP_JET)
|
| 132 |
heatmap = cv2.cvtColor(heatmap, cv2.COLOR_BGR2RGB)
|
| 133 |
-
|
| 134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
return blended
|
| 136 |
|
| 137 |
|
|
|
|
| 127 |
# Overlay Helper
|
| 128 |
# ---------------------------
|
| 129 |
def overlay_attention(pil_img, attention_map):
|
| 130 |
+
# Convert attention map to heatmap
|
| 131 |
heatmap = (attention_map * 255).astype(np.uint8)
|
| 132 |
heatmap = cv2.applyColorMap(heatmap, cv2.COLORMAP_JET)
|
| 133 |
heatmap = cv2.cvtColor(heatmap, cv2.COLOR_BGR2RGB)
|
| 134 |
+
|
| 135 |
+
# Resize heatmap to match image size
|
| 136 |
+
heatmap = cv2.resize(heatmap, pil_img.size)
|
| 137 |
+
|
| 138 |
+
# Convert to PIL and blend
|
| 139 |
+
heatmap_pil = Image.fromarray(heatmap)
|
| 140 |
+
blended = Image.blend(pil_img.convert("RGB"), heatmap_pil, alpha=0.4)
|
| 141 |
return blended
|
| 142 |
|
| 143 |
|