使用gpu(gtx1080) cudnn 5.1下编译faster rcnn

来源:互联网 发布:网络攻击防御软件 编辑:程序博客网 时间:2024/05/29 18:57

GPU (CUDA 8.0,Cudnn5.1 ) Faster-rcnn

caffe都弄好的情况下~~~~(现在的版本faster-rcnn据说只支持cudnn 3版本的,所以在这之上要是想使用cudnn的都需要经过替换文件,下面有提到)

特别注意,你每一次编译的时候都需要把之前编译好的文件清除,否则编译不成功,在 ~/py-faster-rcnn/caffe-fast-rcnn下执行 make clean 操作就是清除上一次编译(没有成功的编译在你希望重新编译的时候都需要make clean)

一:

Clone the Faster R-CNN repository

# Make sure toclone with --recursive
git clone--recursive https://github.com/rbgirshick/py-faster-rcnn.git
  • We'll call the directory that you cloned Faster R-CNN intoFRCN_ROOT

Ignore notes 1 and 2 if you followedstep 1 above.

Note 1:If you didn't clone Faster R-CNN with the--recursiveflag, then you'll need to manually clone thecaffe-fast-rcnnsubmodule:

git submoduleupdate --init --recursive

Note 2:Thecaffe-fast-rcnn sub moduleneeds to be on thefaster-rcnn branch(or equivalent detached state). This will happen automaticallyifyou followed step 1 instructions.

上面就是官方文档给出的正确clonefasterrcnn的方法和如果不按照这个给定方法执行所产生的后果:漏装了caffe-fast-rcnn(这个文件在后面很重要,如果没有它,下面的工作无法执行)

二:

下载demo模型数据

cd $FRCN_ROOT
$./data/scripts/fetch_faster_rcnn_models.sh

This will populate the $FRCN_ROOT/datafolder withfaster_rcnn_models. Seedata/README.md for details. These modelswere trained on VOC 2007 trainval.

py-faster-rcnn的路径下找到执行后面到文件./data/scripts/fetch_faster_rcnn_models.sh,所下载的模型会放在py-faster-rcnn的路径下的data文件夹下,名为faster_rcnn_models.(其实也可以不用执行指令下载的,你可以在其他地方下载好了,放在data目录下就好了~)

三:

修改文件:

1.  执行:cp Makefile.config.exampleMakefile.config (caffe-fast-rcnn目录下)

$ cp Makefile.config.exampleMakefile.config(caffe-fast-rcnn目录下)

2.  打开Makefile.config:文件找到相应的地方添加下面的黄色的内容,修改

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/hdf5/serial/

保存退出,注意新加的内容和原来的有空格隔开

否则会出现什么hdf5.o文件找不到~

3.  更改Makefile.config文件:去掉use_cudnn前面的注释 #


#Unrelatedly, it's also recommended that you use CUDNN

USE_CUDNN:= 1


4.  因为这个版本所用的cudnn为旧版本的,可能与新环境的cudnn不兼容

 所以你需要:

1)./py-faster-rcnn/caffe-fast-rcnn/include/caffe/util/cudnn.hpp换成最新版的caffe里的cudnn的实现,即相应的cudnn.hpp.

)./py-faster-rcnn/caffe-fast-rcnn/include/caffe/layers中所有以cudnn开头的文件都(建议到该目录下了之后,使用文件搜索功能替换)用最新caffe源码的以下文件替换掉fasterrcnn的对应文件(一般在caffe目录下的相同目录下:~caffe/include/caffe/layersxx文件)

)./py-faster-rcnn/caffe-fast-rcnn/src/caffe/layers中所有以cudnn开头的文件都(建议到该目录下了之后,使用文件搜索功能替换)用最新caffe(就是贾阳青的那个框架里面的文件)源码的中对应文件替换掉(一般在caffe目录下的相同目录下:~caffe/src/caffe/layersxx文件)

注意是所有文件哦~所有以cudnn开头的文件拉~

否则导致出现如下错误:

In file includedfrom ./include/caffe/util/device_alternate.hpp:40:0,

from ./include/caffe/common.hpp:19,

from ./include/caffe/blob.hpp:8,

from ./include/caffe/layer.hpp:8,

from src/caffe/layer_factory.cpp:8:

./include/caffe/util/cudnn.hpp:In function ‘voidcaffe::cudnn::createPoolingDesc(cudnnPoolingStruct**,caffe::PoolingParameter_PoolMethod, cudnnPoolingMode_t*, int, int,int, int, int, int)’:

./include/caffe/util/cudnn.hpp:127:41: error:too few arguments to function ‘cudnnStatus_t

5.Makefile.config文件中的WITH_PYTHON_LAYER:= 1前面的注释#去掉~

WITH_PYTHON_LAYER:= 1 (Makefile.config文件中)

一定要注意把这个的注释也去掉了,否则下面会出现这种类似的问题(也就是去掉“# ”)

( 类似的问题:

F110302:52:40.782572 12953 layer_factory.hpp:81] Check failed:registry.count(type) == 1 (0 vs. 1) Unknown layer type:Python (knowntypes: AbsVal, Accuracy, ArgMax, BNLL, BatchNorm, BatchReindex, Bias,Concat, ContrastiveLoss, Convolution, Data, Deconvolution, Dropout,DummyData, ELU, Eltwise, Embed, EuclideanLoss, Exp, Filter, Flatten,HDF5Data, HDF5Output, HingeLoss, Im2col, ImageData, InfogainLoss,InnerProduct, LRN, Log, MVN, MemoryData, MultinomialLogisticLoss,PReLU, Pooling, Power, ROIPooling, ReLU, Reduction, Reshape, SPP,Scale, Sigmoid, SigmoidCrossEntropyLoss, Silence, Slice,SmoothL1Loss, Softmax, SoftmaxWithLoss, Split, TanH, Threshold, Tile,WindowData)

*** Check failurestack trace: ***

)

6.安装easydict

$ sudo pip installl easydict (ubuntu根目录下执行,其实哪里执行都ok吧)

一般不建议这样子安装,因为很多时候会出现问题,建议自己去下载压缩包,解压,cd到解压后的文件目录下,你就会看到setup.py文件,在该目录下执行

$ sudo pythonsetup.py install 就可以安装这个库了(这是必须要的库文件,否则编译的时候会出现类似说没有easydict库文件的问题)

不建议使用$python setup.pyinstall来安装setup.py,因为我遇到过下面这种问题

( 

siahooar@siahooar:~/pip-1.5.6$python setup.py install

running install

error:can't create or remove files in install directory


siahooar@siahooar:~/pip-1.5.6$sudo python setup.py install (换成sudoxxx 就好了)

running install

running bdist_egg

running egg_info

四。

编译Cpython(Build the Cython modules)

$ cd $FRCN_ROOT/lib (py-faster-rcnn/lib目录下)

$ make
五。
编译caffe-fast-rcnn(Build Caffe and pycaffe)
cd$FRCN_ROOT/caffe-fast-rcnn (py-faster-rcnn/caffe-fast-rcnn目录下)

然后在该目录下执行:make–j4 && make pycaffe

$ make -j4 &&make pycaffe
六:
运行程序自带的一个例子验证你的faster-rcnn
$ cd py-faster-rcnn
$ ./tools/demo.py
后面就不贴图了 成功了都一样
原创粉丝点击