plugin  0.1.0
detection_model_retinaface_pt.h
1 /*
2 // Copyright (C) 2021-2024 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16 
17 #pragma once
18 #include <stddef.h>
19 
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
24 #include <opencv2/core/types.hpp>
25 #include <utils/nms.hpp>
26 
27 #include "models/detection_model.h"
28 
29 namespace ov {
30 class Model;
31 class Tensor;
32 } // namespace ov
33 struct InferenceResult;
34 struct ResultBase;
35 
37 public:
38  struct Box {
39  float cX;
40  float cY;
41  float width;
42  float height;
43  };
44 
52  ModelRetinaFacePT(const std::string& modelFileName,
53  float confidenceThreshold,
54  bool useAutoResize,
55  float boxIOUThreshold,
56  const std::string& layout = "");
57  std::unique_ptr<ResultBase> postprocess(InferenceResult& infResult) override;
58 
59 protected:
60  size_t landmarksNum;
61  const float boxIOUThreshold;
62  float variance[2] = {0.1f, 0.2f};
63 
64  enum OutputType { OUT_BOXES, OUT_SCORES, OUT_LANDMARKS, OUT_MAX };
65 
66  std::vector<ModelRetinaFacePT::Box> priors;
67 
68  std::vector<size_t> filterByScore(const ov::Tensor& scoresTensor, const float confidenceThreshold);
69  std::vector<float> getFilteredScores(const ov::Tensor& scoresTensor, const std::vector<size_t>& indicies);
70  std::vector<cv::Point2f> getFilteredLandmarks(const ov::Tensor& landmarksTensor,
71  const std::vector<size_t>& indicies,
72  int imgWidth,
73  int imgHeight);
74  std::vector<ModelRetinaFacePT::Box> generatePriorData();
75  std::vector<Anchor> getFilteredProposals(const ov::Tensor& boxesTensor,
76  const std::vector<size_t>& indicies,
77  int imgWidth,
78  int imgHeight);
79 
80  void prepareInputsOutputs(std::shared_ptr<ov::Model>& model) override;
81 };
Definition: detection_model.h:25
Definition: detection_model_retinaface_pt.h:36
ModelRetinaFacePT(const std::string &modelFileName, float confidenceThreshold, bool useAutoResize, float boxIOUThreshold, const std::string &layout="")
Definition: detection_model_retinaface_pt.cpp:37
Definition: results.h:53
Definition: detection_model_retinaface_pt.h:38
Definition: results.h:29