message ConvolutionParameter {
[...]
enum Engine {
DEFAULT = 0;
CAFFE = 1;
CUDNN = 2;
MASK = 3;
}
#include "caffe/layers/conv_layer_mask.hpp"
[...]
template <typename Dtype>
shared_ptr<Layer<Dtype> > GetConvolutionLayer(const LayerParameter& param) {
[...]
if (engine == ConvolutionParameter_Engine_CAFFE) {
return shared_ptr<Layer<Dtype> >(new ConvolutionLayer<Dtype>(param));
} else if (engine == ConvolutionParameter_Engine_MASK) {
return shared_ptr<Layer<Dtype> >(new MaskConvolutionLayer<Dtype>(param));
#ifdef USE_CUDNN
}
[...]
src/caffe/layer_factory.cpp: In function ‘boost::shared_ptr<caffe::Layer<Dtype> > caffe::GetConvolutionLayer(const caffe::LayerParameter&)’:
src/caffe/layer_factory.cpp:62:37: error: expected primary-expression before ‘(’ token
return shared_ptr<Layer<Dtype> >(new MaskConvolutionLayer<Dtype>(param));
^
src/caffe/layer_factory.cpp:62:42: error: ‘MaskConvolutionLayer’ does not name a type
return shared_ptr<Layer<Dtype> >(new MaskConvolutionLayer<Dtype>(param));
^
src/caffe/layer_factory.cpp:62:68: error: expected primary-expression before ‘>’ token
return shared_ptr<Layer<Dtype> >(new MaskConvolutionLayer<Dtype>(param));
^
src/caffe/layer_factory.cpp: In function ‘boost::shared_ptr<caffe::Layer<Dtype> > caffe::GetTanHLayer(const caffe::LayerParameter&) [with Dtype = double]’:
src/caffe/layer_factory.cpp:240:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
src/caffe/layer_factory.cpp: In function ‘boost::shared_ptr<caffe::Layer<Dtype> > caffe::GetTanHLayer(const caffe::LayerParameter&) [with Dtype = float]’:
src/caffe/layer_factory.cpp:240:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
src/caffe/layer_factory.cpp: In function ‘boost::shared_ptr<caffe::Layer<Dtype> > caffe::GetSoftmaxLayer(const caffe::LayerParameter&) [with Dtype = double]’:
src/caffe/layer_factory.cpp:217:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
src/caffe/layer_factory.cpp: In function ‘boost::shared_ptr<caffe::Layer<Dtype> > caffe::GetSoftmaxLayer(const caffe::LayerParameter&) [with Dtype = float]’:
src/caffe/layer_factory.cpp:217:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
src/caffe/layer_factory.cpp: In function ‘boost::shared_ptr<caffe::Layer<Dtype> > caffe::GetSigmoidLayer(const caffe::LayerParameter&) [with Dtype = double]’:
src/caffe/layer_factory.cpp:194:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
src/caffe/layer_factory.cpp: In function ‘boost::shared_ptr<caffe::Layer<Dtype> > caffe::GetSigmoidLayer(const caffe::LayerParameter&) [with Dtype = float]’:
src/caffe/layer_factory.cpp:194:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
src/caffe/layer_factory.cpp: In function ‘boost::shared_ptr<caffe::Layer<Dtype> > caffe::GetReLULayer(const caffe::LayerParameter&) [with Dtype = double]’:
src/caffe/layer_factory.cpp:171:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
src/caffe/layer_factory.cpp: In function ‘boost::shared_ptr<caffe::Layer<Dtype> > caffe::GetReLULayer(const caffe::LayerParameter&) [with Dtype = float]’:
src/caffe/layer_factory.cpp:171:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
src/caffe/layer_factory.cpp: In function ‘boost::shared_ptr<caffe::Layer<Dtype> > caffe::GetLRNLayer(const caffe::LayerParameter&) [with Dtype = double]’:
src/caffe/layer_factory.cpp:148:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
src/caffe/layer_factory.cpp: In function ‘boost::shared_ptr<caffe::Layer<Dtype> > caffe::GetLRNLayer(const caffe::LayerParameter&) [with Dtype = float]’:
src/caffe/layer_factory.cpp:148:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
src/caffe/layer_factory.cpp: In function ‘boost::shared_ptr<caffe::Layer<Dtype> > caffe::GetPoolingLayer(const caffe::LayerParameter&) [with Dtype = double]’:
src/caffe/layer_factory.cpp:111:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
src/caffe/layer_factory.cpp: In function ‘boost::shared_ptr<caffe::Layer<Dtype> > caffe::GetPoolingLayer(const caffe::LayerParameter&) [with Dtype = float]’:
src/caffe/layer_factory.cpp:111:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
Makefile:572: recipe for target '.build_release/src/caffe/layer_factory.o' failed
make: *** [.build_release/src/caffe/layer_factory.o] Error 1
#include <vector>
#include "caffe/layers/conv_layer_mask.hpp"
namespace caffe {
template <typename Dtype>
void MaskConvolutionLayer<Dtype>::compute_output_shape() {
const int* kernel_shape_data = this->kernel_shape_.cpu_data();
const int* stride_data = this->stride_.cpu_data();
const int* pad_data = this->pad_.cpu_data();
const int* dilation_data = this->dilation_.cpu_data();
this->output_shape_.clear();
for (int i = 0; i < this->num_spatial_axes_; ++i) {
// i + 1 to skip channel axis
const int input_dim = this->input_shape(i + 1);
const int kernel_extent = dilation_data[i] * (kernel_shape_data[i] - 1) + 1;
const int output_dim = (input_dim + 2 * pad_data[i] - kernel_extent)
/ stride_data[i] + 1;
this->output_shape_.push_back(output_dim);
}
}
template <typename Dtype>
void MaskConvolutionLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top) {
const Dtype* weight = this->blobs_[0]->cpu_data();
for (int i = 0; i < bottom.size(); ++i) {
const Dtype* bottom_data = bottom[i]->cpu_data();
Dtype* top_data = top[i]->mutable_cpu_data();
for (int n = 0; n < this->num_; ++n) {
this->forward_cpu_gemm(bottom_data + n * this->bottom_dim_, weight,
top_data + n * this->top_dim_);
if (this->bias_term_) {
const Dtype* bias = this->blobs_[1]->cpu_data();
this->forward_cpu_bias(top_data + n * this->top_dim_, bias);
}
}
}
}
template <typename Dtype>
void MaskConvolutionLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,
const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {
const Dtype* weight = this->blobs_[0]->cpu_data();
const Dtype* mask = this->blobs_[2]->gpu_data();
Dtype* weight_diff = this->blobs_[0]->mutable_cpu_diff();
for (int i = 0; i < top.size(); ++i) {
const Dtype* top_diff = top[i]->cpu_diff();
const Dtype* bottom_data = bottom[i]->cpu_data();
Dtype* bottom_diff = bottom[i]->mutable_cpu_diff();
// Bias gradient, if necessary.
if (this->bias_term_ && this->param_propagate_down_[1]) {
Dtype* bias_diff = this->blobs_[1]->mutable_cpu_diff();
for (int n = 0; n < this->num_; ++n) {
this->backward_cpu_bias(bias_diff, top_diff + n * this->top_dim_);
}
}
if (this->param_propagate_down_[0] || propagate_down[i]) {
for (int n = 0; n < this->num_; ++n) {
// gradient w.r.t. weight. Note that we will accumulate diffs.
if (this->param_propagate_down_[0]) {
this->weight_cpu_gemm(bottom_data + n * this->bottom_dim_,
top_diff + n * this->top_dim_, weight_diff);
}
// gradient w.r.t. bottom data, if necessary.
if (propagate_down[i]) {
this->backward_cpu_gemm(top_diff + n * this->top_dim_, weight,
bottom_diff + n * this->bottom_dim_);
}
}
}
}
const int count = this->blobs_[2]->count();
caffe_mul(count, mask, weight_diff, weight_diff);
}
#ifdef CPU_ONLY
STUB_GPU(MaskConvolutionLayer);
#endif
INSTANTIATE_CLASS(MaskConvolutionLayer);
} // namespace caffe
#ifndef CAFFE_CONV_LAYER_HPP_
#define CAFFE_CONV_LAYER_HPP_
#include <vector>
#include "caffe/blob.hpp"
#include "caffe/layer.hpp"
#include "caffe/proto/caffe.pb.h"
#include "caffe/layers/base_conv_layer.hpp"
namespace caffe {
/**
* @brief Convolves the input image with a bank of learned filters,
* and (optionally) adds biases.
*
* Caffe convolves by reduction to matrix multiplication. This achieves
* high-throughput and generality of input and filter dimensions but comes at
* the cost of memory for matrices. This makes use of efficiency in BLAS.
*
* The input is "im2col" transformed to a channel K' x H x W data matrix
* for multiplication with the N x K' x H x W filter matrix to yield a
* N' x H x W output matrix that is then "col2im" restored. K' is the
* input channel * kernel height * kernel width dimension of the unrolled
* inputs so that the im2col matrix has a column for each input region to
* be filtered. col2im restores the output spatial structure by rolling up
* the output channel N' columns of the output matrix.
*/
template <typename Dtype>
class MaskConvolutionLayer : public BaseConvolutionLayer<Dtype> {
public:
/**
* @param param provides ConvolutionParameter convolution_param,
* with ConvolutionLayer options:
* - num_output. The number of filters.
* - kernel_size / kernel_h / kernel_w. The filter dimensions, given by
* kernel_size for square filters or kernel_h and kernel_w for rectangular
* filters.
* - stride / stride_h / stride_w (\b optional, default 1). The filter
* stride, given by stride_size for equal dimensions or stride_h and stride_w
* for different strides. By default the convolution is dense with stride 1.
* - pad / pad_h / pad_w (\b optional, default 0). The zero-padding for
* convolution, given by pad for equal dimensions or pad_h and pad_w for
* different padding. Input padding is computed implicitly instead of
* actually padding.
* - dilation (\b optional, default 1). The filter
* dilation, given by dilation_size for equal dimensions for different
* dilation. By default the convolution has dilation 1.
* - group (\b optional, default 1). The number of filter groups. Group
* convolution is a method for reducing parameterization by selectively
* connecting input and output channels. The input and output channel dimensions must be divisible
* by the number of groups. For group @f$ \geq 1 @f$, the
* convolutional filters' input and output channels are separated s.t. each
* group takes 1 / group of the input channels and makes 1 / group of the
* output channels. Concretely 4 input channels, 8 output channels, and
* 2 groups separate input channels 1-2 and output channels 1-4 into the
* first group and input channels 3-4 and output channels 5-8 into the second
* group.
* - bias_term (\b optional, default true). Whether to have a bias.
* - engine: convolution has CAFFE (matrix multiplication) and CUDNN (library
* kernels + stream parallelism) engines.
*/
explicit MaskConvolutionLayer(const LayerParameter& param)
: BaseConvolutionLayer<Dtype>(param) {}
virtual inline const char* type() const { return "ConvolutionMask"; }
protected:
virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top);
// virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,
// const vector<Blob<Dtype>*>& top);
virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,
const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);
// virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,
// const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);
virtual inline bool reverse_dimensions() { return false; }
virtual void compute_output_shape();
};
} // namespace caffe
#endif // CAFFE_CONV_LAYER_HPP_
virtual inline const char* type() const { return "ConvolutionMask"; }
virtual inline const char* type() const { return "Convolution"; }
MASK_CONV_LAYER_HPP_, and try to recompile.
Jan
src/caffe/<span style="