解决Mask RCNN的pytorch版本训练时候RuntimeError: Error(s) in loading state_dict for GeneralizedRCNN:
2020-06-06 07:21
12 查看
解决训练时候的RuntimeError: Error(s) in loading state_dict for GeneralizedRCNN:
- 此处错误是在Linux环境下maskrcnn的pytorch版本中遇到的
在训练完成mask rcnn模型后进行图像识别时候出现错误为
Traceback (most recent call last): File "/home/wangfan/maskrcnn-benchmark/demo/person.py", line 74, in <module> confidence_threshold=0.7, File "/home/wangfan/maskrcnn-benchmark/demo/fcpredictorbox.py", line 73, in __init__ _ = checkpointer.load(cfg.MODEL.WEIGHT) File "/home/wangfan/maskrcnn-benchmark/maskrcnn_benchmark/utils/checkpoint.py", line 62, in load self._load_model(checkpoint) File "/home/wangfan/maskrcnn-benchmark/maskrcnn_benchmark/utils/checkpoint.py", line 98, in _load_model load_state_dict(self.model, checkpoint.pop("model")) File "/home/wangfan/maskrcnn-benchmark/maskrcnn_benchmark/utils/model_serialization.py", line 80, in load_state_dict model.load_state_dict(model_state_dict) File "/home/wangfan/anaconda3/envs/maskrcnn/lib/python3.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 GeneralizedRCNN: size mismatch for roi_heads.box.predictor.cls_score.weight: copying a param with shape torch.Size([4, 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([4]) 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([16, 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([16]) from checkpoint, the shape in current model is torch.Size([24]). size mismatch for roi_heads.mask.predictor.mask_fcn_logits.weight: copying a param with shape torch.Size([4, 256, 1, 1]) from checkpoint, the shape in current model is torch.Size([6, 256, 1, 1]). size mismatch for roi_heads.mask.predictor.mask_fcn_logits.bias: copying a param with shape torch.Size([4]) from checkpoint, the shape in current model is torch.Size([6]).
截图显示如下
表示训练的模型分类数量和设置中需要分类的模型数量不一致
在
maskrcnnbenchmark/maskrcnn_benchmark/config路径下找到
defaults.py文件
因此需要在defaults.py文件中将
_C.MODEL.ROI_BOX_HEAD.NUM_CLASSES = 5+1
改为自己训练模型设定的分类数量,
之前为5+1类别所以设定为,本文训练区分三类,加上背景一类为:3+1,
_C.MODEL.ROI_BOX_HEAD.NUM_CLASSES = 3+1
然后再运行图像测试程序
正确
如图所示
相关文章推荐
- pytorch加载的模型踩坑之Error(s) in loading state_dict
- tensorflow加载预训练模型的时候报错:ValueError:No OP Named DecodeBmp in difined operations的解决
- vagrant up error: Valid states are 'starting, running'. The machine is in the 'poweroff' state 解决
- CodeSign error: code signing is required for product type Application in SDK iOS解决办法
- Android Studio运行或Rebuild的时候报Error:Execution failed for task ':app:compileDebugNdk'.的解决办法
- CocoaPods pod install的时候报错:invalid byte sequence in UTF-8 (ArgumentError)解决办法
- 记录error:训练时出现RuntimeError: CUDA out of memory.及解决方法
- CocoaPods pod install的时候报错:invalid byte sequence in UTF-8 (ArgumentError)解决办法
- 训练faster-rcnn出现错误“KeyError: 'max_overlaps'”解决
- 升级xenserver后对存储操作时候报错:Error in Metadata volume operation for SR
- Eclipse 运行SSH项目 一直提示 An internal error occurred during: Loading descriptor for 的解决方法
- <h3>Validation error messages from TagLibraryValidator for c in解决办法
- 解决配置maskrcnn_benchmark时候,CUDA10.1环境配置问题
- configure: error: no acceptable C compiler found in $PATH See `config.log' for more details 问题解决
- CodeSign error: code signing is required for product type Application in SDK iOS XXX的解决办法
- TypeError: Cannot use 'in' operator to search for 'length' in xxx解决
- Error 11 No resource identifier found for attribute 'textAlignment' in package 'android' 问题解决
- 解决Pytorch 加载训练好的模型 遇到的error问题
- **在写spark的时候遇到Exception in thread "main" java.lang.NoSuchMethodError,查到的都说是版本问题,但是解决不了**,**请问怎么解决**
- python 2.7版本解决TypeError: 'encoding' is an invalid keyword argument for this function