FastDeploy  latest
Fast & Easy to Deploy!
yolov5face.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 #include "fastdeploy/fastdeploy_model.h"
17 #include "fastdeploy/vision/common/processors/transform.h"
18 #include "fastdeploy/vision/common/result.h"
19 
20 namespace fastdeploy {
21 
22 namespace vision {
23 
24 namespace facedet {
27 class FASTDEPLOY_DECL YOLOv5Face : public FastDeployModel {
28  public:
36  YOLOv5Face(const std::string& model_file, const std::string& params_file = "",
37  const RuntimeOption& custom_option = RuntimeOption(),
38  const ModelFormat& model_format = ModelFormat::ONNX);
39 
40  std::string ModelName() const { return "yolov5-face"; }
49  virtual bool Predict(cv::Mat* im, FaceDetectionResult* result,
50  float conf_threshold = 0.25,
51  float nms_iou_threshold = 0.5);
52 
56  std::vector<int> size;
57  // padding value, size should be the same as channels
58 
59  std::vector<float> padding_value;
60  // only pad to the minimum rectange which height and width is times of stride
61  bool is_mini_pad;
62  // while is_mini_pad = false and is_no_pad = true,
63  // will resize the image to the set size
64 
65  bool is_no_pad;
66  // if is_scale_up is false, the input image only can be zoom out,
67  // the maximum resize scale cannot exceed 1.0
68 
69  bool is_scale_up;
70  // padding stride, for is_mini_pad
71  int stride;
78 
79  private:
80  bool Initialize();
81 
82  bool Preprocess(Mat* mat, FDTensor* outputs,
83  std::map<std::string, std::array<float, 2>>* im_info);
84 
85  bool Postprocess(FDTensor& infer_result, FaceDetectionResult* result,
86  const std::map<std::string, std::array<float, 2>>& im_info,
87  float conf_threshold, float nms_iou_threshold);
88 
89  bool IsDynamicInput() const { return is_dynamic_input_; }
90 
91  bool is_dynamic_input_;
92 };
93 
94 } // namespace facedet
95 } // namespace vision
96 } // 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
Face detection result structure for all the face detection models.
Definition: result.h:212
FDMat is a structure for replace cv::Mat.
Definition: mat.h:34
std::vector< int > size
Argument for image preprocessing step, tuple of (width, height), decide the target size after resize...
Definition: yolov5face.h:56
std::string ModelName() const
Get model&#39;s name.
Definition: yolov5face.h:40
int landmarks_per_face
Argument for image postprocessing step, setup the number of landmarks for per face (if have)...
Definition: yolov5face.h:77
Model with ONNX format.
Definition: enum_variables.h:70
All C++ FastDeploy APIs are defined inside this namespace.
Definition: option.h:16
YOLOv5Face model object used when to load a YOLOv5Face model exported by YOLOv5Face.
Definition: yolov5face.h:27