版权声明:未经博主允许,不得转载! https://blog.csdn.net/u011681952/article/details/86151648
Eltwise Layer是对多个bottom进行操作计算并将结果赋值给top,一般特点:多个输入一个输出,多个输入维度要求一致
首先看下Eltwise层的参数:
message EltwiseParameter {
enum EltwiseOp {
PROD = 0; //点乘
SUM = 1; //加减(默认)
MAX = 2; //最大值
}
optional EltwiseOp operation = 1 [default = SUM]; // element-wise operation
repeated float coeff = 2; // blob-wise coefficient for SUM operation
// Whether to use an asymptotically slower (for >2 inputs) but stabler method
// of computing the gradient for the PROD operation. (No effect for SUM op.)
optional bool stable_prod_grad = 3 [default = true];
}
则Eltwise层的操作有三个:product(点乘), sum(相加减) 和 max(取大值),其中sum是默认操作。
假设输入bottom为A和B,
1)如果要实现element_wise的A+B,即A和B的对应元素相加,prototxt文件如下:
layer {
name: "eltwise_layer"
bottom: "A"
bottom: "B"
top: "diff"
type: "Eltwise"
eltwise_param {
operation: SUM
}
}
2)如果实现A-B,则prototxt为:
layer {
name: "eltwise_layer"
bottom: "A"
bottom: "B"
top: "diff"
type: "Eltwise"
eltwise_param {
operation: SUM
coeff: 1
coeff: -1
}
}
注意:其中A和B的系数(coefficient)都要给出。
3)如果实现A.*B,则prototxt为:
layer {
name: "eltwise_layer"
bottom: "A"
bottom: "B"
top: "diff"
type: "Eltwise"
eltwise_param {
operation: PROD
}
}