Faster RCNN 爬坑记录

训练

在博客http://blog.csdn.net/Suii_v5/article/details/73776299中介绍了基本的错误类型。我只是做一些自己问题的补充

在error6中,调整numpy的版本,在ubuntu系统中,如果安装了anaconda的话,其实会有两个安装python包的位置,其中一个为系统位置/usr/lib/python2.7/dist-packages, 另一个是anaconda的位置:/home/anaconda2/lib/python2.7/site-packages.

而已经将anaconda2的路径设置进入了环境变量,所以使用单纯pip install 并不能更改anaconda2中的numpy的版本,需要用anaconda2里面的pip进行更新.

anaconda2中pip的路径位于:/home/anaconda2/bin, 输入命令sudo cp pip /usr/bin/pip2.7.13(注意,这里复制的文件一定要取别的名字,不能是pip等一些已经存在的默认命令。)而后进行版本更新即可。

在这里,常见问题就不再一一列出,遇到问题百度就可以了,我举例子说明几个不常见的问题。

Problem1 .在训练stage1 rpn时,出现'numpy.float64' object cannot be interpreted as an index 的提示错误,几乎所有的博客中都指出,需要更换numpy 的版本,照做之后,出现ImportError: numpy.core.multiarray failed to import,这个问题又是numpy不匹配造成的,这样就形成了恶性循环,所以,可以考虑从根源上解决'numpy.float64' object cannot be interpreted as an index

TypeError: 'numpy.float64' object cannot be interpreted as an index 

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)

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)

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)

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)

Problem 2 解决完上一个问题后,又出现 TypeError: slice indices must be integers or None or have an __index__ method的问题,如果没有改变numpy的版本,
修改 /home/XXX/py-faster-rcnn/lib/rpn/proposal_target_layer.py,转到123行:

for ind in inds:
        cls = clss[ind]
        start = 4 * cls
        end = start + 4
        bbox_targets[ind, start:end] = bbox_target_data[ind, 1:]
        bbox_inside_weights[ind, start:end] = cfg.TRAIN.BBOX_INSIDE_WEIGHTS
    return bbox_targets, bbox_inside_weights

这里的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_WEIGHTS
    return bbox_targets, bbox_inside_weight


如果没有问题,建议可以先把迭代次数放很小(例如将py-faster-rcnn/tools/train_faster_rcnn_alt_opt.py中的迭代次数改变为被注释的max_iters = [100, 100, 100, 100]),先让试着训练一次。如果一切顺利,那就可以直接放大的迭代次数就可以了,这样会比较节省时间一点。

测试
按照如下步骤才做就可以了
1 确定模型测试对应网络的prototxt文件
例如:models/pascal_voc/VGG16/faster_rcnn_alt_opt/faster_rcnn_test.pt

2 确定被测试模型文件
例如:output/faster_rcnn_alt_opt/voc_2007_trainval/VGG16_faster_rcnn_final.caffemodel

3 确定配置文件
例如:experiments/cfgs/faster_rcnn_alt_opt.yml

4 确定测试集
例如:voc_2007_test

只要确定了这几个问题,一般测试都不会有问题

笔者不才,目前只做以下记录,如果大家有其他发现的问题,求明示。

下面列出两个讨论更深层次的博客,在创新上可以借鉴
http://blog.csdn.net/z5337209/article/details/72838049
http://blog.csdn.net/qq_34335194/article/details/52778724
原文地址:https://www.cnblogs.com/han1ning1/p/7858357.html