报错代码如下:
D:\ProgramData\anaconda3\envs\pytorch\python.exe E:\02Detection\faster-rcnn-pytorch-master\predict.py
Traceback (most recent call last):
File "E:\02Detection\faster-rcnn-pytorch-master\predict.py", line 14, in
frcnn = FRCNN()
File "E:\02Detection\faster-rcnn-pytorch-master\frcnn.py", line 89, in init
self.generate()
File "E:\02Detection\faster-rcnn-pytorch-master\frcnn.py", line 102, in generate
self.net.load_state_dict(torch.load(self.model_path, map_location=device))
File "D:\ProgramData\anaconda3\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 2041, in load_state_dict
raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
RuntimeError: Error(s) in loading state_dict for FasterRCNN:
size mismatch for head.cls_loc.weight: copying a param with shape torch.Size([84, 2048]) from checkpoint, the shape in current model is torch.Size([8, 2048]).
size mismatch for head.cls_loc.bias: copying a param with shape torch.Size([84]) from checkpoint, the shape in current model is torch.Size([8]).
size mismatch for head.score.weight: copying a param with shape torch.Size([21, 2048]) from checkpoint, the shape in current model is torch.Size([2, 2048]).
size mismatch for head.score.bias: copying a param with shape torch.Size([21]) from checkpoint, the shape in current model is torch.Size([2]).
进程已结束,退出代码1
把frcnn.py里面的model_path换成你刚刚训练好的存在logs目录里面的那个就行了,"model_path": 'logs/best_epoch_weights.pth'
把frcnn.py里面的model_path换成你刚刚训练好的存在logs目录里面的那个就行了,"model_path": 'logs/best_epoch_weights.pth'
PS C:\Users\Raj\Desktop\COD_RCNN_cod\src> python inference.py
C:\Users\Raj\AppData\Roaming\Python\Python312\site-packages\torchvision\models_utils.py:208: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and may be removed in the future, please use 'weights' instead.
e 10, in
model.load_state_dict(torch.load( File "C:\Users\Raj\AppData\Roaming\Python\Python312\site-packages\torch\nn\modules\module.py", line 2215, in load_state_dict raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
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([6, 1024]) from checkpoint, the shape in current model is torch.Size([5, 1024]). size mismatch for roi_heads.box_predictor.cls_score.bias: copying a param with shape torch.Size([6]) from checkpoint, the shape in current model is torch.Size([5]). size mismatch for roi_heads.box_predictor.bbox_pred.weight: copying a param with shape torch.Size([24, 1024]) from checkpoint, the shape in current model is torch.Size([20, 1024]). size mismatch for roi_heads.box_predictor.bbox_pred.bias: copying a param with shape torch.Size([24]) from checkpoint, the shape in current model is torch.Size([20]).
PS C:\Users\Raj\Desktop\COD_RCNN_cod\src>
您好,您能告诉我应该怎么做才能解决这个错误吗。
谢谢。