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

How to integrate ViT in Networks? #46

Open
Snimm opened this issue May 17, 2024 · 1 comment
Open

How to integrate ViT in Networks? #46

Snimm opened this issue May 17, 2024 · 1 comment

Comments

@Snimm
Copy link

Snimm commented May 17, 2024

I want to use Huggingface's ViTForImageClassification. How do I integrate it in FACIL? I want to load the pretrained model
'google/vit-base-patch16-224'. I have read the instructions to add networks in readme of networks. However I am still not sure how to implement it. How do I set "self.head_var = 'fc'" when head is changed by "model.classifier = nn.Linear(768, num_classes)"? How exactly will a class even be created in this case?

@mmasana
Copy link
Owner

mmasana commented May 17, 2024

Not sure I understand which is the exact issue. If the pretrained model has a head called classifier, you just need to define self.head_var = 'classifier' and it should be removed. Not self.head_var = 'fc' because there is no layer called fc.
If you want, you can also remove the head directly from the pretrained model and use the argument --keep-existing-head (even though you removed it) so that nothing else is removed.

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