Faster-r-Cnn 的 CPU_Only 配置方式

Github上早有大神发起过这个问题,我按着这个流程基本就搞定了,原文链接为:

https://github.com/rbgirshick/py-faster-rcnn/issues/123本文基本是对这个Issues翻译加搬运。

首先列举一下相关的错误:

错误1

pythonsetup.py build_ext --inplace

Traceback(most recent call last):

File"setup.py", line 58, in 

CUDA= locate_cuda()

File"setup.py", line 46, in locate_cuda

raiseEnvironmentError('The nvcc binary could not be '

EnvironmentError:The nvcc binary could not be located in your $PATH. Either add it to your path,or set $CUDAHOME

make:*** [all] Error 1

 

错误2

F082521:46:15.782125 7066 common.cpp:55] Cannot use GPU in CPU-only Caffe: checkmode.

 

类似于上面的错误都可以通过下面的方式解决:

  1. 首先是需要将 ./lib/fast_rcnn/下的config.py  里面的USE_GPU_NMS改为 False
  2. 需要将 ./tools下面的两个文件 train_net.py test_net.py中的set_mode_gpu(),替换为set_mode_cpu()
  3. 还有如果只是编译CPU代码,可以把Makefile.Config中的 CPU_ONLY的注释去掉。
  4. ./lib下的 setup.py文件中的三处进行注释,分别为:

             CUDA= locate_cuda()

         和

             self.set_executable('compiler_so',CUDA['nvcc'])

         以及

               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_35',

              '--ptxas-options=-v',

              '-c',

              '--compiler-options',

              "'-fPIC'"]},

             include_dirs= [numpy_include, CUDA['include']]

             )

  1. 此时需要重新编译 lib的内容,即调用 lib 下的make ,再重新编译整个工程。
  2. 最后一个坑,在调用 ./demo.py时,需要在后面加上 --cpu

按照以上的步骤,就可以完成CPU的编译。希望对大家有帮助。

你可能感兴趣的:(深度学习)