運行caffe官方提供的jupyter 的rcnn detection,總是出現各種問題。先將問題及方法匯集在此:
1. Selective Search 的安裝問題
按照官網,我下載了selective_search_ijcv_with_python,但是在我的linux matlab2017a上總是出現問題,
`Error using CountVisualWordsIndex (line 21)
First two input arguments should have the same 2D dimensionError in BlobStructColourHistError in Image2HierarchicalGrouping (line 42)
[colourHist blobSizes] = BlobStructColourHist(blobIndIm, colourIm);Error in demo (line 61)
[boxes blobIndIm blobBoxes hierarchy] =
Image2HierarchicalGrouping(im, sigma, k, minSize, colorType,
simFunctionHandles);`
于是我谷歌到了https://github.com/nightrome/matconvnet-calvin/issues/18,按照nightrome的方法下載新的版本,將其與官網合并,形成了最新的版本(見:鏈接: https://pan.baidu.com/s/1bSoJim 密碼: 67rk),在matlab中使用demo,可以順利運行。
2. 使用caffe運行python/detect.py,
報錯信息:OSError: [Errno 2] No such file or directory
修改文件:~/caffe-master/python/selective_search_ijcv_with_python/selective_search.py
修改前:mc = “matlab -nojvm -r \”try; {}; catch; exit; end; exit\”“.format(command)
修改后:mc = “/usr/local/MATLAB/R2014a/bin/matlab -nojvm -r \”try; {}; catch; exit; end; exit\”“.format(command)
3. 繼續出錯:
TypeError: slice indices must be integers or None or have an index method
主要原因是我安裝的caffe時,使用了默認的anaconda安裝的numpy(1.13),應該降級使用1.11,(參考:https://github.com/rbgirshick/py-faster-rcnn/issues/480)但是當我降級后,caffe不能用了,因此只能按照如下方法修改:
將140行前面加上: window=window.astype(np.int64)
即改為:
# Crop window from the image.window=window.astype(np.int64)crop = im[window[0]:window[2], window[1]:window[3]]
將175-179改成:
box=box.astype(np.int64)context_crop = im[box[0]:box[2], box[1]:box[3]]context_crop = caffe.io.resize_image(context_crop, (crop_h, crop_w))crop = np.ones(self.crop_dims, dtype=np.float32) * self.crop_meancrop[int(pad_y):int(pad_y + crop_h), int(pad_x):int(pad_x + crop_w)] = context_crop
參考文獻:
1. http://nbviewer.jupyter.org/github/ouxinyu/ouxinyu.github.io/blob/master/MyCodes/caffe-master/detection.ipynb
2. https://github.com/rbgirshick/py-faster-rcnn/issues/480