Caffe2 - C++ API
A deep learning, cross platform ML framework
upsample_nearest_op.cc
1 
17 #include "upsample_nearest_op.h"
18 #ifdef CAFFE2_USE_MKLDNN
19 #include "caffe2/ideep/operators/operator_fallback_ideep.h"
20 #include "caffe2/ideep/utils/ideep_operator.h"
21 #endif
22 
23 namespace caffe2 {
24 #ifdef CAFFE2_USE_MKLDNN
25 REGISTER_IDEEP_OPERATOR(
26  UpsampleNearest,
27  IDEEPFallbackOp<UpsampleNearestOp<float, CPUContext>>);
28 #endif
29 
30 REGISTER_CPU_OPERATOR(UpsampleNearest, UpsampleNearestOp<float, CPUContext>);
31 REGISTER_CPU_OPERATOR(
32  UpsampleNearestGradient,
33  UpsampleNearestGradientOp<float, CPUContext>);
34 
35 OPERATOR_SCHEMA(UpsampleNearest)
36  .NumInputs(1)
37  .NumOutputs(1)
38  .SetDoc(R"DOC(
39 Nearest neighbor upsampling operation. Implementation taken from THCUNN.
40 )DOC")
41  .Arg(
42  "scale",
43  "(int) default 2; integer upsampling factor.")
44  .Input(
45  0,
46  "X",
47  "4D feature map input of shape (N, C, H, W).")
48  .Output(
49  0,
50  "Y",
51  "4D feature map of shape (N, C, scale * H, scale * W); Values are "
52  "neareast neighbor samples from X.");
53 
54 OPERATOR_SCHEMA(UpsampleNearestGradient)
55  .NumInputs(2)
56  .NumOutputs(1)
57  .Input(
58  0,
59  "X",
60  "See UpsampleNearest.")
61  .Input(
62  1,
63  "dY",
64  "Gradient of forward output 0 (Y).")
65  .Output(
66  0,
67  "dX",
68  "Gradient of forward input 0 (X).");
69 
71  using GradientMakerBase::GradientMakerBase;
72  vector<OperatorDef> GetGradientDefs() override {
73  return SingleGradientDef(
74  "UpsampleNearestGradient",
75  "",
76  vector<string>{I(0), GO(0)},
77  vector<string>{GI(0)});
78  }
79 };
80 
81 REGISTER_GRADIENT(UpsampleNearest, GetUpsampleNearestGradient);
82 
83 } // 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 ...