PyTorch-Faster R-CNN模型训练好了后进行预测出现size mismatch for head.cls_loc.weight/cls_loc.bias/weight/bias

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

一、问题描述

在大牛的一个讲解训练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]).

二、解决思路

显然这是模型参数和输入参数之间不匹配的问题,但是我不知道问题出在哪个参数

评论 8
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值