IDEA-Research / DINO

[ICLR 2023] Official implementation of the paper "DINO: DETR with Improved DeNoising Anchor Boxes for End-to-End Object Detection"
Apache License 2.0
2.15k stars 232 forks source link

size match #148

Open Richeerard opened 1 year ago

Richeerard commented 1 year ago

作者您好!我使用了4scale进行训练,使用了预训练模型,结果出现了以下错误:size mismatch for transformer.decoder.class_embed.0.weight: copying a param with shape torch.Size([91, 256]) from checkpoint, the shape in current model is torch.Size([4, 256]). 请问我应该如何修改代码

SlongLiu commented 1 year ago

您是在个人数据上训练吗,这个错误是由于类别数被设置成了4和原始预训练模型不同导致的。

Richeerard commented 1 year ago

您是在个人数据上训练吗,这个错误是由于类别数被设置成了4和原始预训练模型不同导致的。

是的,我设置的类别数为4,但是我仍然想要使用预训练模型进行训练。我看了异常位置的代码_load_output = model_without_ddp.load_state_dict(_tmp_st, strict=False),strict设置为False应该能跳过size不匹配问题吧,但是实际上它未能解决该问题,希望得到您的帮助,谢谢!

Richeerard commented 1 year ago

我十分想知道如何在个人数据集上使用类别为91的预训练模型进行预训练,谢谢您了!

我十分想知道如何在个人数据集上使用类别为91的预训练模型进行预训练,谢谢您了!

SlongLiu commented 1 year ago

请参考这里: https://github.com/IDEA-Research/DINO#run Training/Fine-tuning a DINO on your custom dataset

To leverage our pre-trained models for model fine-tuning, we suggest adding two more commands in bash:

--pretrain_model_path /path/to/a/pretrianed/model. specify a pre-trained model. --finetune_ignore label_enc.weight class_embed ignore some inconsistent parameters.

SlongLiu commented 1 year ago

具体来说,添加finetune_ignore忽略掉不一致的参数即可。

--finetune_ignore label_enc.weight class_embed
anweshb commented 1 year ago

Hi @SlongLiu, I tried following the guide to finetune model on a custom dataset with specifically 1 class, changed the number of classes in the corresponding config file and ensured dn_labelbook_size >= num_class + 1 and ran the command !bash "scripts/DINO_train.sh" "../Data" --pretrain_model_path "checkpoint0033_4scale.pth" --finetune_ignore label_enc.weight class_embed. I get the error RuntimeError: Error(s) in loading state_dict for DINO: size mismatch for transformer.decoder.class_embed.0.weight: copying a param with shape torch.Size([91, 256]) from checkpoint, the shape in current model is torch.Size([1, 256]) and similar for all other layers.

Do I need to make some other changed before I try to finetune?

Thanks

Raneem-MT commented 4 months ago

Hi @anweshb we are having a similar problem, did you manage to solve this?