## 【caffe】Layer解读之：Reduction

• Layer type: Reduction
• 头文件位置：./include/caffe/layers/reduction_layer.hpp
• CPU 执行源文件位置: ./src/caffe/layers/reduction_layer.cpp
• CUDA GPU 执行源文件位置: ./src/caffe/layers/reduction_layer.cu
• Reduction层的功能：使用sum或mean等操作作用于输入blob按照给定参数规定的维度。（通俗的讲就是将输入的特征图按照给定的维度进行求和或求平均）。
##### 参数解读
``````layer {
name: "rnn_o_concat"
type: "Concat"
bottom: "o_1"
bottom: "o_2"
bottom: "o_3"
top: "o"
concat_param {
axis: 0
}
}
layer {
name: "o_pseudoloss"
type: "Reduction"
bottom: "o"
top: "o_pseudoloss"
loss_weight: 1
reduction_param{
axis: 0//default = 0
optional ReductionOp operation = SUM //default = SUM
}
}
``````

##### 参数定义

``````// Message that stores parameters used by ReductionLayer
message ReductionParameter {
enum ReductionOp {
SUM = 1;
ASUM = 2;
SUMSQ = 3;
MEAN = 4;
}

optional ReductionOp operation = 1 [default = SUM]; // reduction operation

// The first axis to reduce to a scalar -- may be negative to index from the
// end (e.g., -1 for the last axis).
// (Currently, only reduction along ALL "tail" axes is supported; reduction
// of axis M through N, where N < num_axes - 1, is unsupported.)
// Suppose we have an n-axis bottom Blob with shape:
//     (d0, d1, d2, ..., d(m-1), dm, d(m+1), ..., d(n-1)).
// If axis == m, the output Blob will have shape
//     (d0, d1, d2, ..., d(m-1)),
// and the ReductionOp operation is performed (d0 * d1 * d2 * ... * d(m-1))
// times, each including (dm * d(m+1) * ... * d(n-1)) individual data.
// If axis == 0 (the default), the output Blob always has the empty shape
// (count 1), performing reduction across the entire input --
// often useful for creating new loss functions.
optional int32 axis = 2 [default = 0];

optional float coeff = 3 [default = 1.0]; // coefficient for output
}``````
##### 番外篇

``````convolution_param {
num_output: 1
bias_term: false
kernel_size: 1
weight_filler {
type: 'constant'
value: 1
}
}``````