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