FastDeploy  latest
Fast & Easy to Deploy!
postprocessor.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 
17 #include "fastdeploy/vision/common/processors/transform.h"
18 #include "fastdeploy/vision/common/result.h"
19 #include "fastdeploy/vision/detection/contrib/rknpu2/utils.h"
20 #include <array>
21 namespace fastdeploy {
22 namespace vision {
23 namespace detection {
26 class FASTDEPLOY_DECL RKYOLOPostprocessor {
27  public:
31 
39  bool Run(const std::vector<FDTensor>& tensors,
40  std::vector<DetectionResult>* results);
41 
43  void SetNMSThreshold(float nms_threshold) {
44  nms_threshold_ = nms_threshold;
45  }
46 
48  void SetConfThreshold(float conf_threshold) {
49  conf_threshold_ = conf_threshold;
50  }
51 
53  float GetConfThreshold() const { return conf_threshold_; }
54 
56  float GetNMSThreshold() const { return nms_threshold_; }
57 
59  void SetHeightAndWeight(int height, int width) {
60  height_ = height;
61  width_ = width;
62  }
63 
65  void SetPadHWValues(const std::vector<std::vector<int>>& pad_hw_values) {
66  pad_hw_values_ = pad_hw_values;
67  }
68 
70  void SetScale(const std::vector<float>& scale) { scale_ = scale; }
71 
73  void SetAnchor(const std::vector<int>& anchors, int anchor_per_branch) {
74  anchors_ = anchors;
75  anchor_per_branch_ = anchor_per_branch;
76  }
77 
79  void SetClassNum(int num) {
80  obj_class_num_ = num;
81  prob_box_size_ = obj_class_num_ + 5;
82  }
84  int GetClassNum() {
85  return obj_class_num_;
86  }
87 
88  private:
89  std::vector<int> anchors_ = {10, 13, 16, 30, 33, 23, 30, 61, 62,
90  45, 59, 119, 116, 90, 156, 198, 373, 326};
91  int strides_[3] = {8, 16, 32};
92  int height_ = 0;
93  int width_ = 0;
94  int anchor_per_branch_ = 0;
95 
96  int ProcessFP16(float* input, int* anchor, int grid_h, int grid_w, int stride,
97  std::vector<float>& boxes, std::vector<float>& boxScores,
98  std::vector<int>& classId, float threshold);
99  // Model
100  int QuickSortIndiceInverse(std::vector<float>& input, int left, int right,
101  std::vector<int>& indices);
102 
103  // post_process values
104  std::vector<std::vector<int>> pad_hw_values_;
105  std::vector<float> scale_;
106  float nms_threshold_ = 0.45;
107  float conf_threshold_ = 0.25;
108  int prob_box_size_ = 85;
109  int obj_class_num_ = 80;
110  int obj_num_bbox_max_size = 200;
111 };
112 
113 } // namespace detection
114 } // namespace vision
115 } // namespace fastdeploy
Postprocessor object for YOLOv5 serials model.
Definition: postprocessor.h:26
void SetAnchor(const std::vector< int > &anchors, int anchor_per_branch)
Set Anchor.
Definition: postprocessor.h:73
void SetClassNum(int num)
Set the number of class.
Definition: postprocessor.h:79
void SetConfThreshold(float conf_threshold)
Set conf_threshold, default 0.25.
Definition: postprocessor.h:48
void SetPadHWValues(const std::vector< std::vector< int >> &pad_hw_values)
Set pad_hw_values.
Definition: postprocessor.h:65
void SetNMSThreshold(float nms_threshold)
Set nms_threshold, default 0.45.
Definition: postprocessor.h:43
void SetScale(const std::vector< float > &scale)
Set scale.
Definition: postprocessor.h:70
float GetNMSThreshold() const
Get nms_threshold, default 0.45.
Definition: postprocessor.h:56
float GetConfThreshold() const
Get conf_threshold, default 0.25.
Definition: postprocessor.h:53
int GetClassNum()
Get the number of class.
Definition: postprocessor.h:84
All C++ FastDeploy APIs are defined inside this namespace.
Definition: option.h:16
void SetHeightAndWeight(int height, int width)
Set height and weight.
Definition: postprocessor.h:59