py-faster-rcnn /ubuntu安裝遇到的問題

安裝主要參考: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

發佈了20 篇原創文章 · 獲贊 32 · 訪問量 21萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章