Caffe2 - C++ API
A deep learning, cross platform ML framework
bbox_transform_op.h
1 // Copyright 2004-present Facebook. All Rights Reserved.
2 
3 #ifndef BBOX_TRANSFORM_OP_H_
4 #define BBOX_TRANSFORM_OP_H_
5 
6 #include "caffe2/core/context.h"
7 #include "caffe2/core/logging.h"
8 #include "caffe2/core/operator.h"
9 #include "caffe2/utils/math.h"
10 
11 C10_DECLARE_CAFFE2_OPERATOR(BBoxTransform)
12 
13 namespace caffe2 {
14 
15 template <typename T, class Context>
16 class BBoxTransformOp final : public Operator<Context> {
17  public:
18  template<class... Args>
19  explicit BBoxTransformOp(Args&&... args)
20  : Operator<Context>(std::forward<Args>(args)...),
21  weights_(this->template GetRepeatedArgument<T>(
22  "weights",
23  vector<T>{1.0f, 1.0f, 1.0f, 1.0f})),
24  apply_scale_(
25  this->template GetSingleArgument<bool>("apply_scale", true)),
26  rotated_(this->template GetSingleArgument<bool>("rotated", false)),
27  angle_bound_on_(
28  this->template GetSingleArgument<bool>("angle_bound_on", true)),
29  angle_bound_lo_(
30  this->template GetSingleArgument<int>("angle_bound_lo", -90)),
31  angle_bound_hi_(
32  this->template GetSingleArgument<int>("angle_bound_hi", 90)),
33  clip_angle_thresh_(
34  this->template GetSingleArgument<float>("clip_angle_thresh", 1.0)) {
35  CAFFE_ENFORCE_EQ(
36  weights_.size(),
37  4,
38  "weights size " + c10::to_string(weights_.size()) + "must be 4.");
39  }
40  USE_OPERATOR_CONTEXT_FUNCTIONS;
41 
42  bool RunOnDevice() override;
43 
44  protected:
45  // weights [wx, wy, ww, wh] to apply to the regression target
46  vector<T> weights_;
47  // Transform the boxes to the scaled image space after applying the bbox
48  // deltas.
49  // Set to false to match the detectron code, set to true for the keypoint
50  // model and for backward compatibility
51  bool apply_scale_{true};
52  // Set for RRPN case to handle rotated boxes. Inputs should be in format
53  // [ctr_x, ctr_y, width, height, angle (in degrees)].
54  bool rotated_{false};
55  // If set, for rotated boxes in RRPN, output angles are normalized to be
56  // within [angle_bound_lo, angle_bound_hi].
57  bool angle_bound_on_{true};
58  int angle_bound_lo_{-90};
59  int angle_bound_hi_{90};
60  // For RRPN, clip almost horizontal boxes within this threshold of
61  // tolerance for backward compatibility. Set to negative value for
62  // no clipping.
63  float clip_angle_thresh_{1.0};
64 };
65 
66 } // namespace caffe2
67 
68 #endif // BBOX_TRANSFORM_OP_H_
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13