前言
目标检测经典算法faster-rcnn在caffe框架上的实现,本文介绍了代码配置过程。
1. 安装依赖包
1 | sudo apt-get install python-opencv |
2. 克隆文件
1 | git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git |
3. 配置文件
1 | cd py-faster-rcnn/lib |
1 | cd py-faster-rcnn/caffe-fast-rcnn |
-
如果采用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 | INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include |
修改为
1 | INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/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 | cd py-faster-rcnn/caffe-fast-rcnn |
6. 测试
- 下载文件
1 | cd py-faster-rcnn/ |
- 测试
1 | cd py-faster-rcnn/ |