Caffe2 - C++ API
A deep learning, cross platform ML framework
box_with_nms_limit_op.h
1 // Copyright 2004-present Facebook. All Rights Reserved.
2 
3 #ifndef BOX_WITH_NMS_AND_LIMIT_OP_H_
4 #define BOX_WITH_NMS_AND_LIMIT_OP_H_
5 
6 #include "caffe2/core/context.h"
7 #include "caffe2/core/operator.h"
8 
9 namespace caffe2 {
10 
11 // C++ implementation of function insert_box_results_with_nms_and_limit()
12 template <class Context>
13 class BoxWithNMSLimitOp final : public Operator<Context> {
14  public:
15  USE_OPERATOR_CONTEXT_FUNCTIONS;
16  template <class... Args>
17  explicit BoxWithNMSLimitOp(Args&&... args)
18  : Operator<Context>(std::forward<Args>(args)...),
19  score_thres_(
20  this->template GetSingleArgument<float>("score_thresh", 0.05)),
21  nms_thres_(this->template GetSingleArgument<float>("nms", 0.3)),
22  detections_per_im_(
23  this->template GetSingleArgument<int>("detections_per_im", 100)),
24  soft_nms_enabled_(
25  this->template GetSingleArgument<bool>("soft_nms_enabled", false)),
26  soft_nms_method_str_(this->template GetSingleArgument<std::string>(
27  "soft_nms_method",
28  "linear")),
29  soft_nms_sigma_(
30  this->template GetSingleArgument<float>("soft_nms_sigma", 0.5)),
31  soft_nms_min_score_thres_(this->template GetSingleArgument<float>(
32  "soft_nms_min_score_thres",
33  0.001)),
34  rotated_(this->template GetSingleArgument<bool>("rotated", false)) {
35  CAFFE_ENFORCE(
36  soft_nms_method_str_ == "linear" || soft_nms_method_str_ == "gaussian",
37  "Unexpected soft_nms_method");
38  soft_nms_method_ = (soft_nms_method_str_ == "linear") ? 1 : 2;
39  }
40 
41  ~BoxWithNMSLimitOp() {}
42 
43  bool RunOnDevice() override;
44 
45  protected:
46  // TEST.SCORE_THRESH
47  float score_thres_ = 0.05;
48  // TEST.NMS
49  float nms_thres_ = 0.3;
50  // TEST.DETECTIONS_PER_IM
51  int detections_per_im_ = 100;
52  // TEST.SOFT_NMS.ENABLED
53  bool soft_nms_enabled_ = false;
54  // TEST.SOFT_NMS.METHOD
55  std::string soft_nms_method_str_ = "linear";
56  unsigned int soft_nms_method_ = 1; // linear
57  // TEST.SOFT_NMS.SIGMA
58  float soft_nms_sigma_ = 0.5;
59  // Lower-bound on updated scores to discard boxes
60  float soft_nms_min_score_thres_ = 0.001;
61  // Set for RRPN case to handle rotated boxes. Inputs should be in format
62  // [ctr_x, ctr_y, width, height, angle (in degrees)].
63  bool rotated_{false};
64 };
65 
66 } // namespace caffe2
67 #endif // BOX_WITH_NMS_AND_LIMIT_OP_H_
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13