Modifying BatchedMatMul Prototxt
Do not directly copy the code samples in this section to your network model. Adjust the parameters to suit your use case. For example, the bottom and top parameters must match those in the corresponding network model, and the sequence of the bottom and top parameters is fixed.
The BatchedMatMul operator multiplies the two tensors: y = x1 * x2. (The number of x1 and x2 dimensions must be greater than 2 and less than or equal to 8.) To use this operator in a network model, modify its .prototxt file by referring to this section and then convert the model.
For details, see the caffe.proto file (${INSTALL_DIR}/include/proto). Add the declaration of the custom layer to the LayerParameter message. (The following custom layer has been declared in caffe.proto and you do not need to add it again.)
message LayerParameter {
...
optional BatchMatMulParameter batch_matmul_param = 235;
...
}
According to the caffe.proto file, the operator type and attributes are defined as follows:
message BatchMatMulParameter{
optional bool adj_x1 = 1 [default = false];
optional bool adj_x2 = 2 [default = false];
}
The BatchedMatMul operator has two inputs and one output as described in Supported Caffe Operators. An example of the constructed operator code is as follows.
layer {
name: "batchmatmul"
type: "BatchedMatMul"
bottom: "matmul_data_1"
bottom: "matmul_data_2"
top: "batchmatmul_1"
batch_matmul_param {
adj_x1:false
adj_x2:true
}
For details about the parameters, see Supported Caffe Operators.