转自:http://blog.sina.com.cn/s/blog_679f93560102wpyf.html
git clone
--recursive https://github.com/rbgirshick/py-faster-rcnn.git
[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
进入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 notwith
# # 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']]
# ),
。。。
编译:
[root@localhost lib]# make
进入caffe-fast-rcnn目录,大部分跟前面caffe安装记录一文一样,修改Makefile.config为
## Refer tohttp://caffe.berkeleyvision.org/installation.html
# Contributionssimplifying and improving our build system arewelcome!
# cuDNN accelerationswitch (uncomment to build with cuDNN).
# USE_CUDNN :=1
# CPU-only switch(uncomment to build without GPU support).
CPU_ONLY :=1
# uncomment to disableIO dependencies and corresponding data layers
# USE_OPENCV :=0
# USE_LEVELDB :=0
# USE_LMDB :=0
# uncomment to allowMDB_NOLOCK when reading LMDB files (only if necessary)
# You should not set this flag if you will bereading LMDBs with any
# possibility of simultaneous read andwrite
# ALLOW_LMDB_NOLOCK :=1
# Uncomment if you'reusing OpenCV 3
# OPENCV_VERSION :=3
# To customize yourchoice of compiler, uncomment and set the following.
# N.B. the default forLinux is g++ and the default for OSX is clang++
# CUSTOM_CXX :=g++
# CUDA directorycontains bin/ and lib/ directories that we need.
# CUDA_DIR :=/usr/local/cuda
# On Ubuntu 14.04, ifcuda tools are installed via
# "sudo apt-get installnvidia-cuda-toolkit" then use this instead:
# CUDA_DIR :=/usr
# CUDA architecturesetting: going with all of them.
# For CUDA < 6.0,comment the *_50 lines for compatibility.
#CUDA_ARCH := -gencodearch=compute_20,code=sm_20 \
# -gencodearch=compute_20,code=sm_21 \
# -gencodearch=compute_30,code=sm_30 \
# -gencodearch=compute_35,code=sm_35 \
# -gencodearch=compute_50,code=sm_50 \
# -gencodearch=compute_50,code=compute_50
# BLASchoice:
# atlas for ATLAS(default)
# mkl forMKL
# open forOpenBlas
BLAS :=atlas
# Custom(MKL/ATLAS/OpenBLAS) include and lib directories.
# Leave commented toaccept the defaults for your choice of BLAS
# (which shouldwork)!
BLAS_INCLUDE :=/usr/include/atlas-x86_64-base
BLAS_LIB :=/usr/lib64/atlas
# Homebrew putsopenblas in a directory that is not on the standard searchpath
# BLAS_INCLUDE :=$(shell brew --prefix openblas)/include
# BLAS_LIB := $(shellbrew --prefix openblas)/lib
# This is required onlyif you will compile the matlab interface.
# MATLAB directoryshould contain the mex binary in /bin.
# MATLAB_DIR :=/usr/local
# MATLAB_DIR :=/Applications/MATLAB_R2012b.app
# NOTE: this isrequired only if you will compile the pythoninterface.
# We need to be able tofind Python.h and numpy/arrayobject.h.
PYTHON_INCLUDE :=/usr/include/python2.7 \
/usr/lib64/python2.7/site-packages/numpy/core/include
# Anaconda Pythondistribution is quite popular. Include path:
# Verify anacondalocation, sometimes it's in root.
# ANACONDA_HOME :=$(HOME)/anaconda
# PYTHON_INCLUDE :=$(ANACONDA_HOME)/include \
#$(ANACONDA_HOME)/include/python2.7 \
#$(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include\
# Uncomment to usePython 3 (default is Python 2)
# PYTHON_LIBRARIES :=boost_python3 python3.5m
# PYTHON_INCLUDE :=/usr/include/python3.5m \
# /usr/lib/python3.5/dist-packages/numpy/core/include
# We need to be able tofind libpythonX.X.so or .dylib.
PYTHON_LIB :=/usr/lib64
# PYTHON_LIB :=$(ANACONDA_HOME)/lib
# Homebrew installsnumpy in a non standard path (keg only)
# PYTHON_INCLUDE +=$(dir $(shell python -c 'import numpy.core;print(numpy.core.__file__)'))/include
# PYTHON_LIB += $(shellbrew --prefix numpy)/lib
# Uncomment to supportlayers written in Python (will link against Pythonlibs)
WITH_PYTHON_LAYER :=1
# Whatever else youfind you need goes here.
INCLUDE_DIRS :=$(PYTHON_INCLUDE) /usr/include
LIBRARY_DIRS :=$(PYTHON_LIB) /usr/lib64
# If Homebrew isinstalled at a non standard location (for example your homedirectory) and you use it for general dependencies
# INCLUDE_DIRS +=$(shell brew --prefix)/include
# LIBRARY_DIRS +=$(shell brew --prefix)/lib
# Uncomment to use`pkg-config` to specify OpenCV library paths.
# (Usually notnecessary -- OpenCV libraries are normally installed in one of theabove $LIBRARY_DIRS.)
# USE_PKG_CONFIG :=1
BUILD_DIR :=build
DISTRIBUTE_DIR :=distribute
# Uncomment fordebugging. Does not work on OSX due tohttps://github.com/BVLC/caffe/issues/171
# DEBUG :=1
# The ID of the GPUthat 'make runtest' will use to run unit tests.
# TEST_GPUID :=0
# enable pretty build(comment to see full commands)
Q ?= @
修改Makefile
LIBRARIES += satlas tatlas #新版atlas已经不用这两个lib了:cblasatlas
编译caffe和pycaffe
[root@localhost caffe-fast-rcnn]# make -j8&& make pycaffe
[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.testimport 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
importmatplotlib.pyplot as plt
File"/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py", line 26,in
from matplotlib.figureimport Figure, figaspect
File"/usr/lib64/python2.7/site-packages/matplotlib/figure.py", line 36,in
from matplotlib.axesimport 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
frommatplotlib.axes._axes import Axes
File"/usr/lib64/python2.7/site-packages/matplotlib/axes/_axes.py", line14, in
from matplotlib importunpack_labeled_data
ImportError: cannot import nameunpack_labeled_data
看起来跟
matplotlib库有关,pipinstall的版本太旧,
直接下载源码安装。
按照官网指示, http://matplotlib.org/faq/installing_faq.html#install-from-git
[root@localhost work]# git clonegit://github.com/matplotlib/matplotlib.git
[root@localhost work]# cd matplotlib/
安装依赖包
[root@localhost matplotlib]# yum-builddeppython-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
fromfast_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 importgpu_nms
ImportError: No module named gpu_nms
修改nms_wrapper.py,改
force_cpu
=
True
[root@localhost py-faster-rcnn]# vilib/fast_rcnn/nms_wrapper.py
def
nms
(
dets
,
thresh
,
force_cpu
=
True
):
[root@localhost py-faster-rcnn]# pythontools/demo.py --cpu
就能看到结果了