SaniaE commited on
Commit
0129fbe
·
verified ·
1 Parent(s): 7b80a15

updated saliency logic

Browse files
Files changed (1) hide show
  1. app.py +2 -6
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
- # Average across heads and text tokens to get a single 1D map of image importance
231
- # We exclude the first and last text tokens ([CLS], [SEP])
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"