FastDeploy  latest
Fast & Easy to Deploy!
yolox.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/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 YOLOX : public FastDeployModel {
29  public:
37  YOLOX(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  std::string ModelName() const { return "YOLOX"; }
50  virtual bool Predict(cv::Mat* im, DetectionResult* result,
51  float conf_threshold = 0.25,
52  float nms_iou_threshold = 0.5);
53 
57  std::vector<int> size;
58  // padding value, size should be the same as channels
59  std::vector<float> padding_value;
67  // downsample strides for YOLOX to generate anchors,
68  // will take (8,16,32) as default values, might have stride=64
69  std::vector<int> downsample_strides;
70  // for offseting the boxes by classes when using NMS, default 4096
71  float max_wh;
72 
73  private:
74  bool Initialize();
75 
76  bool Preprocess(Mat* mat, FDTensor* outputs,
77  std::map<std::string, std::array<float, 2>>* im_info);
78 
79  bool Postprocess(FDTensor& infer_result, DetectionResult* result,
80  const std::map<std::string, std::array<float, 2>>& im_info,
81  float conf_threshold, float nms_iou_threshold);
82 
83  bool PostprocessWithDecode(
84  FDTensor& infer_result, DetectionResult* result,
85  const std::map<std::string, std::array<float, 2>>& im_info,
86  float conf_threshold, float nms_iou_threshold);
87 
88  bool IsDynamicInput() const { return is_dynamic_input_; }
89 
90  // whether to inference with dynamic shape (e.g ONNX export with dynamic shape
91  // or not.)
92  // megvii/YOLOX official 'export_onnx.py' script will export static ONNX by
93  // default.
94  // while is_dynamic_shape if 'false', is_mini_pad will force 'false'. This
95  // value will
96  // auto check by fastdeploy after the internal Runtime already initialized.
97  bool is_dynamic_input_;
98 };
99 
100 } // namespace detection
101 } // namespace vision
102 } // 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
bool is_decode_exported
whether the model_file was exported with decode module. The official YOLOX/tools/export_onnx.py script will export ONNX file without decode module. Please set it &#39;true&#39; manually if the model file was exported with decode module. default false.
Definition: yolox.h:66
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
YOLOX model object used when to load a YOLOX model exported by YOLOX.
Definition: yolox.h:28
FDMat is a structure for replace cv::Mat.
Definition: mat.h:34
std::string ModelName() const
Get model&#39;s name.
Definition: yolox.h:41
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: yolox.h:57
All C++ FastDeploy APIs are defined inside this namespace.
Definition: option.h:16