deep-learning-for-image-processing icon indicating copy to clipboard operation
deep-learning-for-image-processing copied to clipboard

Using pre-trained faster-rcnn models on COCO, Forecast error of your own dataset

Open kexinxin521 opened this issue 3 years ago • 2 comments

System information

  • Have I written custom code: NO
  • OS Platform(e.g., window10 or Linux Ubuntu 16.04):window11
  • Python version:3.8.13
  • Deep learning framework and version(e.g., Tensorflow2.1 or Pytorch1.3):pytorch 1.3
  • Use GPU or not:GPU
  • CUDA/cuDNN version(if you use GPU):11.6
  • The network you trained(e.g., Resnet34 network):Resnet 50 _fpn @WZMIAOMIAO Describe the current behavior 我在用faster rcnn跑VOC2012数据集的时候,训练和预测没有问题,但是我自己做的一个目标数据集,用训练模式时,弹出一个提示。但是可以顺利导出模型,在使用预测脚本时,报错。如下 训练脚本提示:

Using cuda device training. Using [0, 0.5, 0.6299605249474366, 0.7937005259840997, 1.0, 1.2599210498948732, 1.5874010519681994, 2.0, inf] as bins for aspect ratio quantization Count of instances per bin: [296 4] Using 2 dataloader workers _IncompatibleKeys(missing_keys=[], unexpected_keys=['fc.weight', 'fc.bias'])

Error info / logs 预测脚本报错:

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([7, 1024]) from checkpoint, the shape in current model is torch.Size([6, 1024]). size mismatch for roi_heads.box_predictor.cls_score.bias: copying a param with shape torch.Size([7]) from checkpoint, the shape in current model is torch.Size([6]). size mismatch for roi_heads.box_predictor.bbox_pred.weight: copying a param with shape torch.Size([28, 1024]) from checkpoint, the shape in current model is torch.Size([24, 1024]). size mismatch for roi_heads.box_predictor.bbox_pred.bias: copying a param with shape torch.Size([28]) from checkpoint, the shape in current model is torch.Size([24]).

kexinxin521 avatar Nov 15 '22 04:11 kexinxin521

根据提示,你预测时创建的模型类别和载入的权重模型类别不一致。

WZMIAOMIAO avatar Nov 20 '22 04:11 WZMIAOMIAO

已解决,预测时,创建模型的类别没有加上背景。感谢,加上注释对新手比较友好。

create model num_classes equal background + predict_classes_num

model = create_model(num_classes=7)

kexinxin521 avatar Nov 20 '22 05:11 kexinxin521