0%

faster-rcnn 配置记录

前言

目标检测经典算法faster-rcnn在caffe框架上的实现,本文介绍了代码配置过程。

1. 安装依赖包

1
2
3
4
5
sudo apt-get install python-opencv

sudo apt-get install cython

sudo pip install easydict

2. 克隆文件

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

3. 配置文件

1
2
3
cd py-faster-rcnn/lib

make
1
2
3
4
5
cd py-faster-rcnn/caffe-fast-rcnn 

cp Makefile.config.example Makefile.config

sudo gedit Makefile.config
  • 如果采用CPU模式:

    # CPU_ONLY := 1 取消注释 CPU_ONLY := 1

  • 使用GPU:

    USE_CUDNN :=1

  • 使用opencv3.0

    # OPENCV_VERSION := 3 修改为:OPENCV_VERSION := 3

  • 若要使用python来编写layer,则需要

    # WITH_PYTHON_LAYER := 1修改为WITH_PYTHON_LAYER := 1

  • 修改hdf5

1
# Whatever else you find you need goes here.
1
2
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib

修改为

1
2
INCLUDE_DIRS :=  $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial
  • 修改nvcc
1
sudo gedit Makefile

1
NVCCFLAGS +=-ccbin=$(CXX) -Xcompiler-fPIC $(COMMON_FLAGS)

替换为

1
NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)

4. 适配新版本的caffe

  • 复制caffe/include/caffe/layers/ cudnn开头的所有文件替换

    py-faster-rcnn/caffe-fast-rcnn/include/caffe/layers 同名文件

  • 复制caffe/src/caffe/layers/ cudnn开头的所有文件替换

    py-faster-rcnn/caffe-fast-rcnn/src/caffe/layers同名文件

  • 将caffe/include/caffe/util/ 里面的cudnn.cpp 复制到

    py-faster-rcnn/caffe-fast-rcnn/include/caffe/util 同名文件

  • import easydict 找不到模块

    将/usr/local/lib/python2.7/dist-packages 里面的 easydict 和 easydict-1.6.egg-info 复制到

    /home/cherrie/anaconda2/lib/python2.7/site-packages下

5. 编译执行

1
2
3
4
5
cd py-faster-rcnn/caffe-fast-rcnn

sudo make -j8

sudo make pycaffe

6. 测试

  • 下载文件
1
2
3
cd py-faster-rcnn/

./data/scripts/fetch_faster_rcnn_models.sh
  • 测试
1
2
3
cd py-faster-rcnn/

python tools/demo.py

7. 运行结果

fasterrcnn运行结果

figure_10