1 #include "caffe2/operators/mean_op.h" 5 REGISTER_CPU_OPERATOR(Mean, MeanOp<CPUContext>);
6 REGISTER_CPU_OPERATOR(MeanGradient, MeanGradientOp<CPUContext>);
11 .IdenticalTypeAndShapeOfInput(0)
12 .AllowInplace({{0, 0}})
14 Element-wise mean of an arbitrary number of input tensors. This operation can be 15 performed in-place, by using the first input blob as the output blob. All inputs 16 must have the same shape and data type, and the output will have the same shape 20 - https://github.com/pytorch/pytorch/blob/master/caffe2/operators/mean_op.cc 24 <summary> <b>Example</b> </summary> 30 workspace.ResetWorkspace() 32 op = core.CreateOperator( 38 workspace.FeedBlob("X", (np.random.rand(3,3)).astype(np.float32)) 39 workspace.FeedBlob("Y", (np.random.rand(3,3)).astype(np.float32)) 40 workspace.FeedBlob("Z", (np.random.rand(3,3)).astype(np.float32)) 41 print("X:", workspace.FetchBlob("X")) 42 print("Y:", workspace.FetchBlob("Y")) 43 print("Z:", workspace.FetchBlob("Z")) 44 workspace.RunOperatorOnce(op) 45 print("Mean:", workspace.FetchBlob("X")) 54 [[0.6035237 0.5305746 0.6298913 ] 55 [0.9169737 0.01280353 0.16286302] 56 [0.6017664 0.9946255 0.05128575]] 58 [[0.07544111 0.45371833 0.08460239] 59 [0.9708728 0.7422064 0.7933344 ] 60 [0.97671497 0.3411384 0.73818344]] 62 [[0.08837954 0.90187573 0.46734726] 63 [0.6308827 0.8719029 0.39888734] 64 [0.90059936 0.92883426 0.5695987 ]] 66 [[0.25578147 0.6287229 0.39394698] 67 [0.8395764 0.5423043 0.45169494] 68 [0.8263602 0.75486606 0.45302266]] 75 .Input(0, "X, Y, ...",
"*(type: Tensor`<Ord>`)* List of input tensors with the same shape.")
76 .Output(0,
"M",
"*(type: Tensor`<Ord>`)* Output tensor with the same dimensions as inputs. Contains " 77 "the mean values of the input tensors calculated element-wise.");
80 using GradientMakerBase::GradientMakerBase;
81 vector<OperatorDef> GetGradientDefs()
override {
82 auto outputs = std::vector<string>();
83 for (
int i = 0; i < def_.input_size(); i++) {
84 outputs.push_back(GI(i));
87 "MeanGradient",
"", std::vector<string>{GO(0)}, outputs);
93 OPERATOR_SCHEMA(MeanGradient)
95 .NumOutputs(1, INT_MAX)
96 .AllowInplace({{0, 0}});
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 ...