下载项目,里面包含的caffe–rcnn与第一部分的caffe并不相同。
git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git
安装cython和easydict:
Cython作为一个Python的编译器,在科学计算方面很流行,是用一个简单的方法来整合C的速度和C数据类型到 Python 函数中去从而提高Python的速度,通过OpenMPI库还可以进行并行计算。
EasyDict允许将dict值作为属性访问(递归运行)。
sudo pip install cython
sudo pip install easydict
编译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']]
#),
编译caffe:到/py-faster-rcnn/caffe-fast-rcnn/目录下,修改Makefile.config文件(和第一部分中的修改一样)和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
测试demo:
首先下载训练好的数据集:
cd ~/py-faster-rcnn
./data/scripts/fetch_faster_rcnn_models.sh
然后修改一些文件:
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):
最后,运行demo:
cd ~/py-faster-rcnn
./tools/demo.py --cpu