faster-rcnn.pytorch-pytorch-1.0踩坑合集

  1. 在做rcnn项目时,把原数据集更换为乳腺癌数据集后,在运行demo.py遇到了报错:

RuntimeError: Error(s) in loading state_dict for resnet:

size mismatch for RCNN_cls_score.weight: copying a param with shape torch.Size([2, 2048]) from checkpoint, the shape in current model is torch.Size([21, 2048]).

size mismatch for RCNN_cls_score.bias: copying a param with shape torch.Size([2]) from checkpoint, the shape in current model is torch.Size([21]).

size mismatch for RCNN_bbox_pred.weight: copying a param with shape torch.Size([8, 2048]) from checkpoint, the shape in current model is torch.Size([84, 2048]).

size mismatch for RCNN_bbox_pred.bias: copying a param with shape torch.Size([8]) from checkpoint, the shape in current model is torch.Size([84]).

首先在网上查到的结果是更改config.py中的__C.ANCHOR_SCALES = [8,16,32]为 __C.ANCHOR_SCALES = [4,8,16,32]

更改之后发现还是有问题,因为网上更改的数据集为CoCo数据集。目前正在寻找解决方案;

找到解决方案,在demo.py文件中将

pascal_classes = np.asarray(['__background__',

'aeroplane', 'bicycle', 'bird', 'boat',

'bottle', 'bus', 'car', 'cat', 'chair',

'cow', 'diningtable', 'dog', 'horse',

'motorbike', 'person', 'pottedplant',

'sheep', 'sofa', 'train', 'tvmonitor'])

更改为:

pascal_classes = np.asarray(['__background__',

'tumour'])

成功解决问题

你可能感兴趣的:(python)