dinov2 icon indicating copy to clipboard operation
dinov2 copied to clipboard

Loading local model

Open AriesChen-UPC opened this issue 1 year ago • 6 comments

How to load a model locally, like in the following example

dinov2_vitb14 = torch.hub.load('facebookresearch/dinov2', 'dinov2_vitb14')

AriesChen-UPC avatar Sep 16 '23 01:09 AriesChen-UPC

same here, I want to load dino base like https://github.com/facebookresearch/dinov2/issues/91#issuecomment-1544368423 but I get error of size mismatch.

AmitIsraeli avatar Sep 19 '23 08:09 AmitIsraeli

You can load the model locally using the following methods, but I have noticed that there are some differences between this approach and loading the model from the network. I haven't yet identified the reason for these differences

from dinov2.models.vision_transformer import vit_base

dinov2_vitb14 = vit_base(patch_size=14, img_size=518) 
state_dict_vitb14 = torch.load("dinov2_vitb14_pretrain.pth")
dinov2_vitb14.load_state_dict(state_dict_vitb14, strict=False)

AriesChen-UPC avatar Sep 21 '23 01:09 AriesChen-UPC

Yes I get the same results, it's run but looks like don't load properly, if someone could help it will be great (:

AmitIsraeli avatar Sep 26 '23 07:09 AmitIsraeli

@AriesChen-UPC What differences do you observe?

patricklabatut avatar Sep 30 '23 19:09 patricklabatut

looks like don't load properly,

@AmitIsraeli Could you elaborate?

patricklabatut avatar Sep 30 '23 19:09 patricklabatut

您观察到哪些差异?

I use torch.hub.load model and vit_large( patch_size=14, img_size=518, init_values=1.0, block_chunks=0 ) model to inference the same input tensor. then use torch.euqal() api to euqal output tensors, it show 'False'. I haven't yet identified the reason for these differences

JackWhite-rwx avatar Dec 26 '23 15:12 JackWhite-rwx