Caffe2 - C++ API
A deep learning, cross platform ML framework
select_smooth_l1_loss_op.cc
1 
17 #include "select_smooth_l1_loss_op.h"
18 
19 namespace caffe2 {
20 
21 REGISTER_CPU_OPERATOR(
22  SelectSmoothL1Loss,
23  SelectSmoothL1LossOp<float, CPUContext>);
24 REGISTER_CPU_OPERATOR(
25  SelectSmoothL1LossGradient,
26  SelectSmoothL1LossGradientOp<float, CPUContext>);
27 
28 OPERATOR_SCHEMA(SelectSmoothL1Loss)
29  .NumInputs(4)
30  .NumOutputs(1)
31  .SetDoc(R"DOC(
32 RetinaNet specific op for computing Smooth L1 Loss at select locations in a 4D
33 tensor that encodes bounding box regression predictions.
34 )DOC")
35  .Arg(
36  "beta",
37  "(float) default 1.0; L2 to L1 transition point.")
38  .Arg(
39  "scale",
40  "(float) default 1.0; multiply the loss by this scale factor.")
41  .Input(
42  0,
43  "Y_hat",
44  "4D tensor of bounding box regression predictions with shape "
45  "(N, 4 * num_bbox_classes * num_anchors, H, W).")
46  .Input(
47  1,
48  "Y",
49  "2D tensor of labels shape (M, 4) for 4 contiguous channels starting "
50  "at each of the M locations selected by the locations input.")
51  .Input(
52  2,
53  "locations",
54  "2D tensor of shape (M, 4) that identifies M 'select' locations "
55  "encoded by the four colums: (n, c, y, x). The loss is computed on the "
56  "four contiguous channel locations [c, c + 3] (inclusive).")
57  .Input(
58  3,
59  "normalizer",
60  "Scalar; the loss is divided by max(1, normalizer).")
61  .Output(
62  0,
63  "loss",
64  "Scalar loss.");
65 
66 OPERATOR_SCHEMA(SelectSmoothL1LossGradient)
67  .NumInputs(5)
68  .NumOutputs(1)
69  .Input(
70  0,
71  "Y_hat",
72  "See SelectSmoothL1Loss.")
73  .Input(
74  1,
75  "Y",
76  "See SelectSmoothL1Loss.")
77  .Input(
78  2,
79  "locations",
80  "See SelectSmoothL1Loss.")
81  .Input(
82  3,
83  "normalizer",
84  "See SelectSmoothL1Loss.")
85  .Input(
86  4,
87  "d_loss",
88  "Gradient of forward output 0 (loss).")
89  .Output(
90  0,
91  "d_Y_hat",
92  "Gradient of forward input 0 (Y_hat).");
93 
95  using GradientMakerBase::GradientMakerBase;
96  vector<OperatorDef> GetGradientDefs() override {
97  return SingleGradientDef(
98  "SelectSmoothL1LossGradient",
99  "",
100  vector<string>{I(0), I(1), I(2), I(3), GO(0)},
101  vector<string>{GI(0)});
102  }
103 };
104 
105 REGISTER_GRADIENT(SelectSmoothL1Loss, GetSelectSmoothL1LossGradient);
106 
107 } // namespace caffe2
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13
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 ...