1. 程式人生 > >Ubuntu 16.04 測試 tf-faster-rcnn 在CPU下執行

Ubuntu 16.04 測試 tf-faster-rcnn 在CPU下執行

參考連結:

git clone https://github.com/endernewton/tf-faster-rcnn.git

2、執行和修改配置檔案

cd tf-faster-rcnn/lib vim setup.py make clean make

此時會報以下錯誤:

python setup.py build_ext --inplace Traceback (most recent call last):   File "setup.py", line 55, in <module>     CUDA = locate_cuda()   File "setup.py", line 43, in locate_cuda     raise EnvironmentError('The nvcc binary could not be ' OSError: The nvcc binary could not be located in your $PATH. Either add it to your path, or set $CUDAHOME Makefile:2: recipe for target 'all' failed make: *** [all] Error 1  

由於使用的是CPU執行,因此需要修改::lib/setup.py

(1)註釋:#CUDA = locate_cuda()

(2)註釋:

 # Extension('nms.gpu_nms',
    #     ['nms/nms_kernel.cu', 'nms/gpu_nms.pyx'],
    #     library_dirs=[CUDA['lib64']],
    #     libraries=['cudart'],
    #     language='c++',
    #     runtime_library_dirs=[CUDA['lib64']],
    #     # this syntax is specific to this build system
    #     # we're only going to use certain compiler args with nvcc and not with gcc
    #     # the implementation of this trick is in customize_compiler() below
    #     extra_compile_args={'gcc': ["-Wno-unused-function"],
    #                         'nvcc': ['-arch=sm_52',
    #                                  '--ptxas-options=-v',
    #                                  '-c',
    #                                  '--compiler-options',
    #                                  "'-fPIC'"]},
    #     include_dirs = [numpy_include, CUDA['include']]
    # )

修改後再次make,無報錯即可

3、安裝Python coco API,因為程式碼執行需要使用coco API來連線coco 資料集

在終端輸入一下命令:

cd data git clone https://github.com/pdollar/coco.git cd coco/PythonAPI make cd ../../..

4、執行Demo

(1)、下載預訓練模型(voc_0712_80k-110k.tgz)

下載完後放入data資料夾下,使用命令解壓:tar xvf voc_0712_80k-110k.tgz

(2)、在根目錄新建output資料夾,然後將前面解壓出來的預訓練模型的四個檔案拷貝到該資料夾下

(3)、修改tools/demo.py

將tfmodel = os.path.join('output', demonet, DATASETS[dataset][0], 'default',   NETS[demonet][0])

改為:tfmodel = os.path.join('output', NETS[demonet][0])

然後將demo.py拷貝到根目錄,再執行demo.py

這時出現以下錯誤:

Traceback (most recent call last):   File "/home/modao/PycharmProjects/tf-faster-rcnn/tools/demo.py", line 20, in <module>     from model.test import im_detect   File "/home/modao/PycharmProjects/tf-faster-rcnn/tools/../lib/model/test.py", line 24, in <module>     from model.nms_wrapper import nms   File "/home/modao/PycharmProjects/tf-faster-rcnn/tools/../lib/model/nms_wrapper.py", line 12, in <module>     from nms.gpu_nms import gpu_nms ModuleNotFoundError: No module named 'nms.gpu_nms'

(4)、修改lib/model/nms_wrapper.py

註釋:from nms.gpu_nms import gpu_nms

修改force_cpu為:force_cpu=True

再次執行demo.py

成功後會顯示:

Loaded network output/res101_faster_rcnn_iter_110000.ckpt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Demo for data/demo/000456.jpg Detection took 59.350s for 300 object proposals  

圖片檢測結果: