Ubuntu14.04配置Faster-RCNN

来源:互联网 发布:ie11浏览器修复软件 编辑:程序博客网 时间:2024/06/05 05:45

1. 环境准备

  • Ubuntu14.04 64位
  • Python2.7.6
  • CUDA7.5
  • cuDNN5.1.10
  • Caffe
  • NVIDIA Quadro K4200

2. 编译Faster-RCNN

2.1 官网下载源码

git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git

编译前请先参考2.3部分避免cuDNN相关的编译错误,计算能力低于3.5的请先参考2.5部分修改配置信息

2.2 生成Cython模块

检查一些相关依赖是否安装:

sudo apt-get install python-pipsudo pip install cythonsudo apt-get install python-opencvsudo pip install easydict

生成Cython模块

cd $FRCN_ROOT/libmake

2.3 生成Caffe和pycaffe

cd $FRCN_ROOT/caffe-fast-rcnn
按照配置Caffe的过程生成自己的Makefile.config文件,参考如下:

## Refer to http://caffe.berkeleyvision.org/installation.html# Contributions simplifying and improving our build system are welcome!# cuDNN acceleration switch (uncomment to build with cuDNN).USE_CUDNN := 1# CPU-only switch (uncomment to build without GPU support).# CPU_ONLY := 1# uncomment to disable IO dependencies and corresponding data layers# USE_OPENCV := 0# USE_LEVELDB := 0# USE_LMDB := 0# uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)#You should not set this flag if you will be reading LMDBs with any#possibility of simultaneous read and write# ALLOW_LMDB_NOLOCK := 1# Uncomment if you're using OpenCV 3# OPENCV_VERSION := 3# To customize your choice of compiler, uncomment and set the following.# N.B. the default for Linux is g++ and the default for OSX is clang++# CUSTOM_CXX := g++# CUDA directory contains bin/ and lib/ directories that we need.CUDA_DIR := /usr/local/cuda# On Ubuntu 14.04, if cuda tools are installed via# "sudo apt-get install nvidia-cuda-toolkit" then use this instead:# CUDA_DIR := /usr# CUDA architecture setting: going with all of them.# For CUDA < 6.0, comment the *_50 lines for compatibility.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# BLAS choice:# atlas for ATLAS (default)# mkl for MKL# open for OpenBlasBLAS := atlas# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.# Leave commented to accept the defaults for your choice of BLAS# (which should work)!# BLAS_INCLUDE := /path/to/your/blas# BLAS_LIB := /path/to/your/blas# Homebrew puts openblas in a directory that is not on the standard search path# BLAS_INCLUDE := $(shell brew --prefix openblas)/include# BLAS_LIB := $(shell brew --prefix openblas)/lib# This is required only if you will compile the matlab interface.# MATLAB directory should contain the mex binary in /bin.# MATLAB_DIR := /usr/local# MATLAB_DIR := /Applications/MATLAB_R2012b.app# NOTE: this is required only if you will compile the python interface.# We need to be able to find Python.h and numpy/arrayobject.h.PYTHON_INCLUDE := /usr/include/python2.7 \/usr/lib/python2.7/dist-packages/numpy/core/include# Anaconda Python distribution is quite popular. Include path:# Verify anaconda location, 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 use Python 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 to find libpythonX.X.so or .dylib.PYTHON_LIB := /usr/lib# PYTHON_LIB := $(ANACONDA_HOME)/lib# Homebrew installs numpy in a non standard path (keg only)# PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include# PYTHON_LIB += $(shell brew --prefix numpy)/lib# Uncomment to support layers written in Python (will link against Python libs)WITH_PYTHON_LAYER := 1# Whatever else you find you need goes here.INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/includeLIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib# If Homebrew is installed at a non standard location (for example your home directory) 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 not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)# USE_PKG_CONFIG := 1BUILD_DIR := buildDISTRIBUTE_DIR := distribute# Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171# DEBUG := 1# The ID of the GPU that 'make runtest' will use to run unit tests.TEST_GPUID := 0# enable pretty build (comment to see full commands)Q ?= @
可以用CMake编译或者直接make编译,CMake方法如下:

cd $FRCN_ROOT/caffe-fast-rcnnmkdir buildcd buildcmake ..make all -j16("‐j16"是使用 CPU 的多核进行编译,可以极大地加速编译的速度)make installmake runtest -j16(如果出错没有关系,直接进行下一步)make pycaffe(编译pycaffe)
make如下:

make -j8 && make pycaffe
出现编译错误:make: *** [.build_release/src/caffe/common.o] Error 1,解决方法参考:编译caffe出现错误:make: *** [.build_release/src/caffe/common.o] Error 1

2.4 下载fetch_fast_rcnn_models

官网给出的方法为运行脚本:

cd $FRCN_ROOT./data/scripts/fetch_faster_rcnn_models.sh
但是由于模型所在地址被墙,所以无法下载,可以先安装Lantern翻墙,然后自行打开脚本中的网址下载,Lantern下载地址:蓝灯最新版下载地址

安装命令:sudo dpkg -i **.deb

下载后直接解压到$FRCN_ROOT/data下即可

2.5 运行demo.py

cd $FRCN_ROOT./tools/demo.py --net vgg16

其中--net选项选择加载的网络,可以是vgg16或者zf,均为小写

如果产生错误:roi_pooling_layer.cu:91] Check failed: error == cudaSuccess (8 vs. 0)  invalid device function

参考:Check failed: error == cudaSuccess (8 vs. 0) invalid device function

修改显卡的计算能力,并重新编译,此处的重新编译意思是参考2.2,编译Cython模块,然后删除三个.c文件,然后重新编译Caffe和pycaffe,如果直接在配置文件中修改,修改内容如下:

CUDA_ARCH := -gencode arch=compute_30,code=sm_30 \-gencode arch=compute_50,code=sm_50 \-gencode arch=compute_50,code=compute_50
删除了计算能力3.5的部分代码,修改完成后也需要重新编译,然后就可以运行demo.py了

3. 参考文章

py-faster-rcnn配置运行demo.py(Ubuntu14.04),不成功的朋友请与我(lee)联系,后面附带邮箱 

Py-faster-rcnn实现自己的数据train和demo 

Caffe: Faster-RCNN Python版本配置 (Windows)