jwyang / faster-rcnn.pytorch

A faster pytorch implementation of faster r-cnn
MIT License
7.67k stars 2.33k forks source link

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]). #766

Open alontrais opened 4 years ago

alontrais commented 4 years ago

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?

devendraswamy commented 4 years ago

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.

lzkzls commented 4 years ago

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]).

devendraswamy commented 4 years ago

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

On Wed 29 Apr, 2020, 13:03 lzkzls, notifications@github.com 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 .

lzkzls commented 4 years ago

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?

devendraswamy commented 4 years ago

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, notifications@github.com 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 .

wuxueliang123 commented 4 years ago

How did you solve your problem?

devendraswamy commented 4 years ago

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, notifications@github.com 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 .

hyejeong99 commented 3 years ago

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

mvpzhangqiu commented 3 years ago

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!