Caffe2 - C++ API
A deep learning, cross platform ML framework
group_spatial_softmax_op.cc
1 
17 #include "group_spatial_softmax_op.h"
18 #include "caffe2/operators/softmax_shared.h"
19 
20 namespace caffe2 {
21 
22 REGISTER_CPU_OPERATOR(
23  GroupSpatialSoftmax,
24  GroupSpatialSoftmaxOp<float, CPUContext>);
25 REGISTER_CPU_OPERATOR(
26  GroupSpatialSoftmaxGradient,
27  GroupSpatialSoftmaxGradientOp<float, CPUContext>);
28 
29 OPERATOR_SCHEMA(GroupSpatialSoftmax)
30  .NumInputs(1)
31  .NumOutputs(1)
32  .SetDoc(R"DOC(
33 RetinaNet specific form of spatial softmax.
34 
35 The input is assumed to be unnormalized scores (sometimes called 'logits')
36 arranged in a 4D tensor with shape (N, C, H, W), where N is the number of
37 elements in the batch, H and W are the height and width, and C = num_anchors *
38 num_classes defines num_anchors 'groups' of softmax inputs, each of length
39 num_classes. The softmax is applied to each group independently.
40 
41 See: https://arxiv.org/abs/1708.02002 for details.
42 )DOC")
43  .Arg(
44  "num_classes",
45  "(int) default 81; number of classes in each softmax group.")
46  .Input(
47  0,
48  "scores",
49  "4D tensor of softmax inputs (called 'scores' or 'logits') with shape "
50  "(N, C, H, W), where C = num_anchors * num_classes defines num_anchors "
51  "groups of contiguous num_classes softmax inputs.")
52  .Output(
53  0,
54  "probabilities",
55  "4D tensor of softmax probabilities with shape (N, C, H, W), where "
56  "C = num_anchors * num_classes, and softmax was applied to each of the "
57  "num_anchors groups; within a group the num_classes values sum to 1.");
58 
59 OPERATOR_SCHEMA(GroupSpatialSoftmaxGradient)
60  .NumInputs(2)
61  .NumOutputs(1)
62  .Input(
63  0,
64  "scores",
65  "See GroupSpatialSoftmax")
66  .Input(
67  1,
68  "d_probabilities",
69  "Gradient of forward output 0 (probabilities).")
70  .Output(
71  0,
72  "d_scores",
73  "Gradient of forward input 0 (scores).");
74 
76  using GradientMakerBase::GradientMakerBase;
77  vector<OperatorDef> GetGradientDefs() override {
78  return SingleGradientDef(
79  "GroupSpatialSoftmaxGradient",
80  "",
81  vector<string>{O(0), GO(0)},
82  vector<string>{GI(0)});
83  }
84 };
85 
86 REGISTER_GRADIENT(GroupSpatialSoftmax, GetGroupSpatialSoftmaxGradient);
87 } // 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 ...