dinov2-retrieval icon indicating copy to clipboard operation
dinov2-retrieval copied to clipboard

size mismatch for pos_embed

Open ccmCCMfk opened this issue 1 year ago • 1 comments

Hello, I have a question about DINOv2. Could you please help me?I instantiated a vit_small ViT model and tried to load the pretrained weights using the load_pretrained_weights function from utils. Here's the code I wrote: self.vit_model = vits.dict'vit_small' load_pretrained_weights(self.vit_model, 'https://dl.fbaipublicfiles.com/dinov2/dinov2_vits14/dinov2_vits14_pretrain.pth', None) However, I encountered the following error: Traceback (most recent call last): File "/data/PycharmProjects/train.py", line 124, in model = model(aff_classes=args.num_classes) File "/data/PycharmProjects/models/locate.py", line 89, in init load_pretrained_weights(self.vit_model, pretrained_url, None) File "/data/PycharmProjects/models/dinov2/dinov2/utils/utils.py", line 32, in load_pretrained_weights msg = model.load_state_dict(state_dict, strict=False) File "/home/ustc/anaconda3/envs/locate/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1605, in load_state_dict self.class.name, "\n\t".join(error_msgs))) RuntimeError: Error(s) in loading state_dict for DinoVisionTransformer: size mismatch for pos_embed: copying a param with shape torch.Size([1, 1370, 384]) from checkpoint, the shape in current model is torch.Size([1, 257, 384]).

Could you please help me understand what might be causing this issue? Thank you for your assistance.

ccmCCMfk avatar Jan 10 '24 13:01 ccmCCMfk

Hello, I have a question about the code. Could you please help me? When I use the retrieval code on my query image data and database, it put an error self.save_result( File "d:\Desktop\CodeFiles\Retrieval\dinov2-retrieval\tests..\src\dinov2_retrieval\image_retriever.py", line 212, in save_result img_path = database_img_paths[img_idx] IndexError: list index out of range Also, I found that the number of database_image_paths is twice the number of input database images.

Could you please help me understand what might be causing these issues? Thank you for your assistance.

YongDeng715 avatar Feb 18 '24 07:02 YongDeng715