Caffe2 - C++ API
A deep learning, cross platform ML framework
mean_op.cc
1 #include "caffe2/operators/mean_op.h"
2 
3 namespace caffe2 {
4 
5 REGISTER_CPU_OPERATOR(Mean, MeanOp<CPUContext>);
6 REGISTER_CPU_OPERATOR(MeanGradient, MeanGradientOp<CPUContext>);
7 
8 OPERATOR_SCHEMA(Mean)
9  .NumInputs(1, INT_MAX)
10  .NumOutputs(1)
11  .IdenticalTypeAndShapeOfInput(0)
12  .AllowInplace({{0, 0}})
13  .SetDoc(R"DOC(
14 Element-wise mean of each of the input tensors. The first input tensor can be
15 used in-place as the output tensor, in which case the mean will be done in
16 place and results will be accumulated in input0. All inputs and outputs must
17 have the same shape and data type.
18 )DOC")
19  .Input(0, "data_0", "First of the input tensors. Can be inplace.")
20  .Output(0, "mean", "Output tensor. Same dimension as inputs.");
21 
22 class GetMeanGradient : public GradientMakerBase {
23  using GradientMakerBase::GradientMakerBase;
24  vector<OperatorDef> GetGradientDefs() override {
25  auto outputs = std::vector<string>();
26  for (int i = 0; i < def_.input_size(); i++) {
27  outputs.push_back(GI(i));
28  }
29  return SingleGradientDef(
30  "MeanGradient", "", std::vector<string>{GO(0)}, outputs);
31  }
32 };
33 
34 REGISTER_GRADIENT(Mean, GetMeanGradient);
35 
36 OPERATOR_SCHEMA(MeanGradient)
37  .NumInputs(1)
38  .NumOutputs(1, INT_MAX)
39  .AllowInplace({{0, 0}});
40 
41 } // namespace caffe2
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
static vector< OperatorDef > SingleGradientDef(const Args &...args)
a helper function to allow one to create one single operator def, which is usually the case for many ...