Caffe2 - C++ API
A deep learning, cross platform ML framework
piecewise_linear_transform_op.cc
1 #include "caffe2/operators/piecewise_linear_transform_op.h"
2 
3 namespace caffe2 {
4 
5 REGISTER_CPU_OPERATOR(
6  PiecewiseLinearTransform,
7  PiecewiseLinearTransformOp<float, CPUContext>);
8 
9 OPERATOR_SCHEMA(PiecewiseLinearTransform)
10  .NumInputs(1, 4)
11  .NumOutputs(1)
12  .SetDoc(R"DOC(
13 PiecewiseLinearTransform takes inputs -- predictions, a 2-D or 1-D tensor
14 (Tensor) of size (batch_size x prediction_dimensions). The piecewise
15 linear functions are stored in bounds, slopes and intercepts. The output tensor
16 has the same shape of input `predictions` and contains the predictions
17 transformed by the piecewise linear functions. Each column of predictions has
18 its own piecewise linear transformation functions. Therefore the size of
19 piecewise function parameters are pieces x prediction_dimensions, except for
20 binary predictions where only the positive prediction needs them. Note that in
21 each piece, low bound is excluded while high bound is included. Also the
22 piecewise linear function must be continuous.
23 
24 Notes
25 - If the input is binary predictions (Nx2 or Nx1 tensor), set the binary arg
26 to true so that one group of piecewise linear functions is needed (see
27 details below).
28 - The transform parameters (bounds, slopes, intercepts) can be passed either
29 through args or through input blobs.
30 - If we have multiple groups of piecewise linear functions, each group has the
31 same number of pieces.
32 - If a prediction is out of the bounds, it is capped to the smallest or largest
33 bound.
34 )DOC")
35  .Arg(
36  "bounds",
37  "1-D vector of size (prediction_dimensions x (pieces+1)) contain the "
38  "upper bounds of each piece of linear function. One special case is "
39  "the first bound is the lower bound of whole piecewise function and we "
40  "treat it the same as the left most functions. (bounds, slopes, "
41  "intercepts) can be passed through either arg or input blobs.")
42  .Arg(
43  "slopes",
44  "1-D vector of size (prediction_dimensions x pieces) containing the "
45  "slopes of linear function")
46  .Arg(
47  "intercepts",
48  "1-D vector of size (prediction_dimensions x pieces) containing the "
49  "intercepts of linear function")
50  .Arg(
51  "binary",
52  "If set true, we assume the input is a Nx1 or Nx2 tensor. If it is Nx1 "
53  "tensor, it is positive predictions. If the input is Nx2 tensor, its "
54  "first column is negative predictions and second column is positive "
55  "and negative + positive = 1. We just need one group of piecewise "
56  "linear functions for the positive predictions.")
57  .Input(
58  0,
59  "predictions",
60  "2-D tensor (Tensor) of size "
61  "(num_batches x num_classes) containing scores")
62  .Input(
63  1,
64  "bounds (optional)",
65  "See bounds in Arg. (bounds, slopes, intercepts) can be passed through "
66  "either arg or input blobs.")
67  .Input(
68  2,
69  "slopes (optional)",
70  "See slopes in Arg. (bounds, slopes, intercepts) can be passed through "
71  "either arg or input blobs.")
72  .Input(
73  3,
74  "intercepts (optional)",
75  "See intercepts in Arg. (bounds, slopes, intercepts) can be passed "
76  "through either arg or input blobs.")
77  .Output(
78  0,
79  "transforms",
80  "2-D tensor (Tensor) of size (num_batches x num_classes) "
81  "containing transformed predictions");
82 
83 SHOULD_NOT_DO_GRADIENT(PiecewiseLinearTransform);
84 } // namespace caffe2
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13