FastDeploy  latest
Fast & Easy to Deploy!
yolov6.h
1 // Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. //NOLINT
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/fastdeploy_model.h"
18 #include "fastdeploy/vision/common/processors/transform.h"
19 #include "fastdeploy/vision/common/result.h"
20 
21 namespace fastdeploy {
22 
23 namespace vision {
24 
25 namespace detection {
28 class FASTDEPLOY_DECL YOLOv6 : public FastDeployModel {
29  public:
37  YOLOv6(const std::string& model_file, const std::string& params_file = "",
38  const RuntimeOption& custom_option = RuntimeOption(),
39  const ModelFormat& model_format = ModelFormat::ONNX);
40 
41  ~YOLOv6();
42 
43  std::string ModelName() const { return "YOLOv6"; }
52  virtual bool Predict(cv::Mat* im, DetectionResult* result,
53  float conf_threshold = 0.25,
54  float nms_iou_threshold = 0.5);
55 
56 
57  void UseCudaPreprocessing(int max_img_size = 3840 * 2160);
58 
62  std::vector<int> size;
63  // padding value, size should be the same as channels
64 
65  std::vector<float> padding_value;
66  // only pad to the minimum rectange which height and width is times of stride
67  bool is_mini_pad;
68  // while is_mini_pad = false and is_no_pad = true,
69  // will resize the image to the set size
70  bool is_no_pad;
71  // if is_scale_up is false, the input image only can be zoom out,
72  // the maximum resize scale cannot exceed 1.0
73  bool is_scale_up;
74  // padding stride, for is_mini_pad
75  int stride;
76  // for offseting the boxes by classes when using NMS,
77  // default 4096 in meituan/YOLOv6
78  float max_wh;
79 
80  private:
81  bool Initialize();
82 
83  bool Preprocess(Mat* mat, FDTensor* outputs,
84  std::map<std::string, std::array<float, 2>>* im_info);
85 
86  bool CudaPreprocess(Mat* mat, FDTensor* output,
87  std::map<std::string, std::array<float, 2>>* im_info);
88 
89  bool Postprocess(FDTensor& infer_result, DetectionResult* result,
90  const std::map<std::string, std::array<float, 2>>& im_info,
91  float conf_threshold, float nms_iou_threshold);
92 
93  bool IsDynamicInput() const { return is_dynamic_input_; }
94 
95  void LetterBox(Mat* mat, std::vector<int> size, std::vector<float> color,
96  bool _auto, bool scale_fill = false, bool scale_up = true,
97  int stride = 32);
98 
99  // whether to inference with dynamic shape (e.g ONNX export with dynamic shape
100  // or not.)
101  // meituan/YOLOv6 official 'export_onnx.py' script will export static ONNX by
102  // default.
103  // while is_dynamic_input if 'false', is_mini_pad will force 'false'. This
104  // value will
105  // auto check by fastdeploy after the internal Runtime already initialized.
106  bool is_dynamic_input_;
107 // CUDA host buffer for input image
108  uint8_t* input_img_cuda_buffer_host_ = nullptr;
109  // CUDA device buffer for input image
110  uint8_t* input_img_cuda_buffer_device_ = nullptr;
111  // CUDA device buffer for TRT input tensor
112  float* input_tensor_cuda_buffer_device_ = nullptr;
113  // Whether to use CUDA preprocessing
114  bool use_cuda_preprocessing_ = false;
115  // CUDA stream
116  void* cuda_stream_ = nullptr;
117 };
118 
119 } // namespace detection
120 } // namespace vision
121 } // namespace fastdeploy
Option object used when create a new Runtime object.
Definition: runtime_option.h:40
std::vector< int > size
Argument for image preprocessing step, tuple of (width, height), decide the target size after resize...
Definition: yolov6.h:62
Base model object for all the vision models.
Definition: fastdeploy_model.h:21
ModelFormat
Definition: enum_variables.h:67
FDTensor object used to represend data matrix.
Definition: fd_tensor.h:31
YOLOv6 model object used when to load a YOLOv6 model exported by YOLOv6.
Definition: yolov6.h:28
Detection result structure for all the object detection models and instance segmentation models...
Definition: result.h:106
std::string ModelName() const
Get model&#39;s name.
Definition: yolov6.h:43
FDMat is a structure for replace cv::Mat.
Definition: mat.h:34
Model with ONNX format.
Definition: enum_variables.h:70
All C++ FastDeploy APIs are defined inside this namespace.
Definition: option.h:16