本文主要是介绍Caffe Prototxt 特殊层系列:Eltwise Layer,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Eltwise Layer是对多个bottom进行操作计算并将结果赋值给top,一般特点:多个输入一个输出,多个输入维度要求一致
首先看下Eltwise层的参数:
message EltwiseParameter {enum EltwiseOp {PROD = 0; //点乘SUM = 1; //加减(默认)MAX = 2; //最大值}optional EltwiseOp operation = 1 [default = SUM]; // element-wise operationrepeated 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: SUMcoeff: 1coeff: -1}
}
注意:其中A和B的系数(coefficient)都要给出。
3)如果实现A.*B,则prototxt为:
layer {name: "eltwise_layer"bottom: "A"bottom: "B"top: "diff"type: "Eltwise"eltwise_param {operation: PROD}
}
这篇关于Caffe Prototxt 特殊层系列:Eltwise Layer的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!