1.下载代码和数据
git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git
2.下载demo模型数据
[root@localhost py-faster-rcnn]# ./data/scripts/fetch_faster_rcnn_models.sh
Downloading Faster R-CNN demo models (695M)...
。。。
Unzipping...
faster_rcnn_models/
faster_rcnn_models/ZF_faster_rcnn_final.caffemodel
faster_rcnn_models/VGG16_faster_rcnn_final.caffemodel
3.编译cython
进入lib目录,修改setup.py,注释掉GPU相关代码,如下
。。。
#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.编译:
[root@localhost lib]# make
5.安装caffe(自带的,不是通用的)
进入caffe-fast-rcnn目录,大部分跟前面caffe安装记录一文一样,修改Makefile.config(打开WITH_PYTHON_LAYER := 1)
6.修改Makefile
7.编译caffe和pycaffe
[root@localhost caffe-fast-rcnn]# make -j8 && make pycaffe
8.跑demo
[root@localhost py-faster-rcnn]# ./tools/demo.py Traceback (most
recent call last): File “./tools/demo.py”, line 17, in from
fast_rcnn.config import cfg File
“/root/zhanxiang/work/py-faster-rcnn/tools/../lib/fast_rcnn/config.py”,
line 23, in from easydict import EasyDict as edict ImportError: No
module named easydict
缺少Python库easydict,所以安装 pip install easydict
[root@localhost py-faster-rcnn]# ./tools/demo.py Traceback (most
recent call last): File “./tools/demo.py”, line 18, in
from fast_rcnn.test import im_detect File “/root/zhanxiang/work/py-faster-rcnn/tools/../lib/fast_rcnn/test.py”,
line 15, in
import cv2 ImportError: No module named cv2
缺少Python库cv2,这个是openCV里面的。那就来装openCV python库
yum install opencv-python.x86_64
[root@localhost py-faster-rcnn]# python tools/demo.py –cpu Traceback
(most recent call last): File “tools/demo.py”, line 21, in
import matplotlib.pyplot as plt File “/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py”, line 26, in
from matplotlib.figure import Figure, figaspect File “/usr/lib64/python2.7/site-packages/matplotlib/figure.py”, line 36, in
from matplotlib.axes import Axes, SubplotBase, subplot_class_factory File
“/usr/lib64/python2.7/site-packages/matplotlib/axes/init.py”, line
4, in
from ._subplots import * File “/usr/lib64/python2.7/site-packages/matplotlib/axes/_subplots.py”,
line 10, in
from matplotlib.axes._axes import Axes File “/usr/lib64/python2.7/site-packages/matplotlib/axes/_axes.py”, line
14, in
from matplotlib import unpack_labeled_data ImportError: cannot import name unpack_labeled_data
看起来跟matplotlib库有关,pip install的版本太旧,直接下载源码安装。
按照官网指示,http://matplotlib.org/faq/installing_faq.html#install-from-git
[root@localhost work]# git clone git://github.com/matplotlib/matplotlib.git
[root@localhost work]# cd matplotlib/
安装依赖包
[root@localhost matplotlib]# yum-builddep python-matplotlib
安装
[root@localhost matplotlib]# python setup.py install
[
root@localhost py-faster-rcnn]# python tools/demo.py –cpu Traceback
(most recent call last): File “tools/demo.py”, line 19, in
from fast_rcnn.nms_wrapper import nms File “/root/zhanxiang/work/py-faster-rcnn/tools/../lib/fast_rcnn/nms_wrapper.py”,
line 9, in
from nms.gpu_nms import gpu_nms ImportError: No module named gpu_nms
修改nms_wrapper.py,改force_cpu =True
[root@localhost py-faster-rcnn]# vi lib/fast_rcnn/nms_wrapper.py
def nms (dets, thresh, force_cpu =True):
另外把nms_wrapper.py的第9行 from nms.gpu_nms import gpu_nms 注释掉
9.大功告成
[root@localhost py-faster-rcnn]# python tools/demo.py –cpu