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 #include "fastdeploy/vision/common/processors/transform.h"
17 #include "fastdeploy/vision/common/result.h"
18 #include "fastdeploy/vision/detection/ppdet/multiclass_nms.h"
19 
20 namespace fastdeploy {
21 namespace vision {
22 namespace detection {
25 class FASTDEPLOY_DECL PaddleDetPostprocessor {
26  public:
28  // There may be no NMS config in the yaml file,
29  // so we need to give a initial value to multi_class_nms_.
30  multi_class_nms_.SetNMSOption(NMSOption());
31  }
32 
37  explicit PaddleDetPostprocessor(const std::string& arch) {
38  // Used to differentiate models
39  arch_ = arch;
40  // There may be no NMS config in the yaml file,
41  // so we need to give a initial value to multi_class_nms_.
42  multi_class_nms_.SetNMSOption(NMSOption());
43  }
44 
51  bool Run(const std::vector<FDTensor>& tensors,
52  std::vector<DetectionResult>* result);
53 
56  void ApplyNMS() { with_nms_ = false; }
57 
60  void SetNMSOption(const NMSOption& option) {
61  multi_class_nms_.SetNMSOption(option);
62  }
63 
64  // Set scale_factor_ value.This is only available for those model exported
65  // without nms.
66  void SetScaleFactor(const std::vector<float>& scale_factor_value) {
67  scale_factor_ = scale_factor_value;
68  }
69 
70  private:
71  std::vector<float> scale_factor_{0.0, 0.0};
72  std::vector<float> GetScaleFactor() { return scale_factor_; }
73 
74  // for model without nms.
75  bool with_nms_ = true;
76 
77  // Used to differentiate models
78  std::string arch_;
79 
80  PaddleMultiClassNMS multi_class_nms_{};
81 
82  // Process for General tensor without nms.
83  bool ProcessWithoutNMS(const std::vector<FDTensor>& tensors,
84  std::vector<DetectionResult>* results);
85 
86  // Process for General tensor with nms.
87  bool ProcessWithNMS(const std::vector<FDTensor>& tensors,
88  std::vector<DetectionResult>* results);
89 
90  // Process SOLOv2
91  bool ProcessSolov2(const std::vector<FDTensor>& tensors,
92  std::vector<DetectionResult>* results);
93 
94  // Process mask tensor for MaskRCNN
95  bool ProcessMask(const FDTensor& tensor,
96  std::vector<DetectionResult>* results);
97 };
98 
99 } // namespace detection
100 } // namespace vision
101 } // namespace fastdeploy
void SetNMSOption(const NMSOption &option)
Definition: postprocessor.h:60
FDTensor object used to represend data matrix.
Definition: fd_tensor.h:31
PaddleDetPostprocessor(const std::string &arch)
Create a preprocessor instance for PaddleDet serials model.
Definition: postprocessor.h:37
void ApplyNMS()
Definition: postprocessor.h:56
Postprocessor object for PaddleDet serials model.
Definition: postprocessor.h:25
Config for PaddleMultiClassNMS.
Definition: multiclass_nms.h:32
All C++ FastDeploy APIs are defined inside this namespace.
Definition: option.h:16