FastDeploy  latest
Fast & Easy to Deploy!
nanodet_plus.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 NanoDetPlus : public FastDeployModel {
29  public:
37  NanoDetPlus(const std::string& model_file,
38  const std::string& params_file = "",
39  const RuntimeOption& custom_option = RuntimeOption(),
40  const ModelFormat& model_format = ModelFormat::ONNX);
42  std::string ModelName() const { return "nanodet"; }
43 
52  virtual bool Predict(cv::Mat* im, DetectionResult* result,
53  float conf_threshold = 0.35f,
54  float nms_iou_threshold = 0.5f);
55 
59  std::vector<int> size;
60  // padding value, size should be the same as channels
61  std::vector<float> padding_value;
62  // keep aspect ratio or not when perform resize operation.
63  // This option is set as `false` by default in NanoDet-Plus
64  bool keep_ratio;
65  // downsample strides for NanoDet-Plus to generate anchors,
66  // will take (8, 16, 32, 64) as default values
67  std::vector<int> downsample_strides;
68  // for offseting the boxes by classes when using NMS, default 4096
69  float max_wh;
73  int reg_max;
74 
75  private:
76  bool Initialize();
77 
78  bool Preprocess(Mat* mat, FDTensor* output,
79  std::map<std::string, std::array<float, 2>>* im_info);
80 
81  bool Postprocess(FDTensor& infer_result, DetectionResult* result,
82  const std::map<std::string, std::array<float, 2>>& im_info,
83  float conf_threshold, float nms_iou_threshold);
84 
85  bool IsDynamicInput() const { return is_dynamic_input_; }
86 
87  // whether to inference with dynamic shape (e.g ONNX export with dynamic shape
88  // or not.)
89  // RangiLyu/nanodet official 'export_onnx.py' script will export static ONNX
90  // by default.
91  // This value will auto check by fastdeploy after the internal Runtime
92  // initialized.
93  bool is_dynamic_input_;
94 };
95 
96 } // namespace detection
97 } // namespace vision
98 } // namespace fastdeploy
Option object used when create a new Runtime object.
Definition: runtime_option.h:40
NanoDetPlus model object used when to load a NanoDetPlus model exported by NanoDet.
Definition: nanodet_plus.h:28
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
std::string ModelName() const
Get model&#39;s name.
Definition: nanodet_plus.h:42
FDMat is a structure for replace cv::Mat.
Definition: mat.h:34
int reg_max
Argument for image postprocessing step, reg_max for GFL regression, default 7.
Definition: nanodet_plus.h:73
Model with ONNX format.
Definition: enum_variables.h:70
std::vector< int > size
Argument for image preprocessing step, tuple of input size (width, height), default (320...
Definition: nanodet_plus.h:59
All C++ FastDeploy APIs are defined inside this namespace.
Definition: option.h:16