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

size mismatch for pos_embed #2

Open
ccmCCMfk opened this issue Jan 10, 2024 · 1 comment
Open

size mismatch for pos_embed #2

ccmCCMfk opened this issue Jan 10, 2024 · 1 comment

Comments

@ccmCCMfk
Copy link

ccmCCMfk commented Jan 10, 2024

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.

@YongDeng715
Copy link

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.

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