Reputation: 2133
I am trying to implement the Eltwise layer in PyCaffe to sum 2 inputs.
My goal is to get this in prototext:
layer {
name: "eltwise_sum"
type: "Eltwise"
bottom: "v1"
bottom: "v2"
top: "v1_v2_sum"
eltwise_param { operation: SUM }
}
I couldn't find any documentation or even google examples on how to do this in PyCaffe.
net.v1_v2_sum = caffe.layers.Eltwise( net.v1,
net.v2,
name='eltwise_sum',
param ={'operation': 'SUM'}
)
However, I keep getting an error. I suspect this is due to not specifying the sum operation correctly, but I cant find any documentation on how to do this right?
Thanks,
Upvotes: 0
Views: 1960
Reputation: 2133
Ok, so apparently there is an integer corresponding to each operation Eltwise performs, and 1 corresponds to sum, so the correct implementation is:
net.v1_v2_sum = caffe.layers.Eltwise( net.v1,
net.v2,
name='eltwise_sum',
operation = 1
)
I figured this out by trial-and-error. See Parag S. Chandakkar's answer for more info on how to understand this from their git code.
Upvotes: 0
Reputation: 9075
The answer lies in caffe.proto. Each parameter that you include in a layer is listed in that file. For Eltwise
layer, the parameters are operation
, coeff
, stable_prod_grad
. The parameter operation
takes 3 values 0
, 1
or 2
whose mappings are defined by an enum EltwiseOp
. As far as the parameter name
is concerned, you will find it in LayerParameter
. I couldn't find any documentation on this. It's just something you learn along the way. I hope this clears your doubts.
Upvotes: 1