caffe跑densenet的错误:Message type "caffe.PoolingParameter" has no field named "ceil_mode".
来源:互联网 发布:javascript map对象 编辑:程序博客网 时间:2024/06/05 02:29
最近看了densenet这篇论文,论文作者给了基于caffe的源码,自己在电脑上跑了下,但是出现了Message type “caffe.PoolingParameter” has no field named “ceil_mode”.的错误,现将解决办法记载如下。主要是参考
(https://github.com/BVLC/caffe/pull/3057/files)。错误原因:由于caffe的版本的原因,现用的caffe的源码中的pooling层没有ceil_mode
这个函数,因此解决办法也是在现在的源码中网pooling层中添加这个参数以及相关的代码,并重新编译caffe即可。
1、修改pooling_layer.hpp文件PoolingLayer类
在pooling_layer.hpp中往PoolingLayer类中添加ceil_mode_这个参数,修改如下:
int height_, width_; int pooled_height_, pooled_width_; bool global_pooling_; bool ceil_mode_; //添加的类成员变量 Blob<Dtype> rand_idx_; Blob<int> max_idx_;
2、修改pooling_layer.cpp文件中相关参数
主要涉及到LayerSetUp函数和Reshape函数。LayerSetUp函数修改如下:
|| (!pool_param.has_stride_h() && !pool_param.has_stride_w())) << "Stride is stride OR stride_h and stride_w are required."; global_pooling_ = pool_param.global_pooling(); ceil_mode_ = pool_param.ceil_mode(); //添加的代码,主要作用是从参数文件中获取ceil_mode_的参数数值。 if (global_pooling_) { kernel_h_ = bottom[0]->height(); kernel_w_ = bottom[0]->width(); if (pad_h_ != 0 || pad_w_ != 0) { CHECK(this->layer_param_.pooling_param().pool() == PoolingParameter_PoolMethod_AVE || this->layer_param_.pooling_param().pool() == PoolingParameter_PoolMethod_MAX) << "Padding implemented only for average and max pooling."; CHECK_LT(pad_h_, kernel_h_); CHECK_LT(pad_w_, kernel_w_); .......
Reshape函数修改如下:
void PoolingLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) { CHECK_EQ(4, bottom[0]->num_axes()) << "Input must have 4 axes, " << "corresponding to (num, channels, height, width)"; channels_ = bottom[0]->channels(); height_ = bottom[0]->height(); width_ = bottom[0]->width(); if (global_pooling_) { kernel_h_ = bottom[0]->height(); kernel_w_ = bottom[0]->width(); } - pooled_height_ = static_cast<int>(ceil(static_cast<float>( - height_ + 2 * pad_h_ - kernel_h_) / stride_h_)) + 1; - pooled_width_ = static_cast<int>(ceil(static_cast<float>( - width_ + 2 * pad_w_ - kernel_w_) / stride_w_)) + 1; + // Specify the structure by ceil or floor mode + + // 添加的代码----------------------------------- + if (ceil_mode_) { + pooled_height_ = static_cast<int>(ceil(static_cast<float>( + height_ + 2 * pad_h_ - kernel_h_) / stride_h_)) + 1; + pooled_width_ = static_cast<int>(ceil(static_cast<float>( + width_ + 2 * pad_w_ - kernel_w_) / stride_w_)) + 1; + } else { + pooled_height_ = static_cast<int>(floor(static_cast<float>( + height_ + 2 * pad_h_ - kernel_h_) / stride_h_)) + 1; + pooled_width_ = static_cast<int>(floor(static_cast<float>( + width_ + 2 * pad_w_ - kernel_w_) / stride_w_)) + 1; + } + // ------------------------------------------------------ + if (pad_h_ || pad_w_) { // If we have padding, ensure that the last pooling starts strictly // inside the image (instead of at the padding); otherwise clip the last.
3、修改caffe.proto文件中PoolingParameter的定义
因为添加了pooling层的参数,因此需要修改caffe.proto文件中PoolingParameter中的定义,需要增加参数的声明。
// If global_pooling then it will pool over the size of the bottom by doing // kernel_h = bottom->height and kernel_w = bottom->width optional bool global_pooling = 12 [default = false]; + // Specify floor/ceil mode + optional bool ceil_mode = 13 [default = true];// 为pooling层添加参数,这样可以在net.prototxt文件中为pooling层设置该参数,注意后面需要给其设置一个ID,同时设置一个默认值。 }
4、重新编译caffe
返回到caffe的根目录,使用make指令,即可。
make -j32 // 这里j后面的数字与电脑配置有关系,可以加速编译
注意:这个流程也是一般修改caffe的层的一般流程:1、主要修改相应层的hpp文件和cpp文件;2、如果有参数的添加或者减少,还需要修改caffe.proto文件对应层的参数即可(注意设置正确的ID以及默认值default);3、重新编译caffe
阅读全文
0 0
- caffe跑densenet的错误:Message type "caffe.PoolingParameter" has no field named "ceil_mode".
- Caffe:Message type "caffe.LayerParameter" has no field named "reshape_param".
- Caffe:Message type "caffe.LayerParameter" has no field named "reshape_param".
- Caffe错误:Message type "caffe.SolverParameter" has no field named "name"
- ssd-mobilenet编译出错:Message type "caffe.LayerParameter" has no field named "permute_param"
- 用caffe训练自己的数据集时出错:type “caffe.ImageDataParameter” has no field named “backend”
- DenseNet-caffe
- no model named caffe
- ImportError: No module named caffe 的解决方案
- ImportError: No module named caffe 的解决方案
- ImportError: No module named caffe 的解决方案
- ImportError: No module named caffe 的解决方案
- 在caffe.proto中定义变量出现“'xxxParameter' has no member named 'xxx'”问题的解决
- 【Caffe安装】ImportError: No module named caffe 的解决方案
- No module named caffe,ubuntu16.04安装caffe的问题解决
- caffe 学习笔记之PoolingParameter
- import caffe失败 No module named caffe
- import caffe ImportError: No module named caffe
- 题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。(java)
- java中RSA数字证书生成,jks文件生成以及读取。
- SpringMVC知识点总结
- 题目:输入两个正整数m和n,求其最大公约数和最小公倍数。(java)
- idea常用快捷键设置(改为eclipse相似)
- caffe跑densenet的错误:Message type "caffe.PoolingParameter" has no field named "ceil_mode".
- Eclipse 中新建svn 仓库卡死的问题,就是把URL 路径写完,finish后 就一直 卡着不动
- ConcurrentHashMap与HashTable的区别
- main方法中访问内部类
- EasyDemo*Conversion to Dalvik format failed with wrror 1?(it's work)
- 题目:求s=a+aa+aaa+aaaa+aa...a的值,其中a是一个数字。例如5+55+555+5555+55555(此时共有5个数相加),几个数相加有键盘控制。
- 第十三周 ——项目二 “二叉树排序树中查找的路径”
- [Offer收割]编程练习赛38 题目1 : 漏写的数字
- Numpy-argsort函数