Caffe2 - C++ API
A deep learning, cross platform ML framework
ps_roi_pool_op.cc
1 
17 #include "ps_roi_pool_op.h"
18 
19 namespace caffe2 {
20 
21 REGISTER_CPU_OPERATOR(PSRoIPool, PSRoIPoolOp<float, CPUContext>);
22 REGISTER_CPU_OPERATOR(
23  PSRoIPoolGradient,
24  PSRoIPoolGradientOp<float, CPUContext>);
25 
26 OPERATOR_SCHEMA(PSRoIPool)
27  .NumInputs(2)
28  .NumOutputs(2)
29  .SetDoc(R"DOC(
30 Position Sensitive Region of Interest Pooling as used in R-FCN.
31 )DOC")
32  .Arg(
33  "spatial_scale",
34  "(float) default 1.0; Spatial scale of the input feature map X "
35  "relative to the input image. E.g., 0.0625 if X has a stride of 16 "
36  "w.r.t. the input image.")
37  .Arg(
38  "group_size",
39  "(int) default 1; pooled_h = pooled_w = group_size where pooled_{h,w} "
40  "is the pooled output Y's height and width, respectively.")
41  .Arg(
42  "output_dim",
43  "(int) default 1; number of channels in the pooled output, which might "
44  "be the number of classes is used for classification or 4 if used for "
45  "class agnostic bounding box regression.")
46  .Input(
47  0,
48  "X",
49  "4D position sensitive feature map input of shape (N, C, H, W), where "
50  "C = group_size**2 * output_dim.")
51  .Input(
52  1,
53  "RoIs",
54  "2D input of shape (R, 5) specifying R RoIs with five columns "
55  "representing: batch index in [0, N - 1], x1, y1, x2, y2. The RoI "
56  "coordinates are in the coordinate system of the input image.")
57  .Output(
58  0,
59  "Y",
60  "4D output of shape (R, output_dim, pooled_h, pooled_w). The r-th "
61  "batch element is a pooled feature map cooresponding to the r-th RoI.")
62  .Output(
63  1,
64  "argmaxes",
65  "4D output of shape (R, output_dim, pooled_h, pooled_w). Same as Y, "
66  "except it records the argmax indices rather than the max pooled "
67  "values.");
68 
69 OPERATOR_SCHEMA(PSRoIPoolGradient)
70  .NumInputs(4)
71  .NumOutputs(1)
72  .Input(
73  0,
74  "X",
75  "See PSRoIPool.")
76  .Input(
77  1,
78  "RoIs",
79  "See PSRoIPool.")
80  .Input(
81  2,
82  "argmaxes",
83  "See PSRoIPool.")
84  .Input(
85  3,
86  "dY",
87  "Gradient of forward output 0 (Y)")
88  .Output(
89  0,
90  "dX",
91  "Gradient of forward input 0 (X)");
92 
93 class GetPSRoIPoolGradient : public GradientMakerBase {
94  using GradientMakerBase::GradientMakerBase;
95  vector<OperatorDef> GetGradientDefs() override {
96  return SingleGradientDef(
97  "PSRoIPoolGradient",
98  "",
99  vector<string>{I(0), I(1), O(1), GO(0)},
100  vector<string>{GI(0)});
101  }
102 };
103 
104 REGISTER_GRADIENT(PSRoIPool, GetPSRoIPoolGradient);
105 
106 } // namespace caffe2
Copyright (c) 2016-present, Facebook, Inc.