Help Center> Atlas 500 Application> TE Custom Operator Development Guide> caffe.proto File Operator Definition (Optional)
Updated on 2022-03-13 GMT+08:00

caffe.proto File Operator Definition (Optional)

If a model under the Caffe open source framework is used, define the caffe.proto file by referring to the description in this section. If a model under the TensorFlow open-source framework is used, skip this section.

After the operator is developed, add the definition of the custom operator to the built-in caffe.proto file of the DDK. If the definition of this operator already exists in the built-in caffe.proto file, skip this section.

If there are multiple unsupported custom operators in the same model, add related operator definitions at a time by referring to this section. During the implementation of operator plug-ins, related operator parameters are read from the caffe.proto file based on the operator name, and then the data structures of operators are converted into those supported by the offline model supported by the Ascend AI processor.

The built-in caffe.proto file of the DDK is stored in $HOME/tools/che/ddk/ddk/include/inc/custom/proto/caffe/caffe.proto. You can modify the file and add the definition of the custom operator.

The following describes how to add the definition of the reduction operator (the definition of the reduction operator has been added to the built-in caffe.proto file of the DDK):

  1. Add the definition of the reduction operator to LayerParameter.

    Add the definition of the reduction layer to LayerParameter and set its ID.

    message LayerParameter {
    ...
    optional ReductionParameter reduction_param = 136;   // The ID must be unique.
    ...
    }

  2. Add the parameter definition of the reduction layer to the caffe.proto file.

    message ReductionParameter {
      enum ReductionOp {          // Operation types supported by the operator
        SUM = 1;                           // Sums the values of all the axes on which the reduce operation is performed.
        ASUM = 2;                        // Sum the calculated absolute values of all axes on which the reduce operation is performed.
        SUMSQ = 3;                      // Sum the squared values of all axes on which the reduce operation is performed.
        MEAN = 4;                        // Average the values of all axes on which the reduce operation is performed.
      }
      optional ReductionOp operation = 1 [default = SUM];   // Defines the operation of the operator.
      optional int32 axis = 2 [default = 0];                                // Defines the axis for which the reduce operation is to be performed.
      optional float coeff = 3 [default = 1.0]; // coefficient for output  // Scalar, indicating the scaling multiple of the result
    }