py-faster-rcnn的CPU安装步骤:
(1)安装cython和easydict:
sudo pip install cython
sudo pip install easydict
(2)下载项目:
git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git
(3)编译cython:
到/py-faster-rcnn/lib/目录下修改setup.py文件,然后make,修改如下
#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']]
#),
(4)修改相关文件:
a、到/py-faster-rcnn/caffe-fast-rcnn/目录下,修改Makefile.config文件,为了make指令的执行,将 Makefile.config.example文件名重命名修改为Makefile.config。
$ cd ~/caffe
$ cp Makefile.config.example Makefile.config
打开Makefile.config文件:去掉CPU_ONLY:= 1的注释
由于是仅CPU安装,注释掉CUDA有关的行:
#CUDA_DIR := /usr/local/cuda
#CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
# -gencode arch=compute_20,code=sm_21 \
# -gencode arch=compute_30,code=sm_30 \
# -gencode arch=compute_35,code=sm_35 \
# -gencode arch=compute_50,code=sm_50 \
# -gencode arch=compute_50,code=compute_50
去掉注释WITH_PYTHON_LAYER := 1
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/i386-linux-gnu/hdf5/serial /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial
#TEST_GPUID := 0
b、修改caffe/examples/cpp_classification/classification.cpp文件,加入:
#include <opencv2/imgproc/types_c.h>
#include <opencv2/objdetect/objdetect_c.h>
c、Makefile 修改:
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5 lmdb opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs
d、修改CMakeLists.txt文件(OFF改成ON):
caffe_option(CPU_ONLY "Build Caffe without CUDA support" ON) # TODO: rename to USE_CUDA
(5)编译caffe:
cd ~/py-faster-rcnn/caffe-fast-rcnn
make -j8&& make pycaffe
(6)测试demo:
cd ~/py-faster-rcnn
./data/scripts/fetch_faster_rcnn_models.sh
(7)然后修改一些文件:
a、修改/py-faster-rcnn/lib/fast_rcnn/config.py文件(True改成False)
# Use GPU implementation of non-maximum suppression
__C.USE_GPU_NMS = False
b、将/py-faster-rcnn/tools/test_net.py和 /py-faster-rcnn/tools/train_net.py的caffe.set_mode_gpu()修改为caffe.set_mode_cpu().
c、修改/py-faster-rcnn/lib/fast_rcnn/nms_wrapper.py文件(注释该引用,并将False改成True)
#from nms.gpu_nms import gpu_nms
def nms(dets, thresh, force_cpu=True):
(8)最后,运行demo:
cd ~/py-faster-rcnn
./tools/demo.py --cpu