一、问题描述
在大牛的一个讲解训练Faster R-CNN的B站视频上,我依他的步骤训练完了模型。
然后进行预测的时候,出现了以下错误:
RuntimeError: Error(s) in loading state_dict for FasterRCNN:
size mismatch for head.cls_loc.weight: copying a param with shape torch.Size([40, 2048]) from checkpoint, the shape in current model is torch.Size([36, 2048]).
size mismatch for head.cls_loc.bias: copying a param with shape torch.Size([40]) from checkpoint, the shape in current model is torch.Size([36]).
size mismatch for head.score.weight: copying a param with shape torch.Size([10, 2048]) from checkpoint, the shape in current model is torch.Size([9, 2048]).
size mismatch for head.score.bias: copying a param with shape torch.Size([10]) from checkpoint, the shape in current model is torch.Size([9]).
二、解决思路
显然这是模型参数和输入参数之间不匹配的问题,但是我不知道问题出在哪个参数

博主在尝试使用Faster R-CNN模型进行预测时遇到RuntimeError,问题在于模型参数与加载的检查点参数尺寸不一致。经过分析,博主发现num_classes的值可能不正确。通过检查classes.txt文件确定类别数量,并调整num_classes的值,问题得到解决。关键在于正确设置num_classes以匹配模型和检查点的类别数。
最低0.47元/天 解锁文章





