Faster RCNN 训练中的一些问题及解决办法
今天使用Faster RCNN训练自己的数据的时候,出现了一些因为boost或者是numpy版本不兼容导致的问题,经过各种查资料和求助大神,总算是顺利把网络跑起来了。下面内容都是今天亲测出现的问题并与其对应的解决方案,和大家一起分享,也便于我以后查看。
训练方法:在配置好Faster RCNN之后,准备好自己的数据,修改网络的配置文件和相应的训练脚本满,使用end to end 的训练方法,在$py-faster-rcnn的根目录下执行:./experiments/scripts/faster_rcnn_end2end.sh 0 VGG16 pascal_voc 。以下都是执行该脚本后出现的问题。
Problem 1
AttributeError: 'module' object has no attribute ‘text_format'- 1
- 1
解决方法:在/home/xxx/py-faster-rcnn/lib/fast_rcnn/train.py的头文件导入部分加上 :import google.protobuf.text_format
Problem 2
TypeError: 'numpy.float64' object cannot be interpreted as an index- 1
- 1
这里是因为numpy版本不兼容导致的问题,最好的解决办法是卸载你的numpy,安装numpy1.11.0。如果你和笔者一样不是服务器的网管,没有权限的话,就只能自己想办法解决了。
修改如下几个地方的code:
1) /home/xxx/py-faster-rcnn/lib/roi_data_layer/minibatch.py
将第26行:fg_rois_per_image = np.round(cfg.TRAIN.FG_FRACTION * rois_per_image) 改为:fg_rois_per_image = np.round(cfg.TRAIN.FG_FRACTION * rois_per_image).astype(np.int)- 1
- 2
- 1
- 2
2) /home/xxx/py-faster-rcnn/lib/datasets/ds_utils.py
将第12行:hashes = np.round(boxes * scale).dot(v) 改为:hashes = np.round(boxes * scale).dot(v).astype(np.int)- 1
- 2
- 1
- 2
3) /home/xxx/py-faster-rcnn/lib/fast_rcnn/test.py
将第129行: hashes = np.round(blobs['rois'] * cfg.DEDUP_BOXES).dot(v) 改为: hashes = np.round(blobs['rois'] * cfg.DEDUP_BOXES).dot(v).astype(np.int)- 1
- 2
- 1
- 2
4) /home/xxx/py-faster-rcnn/lib/rpn/proposal_target_layer.py
将第60行:fg_rois_per_image = np.round(cfg.TRAIN.FG_FRACTION * rois_per_image) 改为:fg_rois_per_image = np.round(cfg.TRAIN.FG_FRACTION * rois_per_image).astype(np.int)- 1
- 2
- 1
- 2
Problem3
TypeError: slice indices must be integers or None or have an __index__ method- 1
- 1
这里还是因为numpy版本的原因,最好的解决办法还是换numpy版本(见problem2),但同样也有其他的解决办法。
修改 /home/lzx/py-faster-rcnn/lib/rpn/proposal_target_layer.py,转到123行:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 1
- 2
- 3
- 4
- 5
- 6
- 7
这里的ind,start,end都是 numpy.int 类型,这种类型的数据不能作为索引,所以必须对其进行强制类型转换,转化结果如下:
for ind in inds:ind = int(ind)cls = clss[ind]start = int(4 * cos)end = int(start + 4)bbox_targets[ind, start:end] = bbox_target_data[ind, 1:]bbox_inside_weights[ind, start:end] = cfg.TRAIN.BBOX_INSIDE_WEIGHTSreturn bbox_targets, bbox_inside_weights- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
以上内容是笔者在训练自己的datasets时候出现的一些问题,大部分还是因为Faster RCNN 发布的时候使用的一些库现在都升级了,所以需要对代码中一些细节进行修改!
总结
以上是生活随笔为你收集整理的Faster RCNN 训练中的一些问题及解决办法的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: CNN几种经典模型比较
- 下一篇: MFC中字符间相互转换总结