mirror of
https://github.com/openai/CLIP.git
synced 2026-11-05 01:37:26 +00:00
[GH-ISSUE #82] Attention map to extract objects #74
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
openai/CLIP#74
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @rodrigoheck on GitHub (Apr 7, 2021).
Original GitHub issue: https://github.com/openai/CLIP/issues/82
I have no idea if something like this is possible, but if I have, for example, an image of a supermarket shelve and the text "juice", could I in theory use the attention map to extract all the regions in which the model found something similar to a juice?
@jongwook commented on GitHub (Apr 8, 2021):
It's not as straightforward as CLIP doesn't have cross-modal attentions and the only cross-modal interaction is the final dot product, but you could start with cropping the images into square-shaped patches and finding the cosine similarity between the image features of those patches and the query text features.
@rodrigoheck commented on GitHub (Apr 8, 2021):
Thanks @jongwook, I will try this approach.
@ModMorph commented on GitHub (Apr 8, 2021):
FYI: @rodrigoheck you might be interested in the following projects: https://ganpaint.io/miniclip/ and https://github.com/hila-chefer/Transformer-MM-Explainability - these have saliency and/or gradcam maps for RN50 and ViTB CLIP respectively. (Although I think the Transformer method is new so not sure how confident to be in it.)
@g-luo commented on GitHub (Apr 22, 2021):
@ModMorph Do you have insight on which layers are best to use as the saliency layer for Grad CAM (for the visual transformer ViT models)? For the RN50 the miniclip demo uses the relu from the last visual layer, and I'm wondering what's the best for the visual transformer.
@ModMorph commented on GitHub (Apr 22, 2021):
Hi @g-luo, good timing. I may be circling back to this...but I haven't had time to
look at how Transformer-MM-Explainability's technique works yet, just that in trying
their demos, it seemed to look reasonably well.
One thing I noticed you might be interested in, is that there's seems to be some
more attention head related information you can derive by taking the full
x[:,:,:] instead of the x[:,0,:] in the last lines of the VisualTransformer forward method. I thought maybe it was de facto a vector describing
each of the 49 32x32x3 pixel patches w.r.t. to the embedding vector..but
I'm new to transformers. When I subtracted the 49 vectors from the embedding
vector currently being used, I got what seemed like a coherent heatmap description
of some basic scenes I tried. HTH. (Not exactly same as the level of detail you want,
I'm still experimenting whether I can make any use out of it.)
@jihwanp commented on GitHub (Apr 11, 2022):
Did that similarity map just measure the similarity between local feature and text(apple)? I tried similar things, but the local similarity of the text-related parts was rather low.
@gordinmitya commented on GitHub (Feb 8, 2023):
now there's such a thing https://huggingface.co/blog/clipseg-zero-shot
@chinmay5 commented on GitHub (Mar 30, 2023):
Here is a very simple code snippet in case someone finds it useful.