faster-rcnn( Ubuntu 14.04 / CUDA 7.5 / cuDNN 5.1/matlab )

  • caffe-master + windows

我的电脑比较渣,独立显卡计算能力,所以并没有使用GPU+Cudnn加速。依照README.md中的指示在Makefile.config依次配置python,matlab环境。其中,在配置Miniconda2环境时,需要将E:\ProgramData\Miniconda2 & E:\ProgramData\Miniconda2\Scripts写入系统路径,然后才可以使用pip命令安装numpy和protobuf,安装指令
— pip install numpy
— conda install --yes numpy scipy matplotlib scikit-image pip
— pip install protobuf
环境配置完成后,修改windows下的CommonSettings.props文件,然后编译caffe for windows源码,记得将roi_pooling_layer和smooth_l1_loss_layer加到解决方案中来。
在运行faster-rcnn代码时,将和GPU有关的代码屏蔽掉即可。

  • BVLC/caffe + ubuntu

首先下载caffe源码:download caffe: git clone git://github.com/BVLC/caffe.git
配置第三方库的过程请参考博客:http://www.cnblogs.com/yaoyaoliu/p/5850993.html

    • 安装Cudnn

下载地址:https://developer.nvidia.com/cudnn,需要先注册账号,下载的时候需要注意cuda和cudnn版本的兼容性,我的是cuda7.5 & cudnn-7.5-linux-x64-v5.1。
解压之后,需要将相应的头文件和库文件拷贝到cuda的路径下以便调用,操作指令如下:

sudo tar xvf cudnn-7.5-linux-x64-v5.1.tgz

cd cuda

sudo cp include/*.h /usr/local/cuda/include/

sudo cp lib64/lib* /usr/local/cuda/lib64

cd /usr/local/lib

sudo chmod +r libcudnn.so.5.1.10

sudo ln -sf licd bcudnn.so.5.1.10 libcudnn.so.5

sudo ln -sf libcudnn.so.5 libcudnn.so

  sudo ldconfig

    • 修改配置文件:

# cuDNN acceleration switch (uncomment to build with cuDNN).
USE_CUDNN := 1

# CPU-only switch (uncomment to build without GPU support).
# CPU_ONLY := 1

USE_OPENCV := 1
USE_LEVELDB := 1
USE_LMDB := 1

OPENCV_VERSION := 3

CUDA_DIR := /usr/local/cuda

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_52,code=sm_52 \
-gencode arch=compute_52,code=compute_52

BLAS := atlas

MATLAB_DIR := /usr/local/MATLAB/R2014a

PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/lib/python2.7/dist-packages/numpy/core/include

PYTHON_LIB := /usr/lib

INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib

BUILD_DIR := build
DISTRIBUTE_DIR := distribute

TEST_GPUID := 0

Q ?= @

    • 开始编译

     在caffe路径下执行make all -j8编译源码。在编译matcaffe时可能会出现问题,如果是g++版本的问题,可以这样解决:在Makefile文件中
     加上一句话

CXXFLAGS += -MMD -MP
CXXFLAGS += -std=c++11
如果报出缺少caffe.pb.h的错误,那么可以用 protoc caffe.proto --cpp_out=./ 指令生成caffe.pb.h文件,然后拷贝到 caffe/include/caffe/proto/路径下。
这样编译之后的caffe在faster-rcnn中仍然会报错,原因是缺少roi_pooling和smooth_l1_loss层,所以要在源码中加入这两个文件,之后还要修改caffe.proto文件,要分别在LayerParameter和V1layerParameter中添加:
optional ROIPoolingParameter roi_pooling_param = 150 & optional SmoothL1LossParameter smooth_l1_loss_param = 151;
另外,需要用如下方法来声明这两个层:

message ROIPoolingParameter {

// Pad, kernel size, and stride are all given as a single value for equal

// dimensions in height and width or as Y, X pairs.

optional uint32 pooled_h = 1 [default = 0]; // The pooled output height

optional uint32 pooled_w = 2 [default = 0]; // The pooled output width

optional float spatial_scale = 3 [default = 1];

}

message SmoothL1LossParameter {
// SmoothL1Loss(x) =
// 0.5 * (sigma * x) ** 2 -- if x < 1.0 / sigma / sigma
// |x| - 0.5 / sigma / sigma -- otherwise
optional float sigma = 1 [default = 1];
}

如此配置之后的caffe在faster-rcnn中仍会报错,这其中包括dropout train scale没有声明以及caffe缺少成员函数reshape_as_input等错误。说明faster-rcnn的caffe在BVLC版caffe的基础上有了较大改动,所以我决定使用shaoqingren提供的caffe代码重新编译。

  • shaoqingren/caffe + ubuntu

    作者提供的caffe由于是基于cuda6.5实现的,所以可能和自己装的cuda版本不一致,和cudnn相关的所有代码将出现不兼容的问题,并不想重装cuda,所有我尝试用caffe-master的代码重新编译。

  • caffe-master + ubuntu

    这个过程还算顺利,只需要去掉box_annotator_ohem_layer.cpp 这个文件,然后使用之前修改好的Makefile.config就可以了,大功告成!
posted @ 2017-08-03 20:52  信步闲庭、、  阅读(214)  评论(0编辑  收藏  举报