[Caffe]: 关于Scale layer

来源:互联网 发布:linux系统切换输入法 编辑:程序博客网 时间:2024/06/04 00:39

Scale layer

caffe源码中给出了scale层的作用,如下:

/** * @brief Computes the elementwise product of two input Blobs, with the shape of *        the latter Blob "broadcast" to match the shape of the former. *        Equivalent to tiling the latter Blob, then computing the elementwise *        product. Note: for efficiency and convenience, this layer can *        additionally perform a "broadcast" sum too when `bias_term: true` *        is set. * * The latter, scale input may be omitted, in which case it's learned as * parameter of the layer (as is the bias, if it is included). */

即,按元素计算连个输入的乘积。该过程以广播第二个输入来匹配第一个输入矩阵的大小。
也就是通过平铺第二个输入矩阵来计算按元素乘积(点乘)。

message ScaleParameter {  // The first axis of bottom[0] (the first input Blob) along which to apply  // bottom[1] (the second input Blob).  May be negative to index from the end  // (e.g., -1 for the last axis).  //  // For example, if bottom[0] is 4D with shape 100x3x40x60, the output  // top[0] will have the same shape, and bottom[1] may have any of the  // following shapes (for the given value of axis):  //    (axis == 0 == -4) 100; 100x3; 100x3x40; 100x3x40x60  //    (axis == 1 == -3)          3;     3x40;     3x40x60  //    (axis == 2 == -2)                   40;       40x60  //    (axis == 3 == -1)                                60  // Furthermore, bottom[1] may have the empty shape (regardless of the value of  // "axis") -- a scalar multiplier.  optional int32 axis = 1 [default = 1]; //指定第二个输入的形状大小,默认为axis = 1,即如例子中所示可能有(3; 3x40; 3x40x60;)三种形状。  // (num_axes is ignored unless just one bottom is given and the scale is  // a learned parameter of the layer.  Otherwise, num_axes is determined by the  // number of axes by the second bottom.) 除了只有一个输入bottom[0]外,num_axes都将被忽略.  // The number of axes of the input (bottom[0]) covered by the scale  // parameter, or -1 to cover all axes of bottom[0] starting from `axis`.  // Set num_axes := 0, to multiply with a zero-axis Blob: a scalar. //num_axes=-1,覆盖第一个输入的所有轴(维度);num_axes=0, 第一个输入与一个标量做点乘.  optional int32 num_axes = 2 [default = 1]; //第一个输入被覆盖轴的数量,默认为1.  // (filler is ignored unless just one bottom is given and the scale is  // a learned parameter of the layer.) 除了只有一个输入bottom[0]外,filler都将被忽略.  // The initialization for the learned scale parameter. 学习的scale参数的初始化.  // Default is the unit (1) initialization, resulting in the ScaleLayer  // initially performing the identity operation. 默认为单位初始化.  optional FillerParameter filler = 3;  // Whether to also learn a bias (equivalent to a ScaleLayer+BiasLayer, but  // may be more efficient).  Initialized with bias_filler (defaults to 0).  optional bool bias_term = 4 [default = false]; //是否同时学习偏差bias,默认为否.  optional FillerParameter bias_filler = 5; //带有偏差填充的初始化,偏差bias_filler默认为0}
0 0