FastDeploy  latest
Fast & Easy to Deploy!
yolov5.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/detection/contrib/yolov5/preprocessor.h"
19 #include "fastdeploy/vision/detection/contrib/yolov5/postprocessor.h"
20 
21 namespace fastdeploy {
22 namespace vision {
23 namespace detection {
26 class FASTDEPLOY_DECL YOLOv5 : public FastDeployModel {
27  public:
35  YOLOv5(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  std::string ModelName() const { return "yolov5"; }
40 
49  virtual bool Predict(cv::Mat* im, DetectionResult* result,
50  float conf_threshold = 0.25,
51  float nms_threshold = 0.5);
52 
59  virtual bool Predict(const cv::Mat& img, DetectionResult* result);
60 
67  virtual bool BatchPredict(const std::vector<cv::Mat>& imgs,
68  std::vector<DetectionResult>* results);
69 
72  return preprocessor_;
73  }
74 
77  return postprocessor_;
78  }
79 
80  protected:
81  bool Initialize();
82  YOLOv5Preprocessor preprocessor_;
83  YOLOv5Postprocessor postprocessor_;
84 };
85 
86 } // namespace detection
87 } // namespace vision
88 } // 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
YOLOv5 model object used when to load a YOLOv5 model exported by YOLOv5.
Definition: yolov5.h:26
ModelFormat
Definition: enum_variables.h:67
std::string ModelName() const
Get model&#39;s name.
Definition: yolov5.h:39
virtual YOLOv5Postprocessor & GetPostprocessor()
Get postprocessor reference of YOLOv5.
Definition: yolov5.h:76
Detection result structure for all the object detection models and instance segmentation models...
Definition: result.h:106
Postprocessor object for YOLOv5 serials model.
Definition: postprocessor.h:25
Model with ONNX format.
Definition: enum_variables.h:70
Preprocessor object for YOLOv5 serials model.
Definition: preprocessor.h:25
virtual YOLOv5Preprocessor & GetPreprocessor()
Get preprocessor reference of YOLOv5.
Definition: yolov5.h:71
All C++ FastDeploy APIs are defined inside this namespace.
Definition: option.h:16