size mismatch for roi_heads.box_predictor.cls_score.weight: copying a param with shape torch.Size([9
Posted 程序媛一枚~
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了size mismatch for roi_heads.box_predictor.cls_score.weight: copying a param with shape torch.Size([9相关的知识,希望对你有一定的参考价值。
1. 报错 RuntimeError: Error(s) in loading state_dict for FasterRCNN: size mismatch for roi_heads.box_predictor.cls_score.weight: copying a param with shape torch.Size([91, 1024]) from checkpoint, the shape in current model is torch.Size([80, 1024]).
pytorch 1.11.0
torchvision 0.12.0
Traceback (most recent call last):
File "C:\\Users\\Administrator\\.IntelliJIdea2017.2\\config\\plugins\\python\\helpers\\pydev\\pydevd.py", line 1596, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\\Users\\Administrator\\.IntelliJIdea2017.2\\config\\plugins\\python\\helpers\\pydev\\pydevd.py", line 1023, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\\Users\\Administrator\\.IntelliJIdea2017.2\\config\\plugins\\python\\helpers\\pydev\\_pydev_imps\\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\\n", file, 'exec'), glob, loc)
File "E:/mat/py-demo-22/p220625/detect_image.py", line 60, in <module>
num_classes=len(CLASSES), pretrained_backbone=True).to(DEVICE)
File "D:\\python374\\lib\\site-packages\\torchvision\\models\\detection\\faster_rcnn.py", line 399, in fasterrcnn_resnet50_fpn
model.load_state_dict(state_dict)
File "D:\\python374\\lib\\site-packages\\torch\\nn\\modules\\module.py", line 1498, in load_state_dict
self.__class__.__name__, "\\n\\t".join(error_msgs)))
RuntimeError: Error(s) in loading state_dict for FasterRCNN:
size mismatch for roi_heads.box_predictor.cls_score.weight: copying a param with shape torch.Size([91, 1024]) from checkpoint, the shape in current model is torch.Size([80, 1024]).
size mismatch for roi_heads.box_predictor.cls_score.bias: copying a param with shape torch.Size([91]) from checkpoint, the shape in current model is torch.Size([80]).
size mismatch for roi_heads.box_predictor.bbox_pred.weight: copying a param with shape torch.Size([364, 1024]) from checkpoint, the shape in current model is torch.Size([320, 1024]).
size mismatch for roi_heads.box_predictor.bbox_pred.bias: copying a param with shape torch.Size([364]) from checkpoint, the shape in current model is torch.Size([320]).
解决
- model.load_state_dict(torch.load(“./model.pth”), False) 未解决
- 调整pytorch版本:pip install pytorch==1.7.1 未解决
报错
Traceback (most recent call last):
File "C:\\Users\\Administrator\\.IntelliJIdea2017.2\\config\\plugins\\python\\helpers\\pydev\\pydevd.py", line 1596, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\\Users\\Administrator\\.IntelliJIdea2017.2\\config\\plugins\\python\\helpers\\pydev\\pydevd.py", line 1023, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\\Users\\Administrator\\.IntelliJIdea2017.2\\config\\plugins\\python\\helpers\\pydev\\_pydev_imps\\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\\n", file, 'exec'), glob, loc)
File "E:/mat/py-demo-22/p220625/detect_image.py", line 50, in <module>
"frcnn-mobilenet": detection.fasterrcnn_mobilenet_v3_large_320_fpn,
AttributeError: module 'torchvision.models.detection' has no attribute 'fasterrcnn_mobilenet_v3_large_320_fpn'
解决办法1: https://github.com/facebookresearch/maskrcnn-benchmark/issues/430
解决办法2:
以上是关于size mismatch for roi_heads.box_predictor.cls_score.weight: copying a param with shape torch.Size([9的主要内容,如果未能解决你的问题,请参考以下文章
size mismatch for roi_heads.box_predictor.cls_score.weight: copying a param with shape torch.Size([9
ntQuerySystemInformtion 和它的 struct - size not mismatch 等疑问
Mismatch in shape: grad_output[0] has a shape of torch.Size([2]) and output[0] has a shape of torch.
Flyway Validate failed: Migration checksum mismatch for migration version 1.0.0.01 错误