Caffe2 - C++ API
A deep learning, cross platform ML framework
loss_op.cc
1 #include "caffe2/operators/loss_op.h"
2 
3 namespace caffe2 {
4 
5 REGISTER_CPU_OPERATOR(AveragedLoss, AveragedLoss<float, CPUContext>);
6 REGISTER_CPU_OPERATOR(AveragedLossGradient,
7  AveragedLossGradient<float, CPUContext>);
8 
9 OPERATOR_SCHEMA(AveragedLoss)
10  .NumInputs(1)
11  .NumOutputs(1)
12  .ScalarType(TensorProto::FLOAT)
13  .SetDoc(R"DOC(
14 AveragedLoss takes in a 1-D tensor as input and returns a single output float
15 value which represents the average of input data (average of the losses).
16 )DOC")
17  .Input(0, "input", "The input data as Tensor")
18  .Output(0, "output", "The output tensor of size 1 containing the averaged "
19  "value.");
20 
21 OPERATOR_SCHEMA(AveragedLossGradient).NumInputs(2).NumOutputs(1);
22 
24  using GradientMakerBase::GradientMakerBase;
25  vector<OperatorDef> GetGradientDefs() override {
26  return SingleGradientDef(
27  "AveragedLossGradient", "",
28  vector<string>{I(0), GO(0)},
29  vector<string>{GI(0)});
30  }
31 };
32 REGISTER_GRADIENT(AveragedLoss, GetAveragedLossGradient);
33 
34 } // 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 ...