Caffe配置:
采用http://blog.csdn.net/u013989576/article/details/56677749配置好caffe
py-faster-rcnn配置:
1、下载py-faster-rcnn源码
git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git
2、安装cython、easydict
sudo pip install cython
sudo pip install easydict
3、编译cython:修改py-faster-rcnn/lib下的setup.py文件,注释掉GPU的相关代码,然后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']]
#),
make
4、编译caffe:修改py-faster-rcnn/caffe-fast-rcnn下的Makefile.config文件和CMakeLists.txt文件,对于Makefile.config文件的修改,和 caffe配置中的修改一样,对于CMakeLists.txt文件,将OFF改成ON,即:
caffe_option(CPU_ONLY "Build Caffe without CUDA support" ON) # TODO: rename to USE_CUDA
cd ~/py-faster-rcnn/caffe-fast-rcnn
make -j8&& make pycaffe
5、测试demo
5.1 下载训练好的模型
cd ~/py-faster-rcnn
./data/scripts/fetch_faster_rcnn_models.sh
有的时候下载不下来,我们可以点击
链接下载,再放到py-faster-rcnn/data下。
5.2 进行如下修改:
A 修改py-faster-rcnn/lib/fast-rcnn下的config.py文件,即:__C.USE_GPU_NMS = False
B 修改py-faster-rcnn/tools下的test_net.py、train_net.py文件,将caffe.set_mode_gpu() 改为caffe.set_mode_cpu()
C 修改py-faster-rcnn/lib/fast-rcnn下的nms_wrapper.py文件,即:
#from nms.gpu_nms import gpu_nms
def nms(dets, thresh, force_cpu= True)
5.3 运行demo
cd ~/py-faster-rcnn
./tools/demo.py --cpu
但是CPU速度比较慢,而且容易内存溢出,所以我们可以使用ZF模型(默认为VGG16):
cd ~/py-faster-rcnn
./tools/demo.py --cpu --net zf