Caffe2 - C++ API
A deep learning, cross platform ML framework
affine_channel_op.cc
1 
17 #include "affine_channel_op.h"
18 
19 namespace caffe2 {
20 
21 REGISTER_CPU_OPERATOR(AffineChannel,
22  AffineChannelOp<float, CPUContext>);
23 REGISTER_CPU_OPERATOR(AffineChannelGradient,
24  AffineChannelGradientOp<float, CPUContext>);
25 
26 OPERATOR_SCHEMA(AffineChannel)
27  .NumInputs(3)
28  .NumOutputs(1)
29  .AllowInplace({{0, 0}})
30  .SetDoc(R"DOC(
31 Applies a separate affine transformation to each channel of the input. Useful
32 for replacing spatial batch norm with its equivalent fixed transformation.
33 )DOC")
34  .Input(
35  0,
36  "X",
37  "4D feature map input of shape (N, C, H, W).")
38  .Input(
39  1,
40  "scale",
41  "1D input of shape (C); the c-th element is the scale factor of the "
42  "affine transformation for the c-th channel of the input.")
43  .Input(
44  2,
45  "bias",
46  "1D input of shape (C); the c-th element is the bias of the affine "
47  "transformation for the c-th channel of the input.")
48  .Output(
49  0,
50  "Y",
51  "4D output of shape (N, C, H, W).");
52 
53 OPERATOR_SCHEMA(AffineChannelGradient)
54  .NumInputs(2)
55  .NumOutputs(1)
56  .AllowInplace({{1, 0}})
57  .Input(
58  0,
59  "scale",
60  "See AffineChannel.")
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  "AffineChannelGradient", "",
75  vector<string>{I(1), GO(0)},
76  vector<string>{GI(0)});
77  }
78 };
79 
80 REGISTER_GRADIENT(AffineChannel, GetAffineChannelGradient);
81 
82 } // 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 ...