Caffe2 - C++ API
A deep learning, cross platform ML framework
spatial_narrow_as_op.cc
1 
17 #include "spatial_narrow_as_op.h"
18 
19 namespace caffe2 {
20 
21 REGISTER_CPU_OPERATOR(SpatialNarrowAs, SpatialNarrowAsOp<CPUContext>);
22 REGISTER_CPU_OPERATOR(
23  SpatialNarrowAsGradient,
24  SpatialNarrowAsGradientOp<CPUContext>);
25 
26 OPERATOR_SCHEMA(SpatialNarrowAs)
27  .NumInputs(2)
28  .NumOutputs(1)
29  .SetDoc(R"DOC(
30 Reduces ("narrows") the spatial extent of A to that of B by removing rows and
31 columns from the bottom and right.
32 )DOC")
33  .Input(
34  0,
35  "A",
36  "3D or 4D input of shape (N, H0, W0) or (N, C, H0, W0).")
37  .Input(
38  1,
39  "B",
40  "3D or 4D input of shape (N, H1, W1) or (N, C, H1, W1), where H1 <= H0 "
41  "and W1 <= W0.")
42  .Output(
43  0,
44  "C",
45  "Sub window of A containing rows [0, H1 - 1] (inclusive) and columns "
46  "[0, W1 - 1] (inclusive).");
47 
48 OPERATOR_SCHEMA(SpatialNarrowAsGradient)
49  .NumInputs(3)
50  .NumOutputs(1)
51  .Input(
52  0,
53  "A",
54  "See SpatialNarrowAs.")
55  .Input(
56  1,
57  "B",
58  "See SpatialNarrowAs.")
59  .Input(
60  2,
61  "dC",
62  "Gradient of forward output 0 (C).")
63  .Output(
64  0,
65  "dA",
66  "Gradient of forward input 0 (A)");
67 
69  using GradientMakerBase::GradientMakerBase;
70  vector<OperatorDef> GetGradientDefs() override {
71  return SingleGradientDef(
72  "SpatialNarrowAsGradient", "",
73  vector<string>{I(0), I(1), GO(0)},
74  vector<string>{GI(0)});
75  }
76 };
77 REGISTER_GRADIENT(SpatialNarrowAs, SpatialNarrowAsGradient);
78 
79 } // 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 ...