Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code for Google's ViT and complete example #2

Closed
sayakpaul opened this issue Mar 25, 2021 · 2 comments
Closed

Code for Google's ViT and complete example #2

sayakpaul opened this issue Mar 25, 2021 · 2 comments

Comments

@sayakpaul
Copy link

sayakpaul commented Mar 25, 2021

Hi @jacobgil!

Thank you for this amazing piece of work. I was wondering if you plan to open-source the code to try out your experiments on Google's ViT (An Image is Worth ...) as well. If it's already there inside the repo, could you point me to it?

Update: I was able to use timm and make use of the ViT model it comes with:

timm_vit_model = timm.create_model('vit_large_patch16_384', pretrained=True)
timm_vit_model.eval()
roller = VITAttentionGradRollout(timm_vit_model, discard_ratio=0.9)
mask = roller(x.unsqueeze(0), label_idx)

However, I am still a bit unsure as to how to actually visualize the mask. Could you help?

@sayakpaul sayakpaul changed the title Code for Google's ViT Code for Google's ViT and complete example Mar 26, 2021
@jacobgil
Copy link
Owner

jacobgil commented Apr 2, 2021

Hi,
In vit_explain.py there is an example.
Once you have the mask you can do
mask = show_mask_on_image(img, mask).

Did it work out?

@sayakpaul
Copy link
Author

It does thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants