updated saliency logic
Browse files
app.py
CHANGED
|
@@ -227,12 +227,8 @@ async def get_saliency_heatmap(file: UploadFile = File(...), query_text: str = Q
|
|
| 227 |
# Shape: (layers, batch, heads, text_tokens, image_patches)
|
| 228 |
cross_attentions = outputs.cross_attentions[-1]
|
| 229 |
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
mask_1d = cross_attentions[0, :, 1:-1, :].mean(dim=(0, 1))
|
| 233 |
-
|
| 234 |
-
# Reshape to the grid (usually 16x16 for BLIP-large)
|
| 235 |
-
grid_size = int(np.sqrt(mask_1d.shape[-1]))
|
| 236 |
mask = mask_1d.view(grid_size, grid_size).cpu().numpy()
|
| 237 |
|
| 238 |
# Normalize and create the "Glow"
|
|
|
|
| 227 |
# Shape: (layers, batch, heads, text_tokens, image_patches)
|
| 228 |
cross_attentions = outputs.cross_attentions[-1]
|
| 229 |
|
| 230 |
+
mask_1d = cross_attentions[0, :, 1:-1, 1:].mean(dim=(0, 1)) # Note the 1: at the end
|
| 231 |
+
grid_size = int(np.sqrt(mask_1d.shape[-1])) # This will now be 24
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
mask = mask_1d.view(grid_size, grid_size).cpu().numpy()
|
| 233 |
|
| 234 |
# Normalize and create the "Glow"
|