1 #include "caffe2/operators/loss_op.h" 5 REGISTER_CPU_OPERATOR(AveragedLoss, AveragedLoss<float, CPUContext>);
6 REGISTER_CPU_OPERATOR(AveragedLossGradient,
7 AveragedLossGradient<float, CPUContext>);
9 OPERATOR_SCHEMA(AveragedLoss)
12 .ScalarType(TensorProto::FLOAT)
14 The *AveragedLoss* op takes a single 1-D input tensor *input* and returns a single output float value *output*. The output represents the average of the values in *input*. This op is commonly used for averaging losses, hence the name, however it does not exclusively operate on losses. 18 - https://github.com/caffe2/caffe2/blob/master/caffe2/operators/loss_op.h 19 - https://github.com/caffe2/caffe2/blob/master/caffe2/operators/loss_op.cc 24 <summary> <b>Example</b> </summary> 30 workspace.ResetWorkspace() 32 op = core.CreateOperator( 38 workspace.FeedBlob("input", np.array([8, 10, 12]).astype(np.float32)) 39 print("input:\n", workspace.FetchBlob("input")) 41 workspace.RunOperatorOnce(op) 42 print("output: \n", workspace.FetchBlob("output")) 61 .Input(0, "input",
"The input data as Tensor")
62 .Output(0,
"output",
"The output tensor of size 1 containing the averaged value.");
64 OPERATOR_SCHEMA(AveragedLossGradient).NumInputs(2).NumOutputs(1);
67 using GradientMakerBase::GradientMakerBase;
68 vector<OperatorDef> GetGradientDefs()
override {
70 "AveragedLossGradient",
"",
71 vector<string>{I(0), GO(0)},
72 vector<string>{GI(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 ...