FastDeploy  latest
Fast & Easy to Deploy!
yolor.h
1 
2  // Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #pragma once
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 namespace vision {
23 namespace detection {
26 class FASTDEPLOY_DECL YOLOR : public FastDeployModel {
27  public:
35  YOLOR(const std::string& model_file, const std::string& params_file = "",
36  const RuntimeOption& custom_option = RuntimeOption(),
37  const ModelFormat& model_format = ModelFormat::ONNX);
38 
39  virtual std::string ModelName() const { return "YOLOR"; }
48  virtual bool Predict(cv::Mat* im, DetectionResult* result,
49  float conf_threshold = 0.25,
50  float nms_iou_threshold = 0.5);
51 
55  std::vector<int> size;
56  // padding value, size should be the same as channels
57 
58  std::vector<float> padding_value;
59  // only pad to the minimum rectange which height and width is times of stride
60  bool is_mini_pad;
61  // while is_mini_pad = false and is_no_pad = true,
62  // will resize the image to the set size
63  bool is_no_pad;
64  // if is_scale_up is false, the input image only can be zoom out,
65  // the maximum resize scale cannot exceed 1.0
66  bool is_scale_up;
67  // padding stride, for is_mini_pad
68  int stride;
69  // for offseting the boxes by classes when using NMS
70  float max_wh;
71 
72  private:
73  bool Initialize();
74 
75  bool Preprocess(Mat* mat, FDTensor* output,
76  std::map<std::string, std::array<float, 2>>* im_info);
77 
78  bool Postprocess(FDTensor& infer_result, DetectionResult* result,
79  const std::map<std::string, std::array<float, 2>>& im_info,
80  float conf_threshold, float nms_iou_threshold);
81 
82  void LetterBox(Mat* mat, const std::vector<int>& size,
83  const std::vector<float>& color, bool _auto,
84  bool scale_fill = false, bool scale_up = true,
85  int stride = 32);
86 
87  // whether to inference with dynamic shape (e.g ONNX export with dynamic shape
88  // or not.)
89  // while is_dynamic_shape if 'false', is_mini_pad will force 'false'. This
90  // value will
91  // auto check by fastdeploy after the internal Runtime already initialized.
92  bool is_dynamic_input_;
93 };
94 
95 } // namespace detection
96 } // namespace vision
97 } // namespace fastdeploy
Option object used when create a new Runtime object.
Definition: runtime_option.h:40
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
Detection result structure for all the object detection models and instance segmentation models...
Definition: result.h:106
FDMat is a structure for replace cv::Mat.
Definition: mat.h:34
YOLOR model object used when to load a YOLOR model exported by YOLOR.
Definition: yolor.h:26
Model with ONNX format.
Definition: enum_variables.h:70
std::vector< int > size
Argument for image preprocessing step, tuple of (width, height), decide the target size after resize...
Definition: yolor.h:55
All C++ FastDeploy APIs are defined inside this namespace.
Definition: option.h:16
virtual std::string ModelName() const
Get model&#39;s name.
Definition: yolor.h:39