Caffe 运行平台支持DSSD模型
Posted 楚兴
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Caffe 运行平台支持DSSD模型相关的知识,希望对你有一定的参考价值。
DSSD源码:https://github.com/chengyangfu/caffe/tree/dssd
在cuda9环境下编译,首先把Makefile.config里面的USE_CUDNN := 1
开关打开,编译报如下的错:
make: *** [.build_release/src/caffe/layers/multibox_loss_layer.o] Error 1
In file included from ./include/caffe/util/device_alternate.hpp:40:0,
from ./include/caffe/common.hpp:19,
from ./include/caffe/blob.hpp:8,
from ./include/caffe/caffe.hpp:7,
from src/caffe/parallel.cpp:12:
./include/caffe/util/cudnn.hpp: In function 'void caffe::cudnn::setConvolutionDesc(cudnnConvolutionStruct**, cudnnTensorDescriptor_t, cudnnFilterDescriptor_t, int, int, int, int)':
./include/caffe/util/cudnn.hpp:112:3: error: too few arguments to function 'cudnnStatus_t cudnnSetConvolution2dDescriptor(cudnnConvolutionDescriptor_t, int, int, int, int, int, int, cudnnConvolutionMode_t, cudnnDataType_t)'
CUDNN_CHECK(cudnnSetConvolution2dDescriptor(*conv,
^
In file included from ./include/caffe/util/cudnn.hpp:5:0,
from ./include/caffe/util/device_alternate.hpp:40,
from ./include/caffe/common.hpp:19,
from ./include/caffe/blob.hpp:8,
from ./include/caffe/caffe.hpp:7,
from src/caffe/parallel.cpp:12:
/usr/local/cuda/include/cudnn.h:537:27: note: declared here
cudnnStatus_t CUDNNWINAPI cudnnSetConvolution2dDescriptor( cudnnConvolutionDescriptor_t convDesc,
^
原因:上述DSSD的代码是基于老版本的caffe开发,老版本的caffe不支持新版本的cudnn,从而报错。
老版本的caffe代码如下:
template <typename Dtype>
inline void setConvolutionDesc(cudnnConvolutionDescriptor_t* conv,
cudnnTensorDescriptor_t bottom, cudnnFilterDescriptor_t filter,
int pad_h, int pad_w, int stride_h, int stride_w)
CUDNN_CHECK(cudnnSetConvolution2dDescriptor(*conv,
pad_h, pad_w, stride_h, stride_w, 1, 1, CUDNN_CROSS_CORRELATION));
新版本的caffe代码如下:
//定义宏CUDNN_VERSION_MIN,从而支持高版本CUDNN。
template <typename Dtype>
inline void setConvolutionDesc(cudnnConvolutionDescriptor_t* conv,
cudnnTensorDescriptor_t bottom, cudnnFilterDescriptor_t filter,
int pad_h, int pad_w, int stride_h, int stride_w)
#if CUDNN_VERSION_MIN(6, 0, 0)
CUDNN_CHECK(cudnnSetConvolution2dDescriptor(*conv,
pad_h, pad_w, stride_h, stride_w, 1, 1, CUDNN_CROSS_CORRELATION,
dataType<Dtype>::type));
#else
CUDNN_CHECK(cudnnSetConvolution2dDescriptor(*conv,
pad_h, pad_w, stride_h, stride_w, 1, 1, CUDNN_CROSS_CORRELATION));
#endif
所以为了让现有运行平台支持DSSD模型,后面的解决方案是:
- 把dssd中新增加的layer添加到现有运行平台的caffe依赖中,即把xxx_layer.hpp加到/include/caffe/layers。
- 重新编译
libcaffe.so.1.0.0
- 把新.so文件替换原有的.so文件
- 把新的include目录替换老的include目录(可以通过
make distribute
生成)
以上是关于Caffe 运行平台支持DSSD模型的主要内容,如果未能解决你的问题,请参考以下文章
Caffe nvcc编译问题:Unsupported gpu architecture
行业热点Facebook发布开源Caffe2深度学习框架,顺应跨平台模型训练的新趋势