Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Size mismatch for ssd_heads when using the pretrained model #62

Open
QiqLiang opened this issue Dec 12, 2022 · 6 comments
Open

Size mismatch for ssd_heads when using the pretrained model #62

QiqLiang opened this issue Dec 12, 2022 · 6 comments

Comments

@QiqLiang
Copy link

Hi, I came up with an issue when training on my dataset which has 102 classes. It seems like a size mismatch problem when using the pretrained model.

Here is my code:
PYTHONWARNINGS="ignore" cvnets-train
--common.config-file config/detection/ssd_coco/coco-ssd-mobilevitv2-1.75.yaml
--common.results-loc exp/exp1
--common.override-kwargs model.detection.pretrained="ckpt/coco-ssd-mobilevitv2-1.75.pt" model.detection.n-classes=103

and this is the error:
2022-12-12 21:09:24 - ERROR - Unable to load pretrained weights from ckpt/coco-ssd-mobilevitv2-1.75.pt. Error: Error(s) in loading state_dict for SingleShotMaskDetector:
size mismatch for ssd_heads.0.loc_cls_layer.pw_conv.block.conv.weight: copying a param with shape torch.Size([510, 512, 1, 1]) from checkpoint, the shape in current model is torch.Size([642, 512, 1, 1]).
size mismatch for ssd_heads.0.loc_cls_layer.pw_conv.block.conv.bias: copying a param with shape torch.Size([510]) from checkpoint, the shape in current model is torch.Size([642]).
size mismatch for ssd_heads.1.loc_cls_layer.pw_conv.block.conv.weight: copying a param with shape torch.Size([510, 256, 1, 1]) from checkpoint, the shape in current model is torch.Size([642, 256, 1, 1]).
size mismatch for ssd_heads.1.loc_cls_layer.pw_conv.block.conv.bias: copying a param with shape torch.Size([510]) from checkpoint, the shape in current model is torch.Size([642]).
size mismatch for ssd_heads.2.loc_cls_layer.pw_conv.block.conv.weight: copying a param with shape torch.Size([510, 256, 1, 1]) from checkpoint, the shape in current model is torch.Size([642, 256, 1, 1]).
size mismatch for ssd_heads.2.loc_cls_layer.pw_conv.block.conv.bias: copying a param with shape torch.Size([510]) from checkpoint, the shape in current model is torch.Size([642]).
size mismatch for ssd_heads.3.loc_cls_layer.pw_conv.block.conv.weight: copying a param with shape torch.Size([510, 128, 1, 1]) from checkpoint, the shape in current model is torch.Size([642, 128, 1, 1]).
size mismatch for ssd_heads.3.loc_cls_layer.pw_conv.block.conv.bias: copying a param with shape torch.Size([510]) from checkpoint, the shape in current model is torch.Size([642]).
size mismatch for ssd_heads.4.loc_cls_layer.pw_conv.block.conv.weight: copying a param with shape torch.Size([510, 128, 1, 1]) from checkpoint, the shape in current model is torch.Size([642, 128, 1, 1]).
size mismatch for ssd_heads.4.loc_cls_layer.pw_conv.block.conv.bias: copying a param with shape torch.Size([510]) from checkpoint, the shape in current model is torch.Size([642]).
size mismatch for ssd_heads.5.loc_cls_layer.block.conv.weight: copying a param with shape torch.Size([340, 64, 1, 1]) from checkpoint, the shape in current model is torch.Size([428, 64, 1, 1]).
size mismatch for ssd_heads.5.loc_cls_layer.block.conv.bias: copying a param with shape torch.Size([340]) from checkpoint, the shape in current model is torch.Size([428]).

How to use the pretrained model when i try to train on my own dataset with different num_classes with mscoco?

@sacmehta
Copy link
Collaborator

For overriding kwargs, we need keys to have _ instead of -

Change model.detection.n-classes=103 to model.detection.n_classes=103

@sacmehta
Copy link
Collaborator

Also, we recommend to use yaml files over command line arguments.

@QiqLiang
Copy link
Author

For overriding kwargs, we need keys to have _ instead of -

Change model.detection.n-classes=103 to model.detection.n_classes=103

I used this code:
PYTHONWARNINGS="ignore" cvnets-train
--common.config-file config/detection/ssd_coco/coco-ssd-mobilevitv2-1.75.yaml
--common.results-loc exp/exp1
--common.override-kwargs model.detection.pretrained="ckpt/coco-ssd-mobilevitv2-1.75.pt" model.detection.n_classes=103

but still got the same error.

@sacmehta
Copy link
Collaborator

Are these weights pretrained on MS-COCO?

@QiqLiang
Copy link
Author

Are these weights pretrained on MS-COCO?

Yes. I downloaded from model zoo(MS-COCO). The link is: https://docs-assets.developer.apple.com/ml-research/models/cvnets-v2/detection/mobilevitv2/coco-ssd-mobilevitv2-1.75.pt

@sacmehta
Copy link
Collaborator

In our recent release, we added support for excluding keys in checkpoint. Could you please try it?

You need to pass the name of keys as list using --model.resume-exclude-scopes argument for which pre-trained weights shape is different?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants