FastDeploy  latest
Fast & Easy to Deploy!
retinaface.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 {
26 namespace facedet {
29 class FASTDEPLOY_DECL RetinaFace : public FastDeployModel {
30  public:
38  RetinaFace(const std::string& model_file, const std::string& params_file = "",
39  const RuntimeOption& custom_option = RuntimeOption(),
40  const ModelFormat& model_format = ModelFormat::ONNX);
41 
42  std::string ModelName() const { return "Pytorch_Retinaface"; }
51  virtual bool Predict(cv::Mat* im, FaceDetectionResult* result,
52  float conf_threshold = 0.25f,
53  float nms_iou_threshold = 0.4f);
54 
58  std::vector<int> size;
62  std::vector<float> variance;
66  std::vector<int> downsample_strides;
70  std::vector<std::vector<int>> min_sizes;
75 
76  private:
77  bool Initialize();
78 
79  bool Preprocess(Mat* mat, FDTensor* output,
80  std::map<std::string, std::array<float, 2>>* im_info);
81 
82  bool Postprocess(std::vector<FDTensor>& infer_result,
83  FaceDetectionResult* result,
84  const std::map<std::string, std::array<float, 2>>& im_info,
85  float conf_threshold, float nms_iou_threshold);
86 
87  bool IsDynamicInput() const { return is_dynamic_input_; }
88 
89  bool is_dynamic_input_;
90 };
91 
92 } // namespace facedet
93 } // namespace vision
94 } // 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
RetinaFace model object used when to load a RetinaFace model exported by RetinaFace.
Definition: retinaface.h:29
ModelFormat
Definition: enum_variables.h:67
FDTensor object used to represend data matrix.
Definition: fd_tensor.h:31
std::vector< int > downsample_strides
Argument for image postprocessing step, downsample strides (namely, steps) for RetinaFace to generate...
Definition: retinaface.h:66
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
int landmarks_per_face
Argument for image postprocessing step, landmarks_per_face, default 5 in RetinaFace.
Definition: retinaface.h:74
std::vector< int > size
Argument for image preprocessing step, tuple of (width, height), decide the target size after resize...
Definition: retinaface.h:58
Model with ONNX format.
Definition: enum_variables.h:70
std::string ModelName() const
Get model&#39;s name.
Definition: retinaface.h:42
std::vector< std::vector< int > > min_sizes
Argument for image postprocessing step, min sizes, width and height for each anchor, default min_sizes = {{16, 32}, {64, 128}, {256, 512}}.
Definition: retinaface.h:70
std::vector< float > variance
Argument for image postprocessing step, variance in RetinaFace&#39;s prior-box(anchor) generate process...
Definition: retinaface.h:62
All C++ FastDeploy APIs are defined inside this namespace.
Definition: option.h:16