FastDeploy  latest
Fast & Easy to Deploy!
multiclass_nms.h
1 // Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 #include <map>
17 #include <string>
18 #include <vector>
19 
20 namespace fastdeploy {
21 namespace vision {
22 namespace detection {
32 struct NMSOption{
33  NMSOption() = default;
34  int64_t background_label = -1;
35  int64_t keep_top_k = 100;
36  float nms_eta = 1.0;
37  float nms_threshold = 0.5;
38  int64_t nms_top_k = 1000;
39  bool normalized = true;
40  float score_threshold = 0.3;
41 };
42 
43 struct PaddleMultiClassNMS {
44  int64_t background_label = -1;
45  int64_t keep_top_k = -1;
46  float nms_eta;
47  float nms_threshold = 0.7;
48  int64_t nms_top_k;
49  bool normalized;
50  float score_threshold;
51 
52  std::vector<int32_t> out_num_rois_data;
53  std::vector<int32_t> out_index_data;
54  std::vector<float> out_box_data;
55  void FastNMS(const float* boxes, const float* scores, const int& num_boxes,
56  std::vector<int>* keep_indices);
57  int NMSForEachSample(const float* boxes, const float* scores, int num_boxes,
58  int num_classes,
59  std::map<int, std::vector<int>>* keep_indices);
60  void Compute(const float* boxes, const float* scores,
61  const std::vector<int64_t>& boxes_dim,
62  const std::vector<int64_t>& scores_dim);
63 
64  void SetNMSOption(const struct NMSOption &nms_option){
65  background_label = nms_option.background_label;
66  keep_top_k = nms_option.keep_top_k;
67  nms_eta = nms_option.nms_eta;
68  nms_threshold = nms_option.nms_threshold;
69  nms_top_k = nms_option.nms_top_k;
70  normalized = nms_option.normalized;
71  score_threshold = nms_option.score_threshold;
72  }
73 };
74 } // namespace detection
75 } // namespace vision
76 } // namespace fastdeploy
Config for PaddleMultiClassNMS.
Definition: multiclass_nms.h:32
All C++ FastDeploy APIs are defined inside this namespace.
Definition: option.h:16