py-faster-rcnn /ubuntu安装遇到的问题

来源:互联网 发布:导航升级软件下载 编辑:程序博客网 时间:2024/06/09 13:11

安装主要参考:http://blog.csdn.net/sinat_30071459/article/details/51332084
1.通过git下载好faster的文件夹后把以前装了的data中的东西全部复杂到刚下载好的data文件夹下,替换合并即可。

2.可以安装opencv3.0.0版本或者自己sudo pip install python-opencv。不要安装opencv3.1.0版本,最后训练时会出错(内核错误blabla)。

3.出现问题:
TypeError: ‘numpy.float64’ object cannot be interpreted as an index
用了 sudo pip install -U numpy==1.11.0 降级numpy1.11.0
结果有新问题ImportError: numpy.core.multiarray failed to import
坑爹的是解决这个问题是要升级numpy 于是又升回去了pip install -U numpy
又回到了
TypeError: ‘numpy.float64’ object cannot be interpreted as an index这个问题上。然后搜这个问题还有另一个解决办法
这个问题的本质就是数据类型的不匹配。所以只要把这个用到numpy.float64的地方改成int类型就可以了,这里面一共有几处需要改:
lib/roi_data_layer/minibatch.py这个文件里面
第26行line 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)
需要改的地方还有以下几处
把.astype(np.int) 加到后面

lib/datasets/ds_utils.py line 12 : hashes = np.round(boxes * scale).dot(v)变成lib/datasets/ds_utils.py line 12 : hashes = np.round(boxes * scale).dot(v).astype(np.int)lib/fast_rcnn/test.py line 129 : hashes = np.round(blobs['rois'] * cfg.DEDUP_BOXES).dot(v)变成lib/fast_rcnn/test.py line 129 : hashes = np.round(blobs['rois'] * cfg.DEDUP_BOXES).dot(v).astype(np.int)lib/rpn/proposal_target_layer.py line 60 : fg_rois_per_image = np.round(cfg.TRAIN.FG_FRACTION * rois_per_image)变成lib/rpn/proposal_target_layer.py line 60 : fg_rois_per_image = np.round(cfg.TRAIN.FG_FRACTION * rois_per_image).astype(np.int)

4.遇到

Traceback (most recent call last):  File "./tools/test_net.py", line 90, in <module>    test_net(net, imdb, max_per_image=args.max_per_image, vis=args.vis)  File "/home/wlw/language/caffe/py-faster-rcnn/tools/../lib/fast_rcnn/test.py", line 295, in test_net    imdb.evaluate_detections(all_boxes, output_dir)  File "/home/wlw/language/caffe/py-faster-rcnn/tools/../lib/datasets/pascal_voc.py", line 317, in evaluate_detections    self._write_voc_results_file(all_boxes)  File "/home/wlw/language/caffe/py-faster-rcnn/tools/../lib/datasets/pascal_voc.py", line 244, in _write_voc_results_file    with open(filename, 'wt') as f:IOError: [Errno 2] No such file or directory: '/home/wlw/language/caffe/py-faster-rcnn/data/VOCdevkit2007/results/VOC2007/Main/comp4_507d2b05-379f-4cf1-a1d4-5bd729d32fb0_det_test_building.txt'

解决方法:检查./data/VOCdevkit2007文件夹是否复制完整,./data/VOCdevkit2007/results/VOC2007目录下是否有Layout Main Segmentation三个文件夹。
通过git下载好faster的文件夹后把以前装的faster的data中的东西全部复制到刚下载好的data文件夹下,替换合并即可。

5.在编译caffe时出现错误:

    In file included from ./include/caffe/util/device_alternate.hpp:40:0,                       from ./include/caffe/common.hpp:19,                       from src/caffe/common.cpp:7:      ./include/caffe/util/cudnn.hpp: In functionvoid caffe::cudnn::createPoolingDesc(cudnnPoolingStruct**, caffe::PoolingParameter_PoolMethod, cudnnPoolingMode_t*, int, int, int, int, int, int)’:      ./include/caffe/util/cudnn.hpp:127:41: error: too few arguments to functioncudnnStatus_t cudnnSetPooling2dDescriptor(cudnnPoolingDescriptor_t, cudnnPoolingMode_t, cudnnNanPropagation_t, int, int, int, int, int, int)’               pad_h, pad_w, stride_h, stride_w));                                               ^      ./include/caffe/util/cudnn.hpp:15:28: note: in definition of macro ‘CUDNN_CHECK’           cudnnStatus_t status = condition; \                                  ^      In file included from ./include/caffe/util/cudnn.hpp:5:0,                       from ./include/caffe/util/device_alternate.hpp:40,                       from ./include/caffe/common.hpp:19,                       from src/caffe/common.cpp:7:      /usr/local/cuda-7.5//include/cudnn.h:803:27: note: declared here       cudnnStatus_t CUDNNWINAPI cudnnSetPooling2dDescriptor(                                 ^      make: *** [.build_release/src/caffe/common.o] Error 1  

这里写图片描述
这里写图片描述
这是因为当前版本的caffe的cudnn实现与系统所安装的cudnn的版本不一致引起的。
解决办法:
1.将./include/caffe/util/cudnn.hpp 换成最新版的caffe里的cudnn的实现,即相应的cudnn.hpp.
2. 将./include/caffe/layers里的,所有以cudnn开头的文件,例如cudnn_conv_layer.hpp。 都替换成最新版的caffe里的相应的同名文件。
3.将./src/caffe/layer里的,所有以cudnn开头的文件,例如cudnn_lrn_layer.cu,cudnn_pooling_layer.cpp,cudnn_sigmoid_layer.cu。
都替换成最新版的caffe里的相应的同名文件。
rbgirshick的py-faster-rcnn实现,因为其cudnn实现为旧版本的实现,所有出现了以上问题.

6.AttributeError: ‘module’ object has no attribute ‘text_format’ :
在文件./lib/fast_rcnn/train.py增加一行import google.protobuf.text_format 即可解决问题

7.TypeError: slice indices must be integers or None or have an index method:
这里还是因为numpy版本的原因,最好的解决办法还是换numpy版本(见problem2),但同样也有其他的解决办法。
修改 /home/lzx/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_weights

原创粉丝点击