Caffe2 - C++ API
A deep learning, cross platform ML framework
loss_op.cc
1 
17 #include "caffe2/operators/loss_op.h"
18 
19 namespace caffe2 {
20 
21 REGISTER_CPU_OPERATOR(AveragedLoss, AveragedLoss<float, CPUContext>);
22 REGISTER_CPU_OPERATOR(AveragedLossGradient,
23  AveragedLossGradient<float, CPUContext>);
24 
25 OPERATOR_SCHEMA(AveragedLoss)
26  .NumInputs(1)
27  .NumOutputs(1)
28  .ScalarType(TensorProto::FLOAT)
29  .SetDoc(R"DOC(
30 AveragedLoss takes in a 1-D tensor as input and returns a single output float
31 value which represents the average of input data (average of the losses).
32 )DOC")
33  .Input(0, "input", "The input data as Tensor")
34  .Output(0, "output", "The output tensor of size 1 containing the averaged "
35  "value.");
36 
37 OPERATOR_SCHEMA(AveragedLossGradient).NumInputs(2).NumOutputs(1);
38 
40  using GradientMakerBase::GradientMakerBase;
41  vector<OperatorDef> GetGradientDefs() override {
42  return SingleGradientDef(
43  "AveragedLossGradient", "",
44  vector<string>{I(0), GO(0)},
45  vector<string>{GI(0)});
46  }
47 };
48 REGISTER_GRADIENT(AveragedLoss, GetAveragedLossGradient);
49 
50 } // namespace caffe2
Copyright (c) 2016-present, Facebook, Inc.
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 ...