apple / ml-cvnets

CVNets: A library for training computer vision networks
https://apple.github.io/ml-cvnets
Other
1.76k stars 225 forks source link

Size mismatch error when loading a pretrained model #87

Open jackywangtj66 opened 1 year ago

jackywangtj66 commented 1 year ago

I tried to load a pretrained mobilevit model downloaded from model zoo for fine-tuning on a classification task with 6 labels. I do have excluded the last layer: image

But I still encountered the following error: 2023-08-16 15:05:22 - ERROR - Unable to load pretrained weights from ./TrainedModels/Models/MobileVitv1/mobilevit_xxs.pt. Error: Error(s) in loading state_dict for MobileViT: size mismatch for classifier.fc.weight: copying a param with shape torch.Size([1000, 320]) from checkpoint, the shape in current model is torch.Size([6, 320]). size mismatch for classifier.fc.bias: copying a param with shape torch.Size([1000]) from checkpoint, the shape in current model is torch.Size([6]).. Exiting!!!

Do you have any idea?

jackywangtj66 commented 1 year ago

Found the problem myself. Resume_exclude_scopes should be under 'model' instead of 'model.classification'. Suggestion: would you consider putting the scopes arguments under 'pretrained'? Since they will be useless without a pretrained model.