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

Loading Pretrained Models(dinov2_vits14_pretrain.pth, inov2_vitb14/dinov2_vitb14_pretrain.pth) #410

Closed
kongminseok opened this issue Apr 27, 2024 · 2 comments

Comments

@kongminseok
Copy link

kongminseok commented Apr 27, 2024

Hi, How can I initiate the pre-trained Dinov2 model by using load_state_dict? I've seen issue #91, but there is no information about vit_small and vit_large arch to load the state of pre-trained models.

from dinov2.models.vision_transformer import vit_small, vit_base, vit_large 

model_small = vit_small(
   ???
)

model_base = vit_base(
   ???
)

model_large = vit_large(
    patch_size=14,
    img_size=526,
    init_values=1.0,
    block_chunks=0
 )

model_small.load_state_dict(torch.load('dinov2_vits14_pretrain.pth'), strict=True)
model_base.load_state_dict(torch.load('dinov2_vitb14_pretrain.pth'), strict=True)
model_large.load_state_dict(torch.load('dinov2_vitl14_pretrain.pth'), strict=True)
@wangh09
Copy link

wangh09 commented May 6, 2024

didn't verify but the following should work

model = vit_x(
    patch_size=14,
    img_size=518,
    init_values=1.0,
    block_chunks=0
 )
x = small/base/large

518 should be the correct img_size but 526 also works as 526//14 == 518//14

@qasfb
Copy link
Contributor

qasfb commented May 13, 2024

yes
essentially the best way is to do what is done with torch.hub.load :
https://github.com/facebookresearch/dinov2/blob/main/hubconf.py

@qasfb qasfb closed this as completed May 13, 2024
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

3 participants