faster-rcnn.pytorch icon indicating copy to clipboard operation
faster-rcnn.pytorch copied to clipboard

size mismatch for RCNN_cls_score.bias: copying a param with shape torch.Size([4]) from checkpoint, the shape in current model is torch.Size([21]).

Open alontrais opened this issue 4 years ago • 9 comments

I trained a model by trainval_net script. when I run the demo script, I get a RuntimeError: load checkpoint /home/trais_user/pipeline/algorithms/faster-rcnn.pytorch/models//vgg16/pascal_voc/faster_rcnn_1_200_47.pth Traceback (most recent call last): File "demo.py", line 195, in fasterRCNN.load_state_dict(checkpoint['model']) File "/home/trais_user/.conda/envs/frcnn/lib/python2.7/site-packages/torch/nn/modules/module.py", line 830, in load_state_dict self.class.name, "\n\t".join(error_msgs))) RuntimeError: Error(s) in loading state_dict for vgg16: size mismatch for RCNN_cls_score.bias: copying a param with shape torch.Size([4]) from checkpoint, the shape in current model is torch.Size([21]). size mismatch for RCNN_cls_score.weight: copying a param with shape torch.Size([4, 4096]) from checkpoint, the shape in current model is torch.Size([21, 4096]). size mismatch for RCNN_bbox_pred.bias: copying a param with shape torch.Size([16]) from checkpoint, the shape in current model is torch.Size([84]). size mismatch for RCNN_bbox_pred.weight: copying a param with shape torch.Size([16, 4096]) from checkpoint, the shape in current model is torch.Size([84, 4096]).

What could cause this error?

alontrais avatar Mar 09 '20 13:03 alontrais

Check the Anchor boxes scales in config.py and mention proper classes in demo.py

([16, 4096]) = (classes*4 bounding boxes) , final feature map is 4096.

devendraswamy avatar Mar 13 '20 04:03 devendraswamy

When I use my own data to train fasterrcnn model and run demo.py, the following error occurs,please help me analyze the error: RuntimeError: Error(s) in loading state_dict for vgg16: While copying the parameter named "RCNN_rpn.RPN_cls_score.weight", whose dimensions in the model are torch.Size([18, 512, 1, 1]) and whose dimensions in the checkpoint are torch.Size([24, 512, 1, 1]). While copying the parameter named "RCNN_rpn.RPN_cls_score.bias", whose dimensions in the model are torch.Size([18]) and whose dimensions in the checkpoint are torch.Size([24]). While copying the parameter named "RCNN_rpn.RPN_bbox_pred.weight", whose dimensions in the model are torch.Size([36, 512, 1, 1]) and whose dimensions in the checkpoint are torch.Size([48, 512, 1, 1]). While copying the parameter named "RCNN_rpn.RPN_bbox_pred.bias", whose dimensions in the model are torch.Size([36]) and whose dimensions in the checkpoint are torch.Size([48]).

lzkzls avatar Apr 29 '20 07:04 lzkzls

Check the anchor scales at training and demo.py , check the classes in demo.py code

On Wed 29 Apr, 2020, 13:03 lzkzls, [email protected] wrote:

When I use my own data to train fasterrcnn model and run demo.py, the following error occurs,please help me analyze the error: RuntimeError: Error(s) in loading state_dict for vgg16: While copying the parameter named "RCNN_rpn.RPN_cls_score.weight", whose dimensions in the model are torch.Size([18, 512, 1, 1]) and whose dimensions in the checkpoint are torch.Size([24, 512, 1, 1]). While copying the parameter named "RCNN_rpn.RPN_cls_score.bias", whose dimensions in the model are torch.Size([18]) and whose dimensions in the checkpoint are torch.Size([24]). While copying the parameter named "RCNN_rpn.RPN_bbox_pred.weight", whose dimensions in the model are torch.Size([36, 512, 1, 1]) and whose dimensions in the checkpoint are torch.Size([48, 512, 1, 1]). While copying the parameter named "RCNN_rpn.RPN_bbox_pred.bias", whose dimensions in the model are torch.Size([36]) and whose dimensions in the checkpoint are torch.Size([48]).

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jwyang/faster-rcnn.pytorch/issues/766#issuecomment-621037535, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALLD6LU3FOCO37UM3DG6BHDRO7J55ANCNFSM4LEIMXKA .

devendraswamy avatar Apr 29 '20 07:04 devendraswamy

Check the anchor scales at training and demo.py , check the classes in demo.py code On Wed 29 Apr, 2020, 13:03 lzkzls, @.***> wrote: When I use my own data to train fasterrcnn model and run demo.py, the following error occurs,please help me analyze the error: RuntimeError: Error(s) in loading state_dict for vgg16: While copying the parameter named "RCNN_rpn.RPN_cls_score.weight", whose dimensions in the model are torch.Size([18, 512, 1, 1]) and whose dimensions in the checkpoint are torch.Size([24, 512, 1, 1]). While copying the parameter named "RCNN_rpn.RPN_cls_score.bias", whose dimensions in the model are torch.Size([18]) and whose dimensions in the checkpoint are torch.Size([24]). While copying the parameter named "RCNN_rpn.RPN_bbox_pred.weight", whose dimensions in the model are torch.Size([36, 512, 1, 1]) and whose dimensions in the checkpoint are torch.Size([48, 512, 1, 1]). While copying the parameter named "RCNN_rpn.RPN_bbox_pred.bias", whose dimensions in the model are torch.Size([36]) and whose dimensions in the checkpoint are torch.Size([48]). — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#766 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALLD6LU3FOCO37UM3DG6BHDRO7J55ANCNFSM4LEIMXKA .

Thanks for your reply. I changed the category into my own category. I don't quite understand what you mean by "Check the anchor scales at training and demo.py ". According to the error prompt, is this the problem of batch size?

lzkzls avatar Apr 29 '20 07:04 lzkzls

No check the parameters which your used in training time like anchor scales and ratios and check the same parameters at demo.py code while you running and along with that change the classes names as per your dataset.

On Wed 29 Apr, 2020, 13:22 lzkzls, [email protected] wrote:

Check the anchor scales at training and demo.py , check the classes in demo.py code … <#m_-237917486883643358_> On Wed 29 Apr, 2020, 13:03 lzkzls, @.***> wrote: When I use my own data to train fasterrcnn model and run demo.py, the following error occurs,please help me analyze the error: RuntimeError: Error(s) in loading state_dict for vgg16: While copying the parameter named "RCNN_rpn.RPN_cls_score.weight", whose dimensions in the model are torch.Size([18, 512, 1, 1]) and whose dimensions in the checkpoint are torch.Size([24, 512, 1, 1]). While copying the parameter named "RCNN_rpn.RPN_cls_score.bias", whose dimensions in the model are torch.Size([18]) and whose dimensions in the checkpoint are torch.Size([24]). While copying the parameter named "RCNN_rpn.RPN_bbox_pred.weight", whose dimensions in the model are torch.Size([36, 512, 1, 1]) and whose dimensions in the checkpoint are torch.Size([48, 512, 1, 1]). While copying the parameter named "RCNN_rpn.RPN_bbox_pred.bias", whose dimensions in the model are torch.Size([36]) and whose dimensions in the checkpoint are torch.Size([48]). — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#766 (comment) https://github.com/jwyang/faster-rcnn.pytorch/issues/766#issuecomment-621037535>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALLD6LU3FOCO37UM3DG6BHDRO7J55ANCNFSM4LEIMXKA .

Thanks for your reply. I changed the category into my own category. I don't quite understand what you mean by "Check the anchor scales at training and demo.py ". According to the error prompt, is this the problem of batch size?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jwyang/faster-rcnn.pytorch/issues/766#issuecomment-621046256, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALLD6LTSAMO6Q5CU2ZS3GNDRO7MCTANCNFSM4LEIMXKA .

devendraswamy avatar Apr 29 '20 07:04 devendraswamy

How did you solve your problem?

wuxueliang123 avatar Jul 20 '20 09:07 wuxueliang123

Plz check your no classes in testing with traning classes .. those are must be had same length

On Mon 20 Jul, 2020, 15:08 wuxueliang123, [email protected] wrote:

How did you solve your problem?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jwyang/faster-rcnn.pytorch/issues/766#issuecomment-660920003, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALLD6LWJPYZBZUPKUMVUIJ3R4QGCZANCNFSM4LEIMXKA .

devendraswamy avatar Jul 20 '20 09:07 devendraswamy

i don't know this error...in my case "copying a param with shape torch.Size([128, 4600]) from checkpoint, the shape in current model is torch.Size([128, 4400])" is come out. how can i fixed it??I'm really dont know why!!i'm stuck with this error

hyejeong99 avatar Feb 18 '21 02:02 hyejeong99

Plz check your no classes in testing with traning classes .. those are must be had same length On Mon 20 Jul, 2020, 15:08 wuxueliang123, @.***> wrote: How did you solve your problem? — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#766 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALLD6LWJPYZBZUPKUMVUIJ3R4QGCZANCNFSM4LEIMXKA .

nice bro!

mvpzhangqiu avatar Sep 27 '21 07:09 mvpzhangqiu