1. 程式人生 > >Windows下py-Faster rcnn的編譯及遇到的問題

Windows下py-Faster rcnn的編譯及遇到的問題

參考

caffe

windows-caffe的編譯參考我的上一篇部落格,或是找其他。
在編譯windows-caffe的時候有個小問題,預設是沒有把roi_pooling層放進去編譯的,這樣的後果就是之後在執行pyfaster-rcnn網路的時候會出現Check failed: registry.count(type) == 1 (0 vs. 1) Unknown layer ROIPooling的問題。
把roi_pooling_layer.hpp , roi_pooling_layer.cpp , roi_pooling_layer.cu 新增到libcaffe專案的layer層下,具體步驟參照參考資料4.在新增完以後重新編譯,最後編譯出來的pycaffe的介面是在Build/x64/Release/pycaffe/caffe目錄下。
具體參考如下:

caffe,執行fast-rcnn出現Check failed: registry.count(type) == 1 (0 vs. 1) Unknown layer type: ROIPooling
編譯完成後,python介面路徑需要手動配置。設定環境變數PythonPath指向 \Build\x64\Release\pycaffe, 或者複製 \Build\x64\Release\pycaffe\caffe 到python_root\lib\site-packages.這裡的python_root對應miniconda2。這樣之後,在python中import caffe就會成功。

Faster rcnn

  1. 用命令列(CMD)到{Faster root} / lib ,然後執行

    1. python setup.py (cpu)
    2. python setup_cuda.py (GPU)
      其中,修改setup_cuda.py中的第33行為自己的cuda路徑
      include_dirs = [numpy_include, 'C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v8.0\\include']) 
  2. 至此,所需要的東西都編譯好了,可以執行 python tools/demo.py了

遇到的相關錯誤

1. Python error: Microsoft Visual C++ 9.0 is required (Unable to find vcvarsall.bat)

2. ImportError: DLL load failed: 找不到指定的程式。

具體描述:

>>>import matplotlib.pyplot as plt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\ProgramData\Anaconda2\lib\site-packages\matplotlib\pyplot.py", line 29, in <module>
    import matplotlib.colorbar
  File "C:\ProgramData\Anaconda2\lib\site-packages\matplotlib\colorbar.py", line 36, in <module>
    import matplotlib.contour as contour
  File "C:\ProgramData\Anaconda2\lib\site-packages\matplotlib\contour.py", line 23, in <module>
    import matplotlib.text as text
  File "C:\ProgramData\Anaconda2\lib\site-packages\matplotlib\text.py", line 33, in <module>
    from matplotlib.backend_bases import RendererBase
  File "C:\ProgramData\Anaconda2\lib\site-packages\matplotlib\backend_bases.py", line 63, in <module>
    import matplotlib.textpath as textpath
  File "C:\ProgramData\Anaconda2\lib\site-packages\matplotlib\textpath.py", line 20, in <module>
    from matplotlib.mathtext import MathTextParser
  File "C:\ProgramData\Anaconda2\lib\site-packages\matplotlib\mathtext.py", line 62, in <module>
    import matplotlib._png as _png
ImportError: DLL load failed: 找不到指定的程式。

解決方案:conda install libpng(注:一般都是什麼模組沒有裝全,看具體錯誤,缺什麼裝什麼。)

3. AttributeError: ‘ProposalLayer’ object has no attribute ‘param_str_’

解決方案:找到對應檔案,修改param_str_為param_str ,完成編譯。

4. KeyError: ‘1’

具體描述:

Traceback (most recent call last):
  File "demo.py", line 142, in <module>
    _, _= im_detect(net, im)
  File "D:\Windows+Caffe\py-faster-rcnn\tools\..\lib\fast_rcnn\test.py", line 154, in im_detect
    blobs_out = net.forward(**forward_kwargs)
  File "D:\Windows+Caffe\py-faster-rcnn\tools\..\caffe-fast-rcnn\python\caffe\pycaffe.py", line 121, in _Net_forward
    self._forward(start_ind, end_ind)
  File "D:\Windows+Caffe\py-faster-rcnn\tools\..\lib\rpn\proposal_layer.py", line 65, in forward
    pre_nms_topN  = cfg[cfg_key].RPN_PRE_NMS_TOP_N
KeyError: '1'

解決方案:
1. 暴力地將第64行改為cfg_key = ‘TEST’#str(self.phase), demo可以正常執行。
2. 直接做個判斷,phase ==1 為 TEST 0則為TRAIN就可以了

if self.phase:
cfg_key = 'TEST'
else:
cfg_key = 'TRAIN'

注:python程式碼需要注意縮排,不然執行demo.py的時候會報錯

IndentationError: unexpected indent
Traceback (most recent call last):
  File "demo.py", line 135, in <module>
    net = caffe.Net(prototxt, caffemodel, caffe.TEST)
SystemError: NULL result without error in PyObject_Call