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

Is it possible to use the "Accessing Attention" of the vit-pytorch on the timm models? #270

Open
Shima-shoki opened this issue Jul 3, 2023 · 0 comments

Comments

@Shima-shoki
Copy link

Hi, thanks always for the great work of this project. Recently I dive into the transformer models and they are really fascinating. The attention system looks quite interesting. I've got to know that we can access the attention information by using vit_pytorch.recorder.Recorder, but it can't be applied on the pre-trained models available from timm. Here is an example of my attempt to use the Recorder module with a timm model and corresponding errors.

import torch
import timm
from vit_pytorch.recorder import Recorder

model = timm.create_model('vit_base_patch16_224', pretrained=True, num_classes=2)
v = Recorder(model)

img = torch.randn(1, 3, 224, 224)
preds, attns = v(img)

The error messages are:

AttributeError: 'VisionTransformer' object has no attribute 'transformer'

I understand that since they are different libraries so that it'd be expected to not work smoothly, but I'd hope that it would be quite nice if they can be combined together. Are there any ways to go around this issue?

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

1 participant