base.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #pragma once
  15. #include "ultra_infer/ultra_infer_model.h"
  16. #include "ultra_infer/vision/faceid/contrib/insightface/postprocessor.h"
  17. #include "ultra_infer/vision/faceid/contrib/insightface/preprocessor.h"
  18. namespace ultra_infer {
  19. namespace vision {
  20. namespace faceid {
  21. /*! @brief InsightFaceRecognition model object used when to load a
  22. * InsightFaceRecognition model exported by InsightFaceRecognition.
  23. */
  24. class ULTRAINFER_DECL InsightFaceRecognitionBase : public UltraInferModel {
  25. public:
  26. /** \brief Set path of model file and the configuration of runtime.
  27. *
  28. * \param[in] model_file Path of model file, e.g ./arcface.onnx
  29. * \param[in] params_file Path of parameter file, e.g arcface/model.pdiparams,
  30. * if the model format is ONNX, this parameter will be ignored \param[in]
  31. * custom_option RuntimeOption for inference, the default will use cpu, and
  32. * choose the backend defined in "valid_cpu_backends" \param[in] model_format
  33. * Model format of the loaded model, default is ONNX format
  34. */
  35. InsightFaceRecognitionBase(
  36. const std::string &model_file, const std::string &params_file = "",
  37. const RuntimeOption &custom_option = RuntimeOption(),
  38. const ModelFormat &model_format = ModelFormat::ONNX);
  39. std::string ModelName() const { return "insightface_rec"; }
  40. /** \brief Predict the detection result for an input image
  41. *
  42. * \param[in] img The input image data, comes from cv::imread(), is a 3-D
  43. * array with layout HWC, BGR format \param[in] result The output
  44. * FaceRecognitionResult will be written to this structure \return true if the
  45. * prediction succeeded, otherwise false
  46. */
  47. virtual bool Predict(const cv::Mat &im, FaceRecognitionResult *result);
  48. /** \brief Predict the detection results for a batch of input images
  49. *
  50. * \param[in] imgs, The input image list, each element comes from cv::imread()
  51. * \param[in] results The output FaceRecognitionResult list
  52. * \return true if the prediction succeeded, otherwise false
  53. */
  54. virtual bool BatchPredict(const std::vector<cv::Mat> &images,
  55. std::vector<FaceRecognitionResult> *results);
  56. /// Get preprocessor reference of InsightFaceRecognition
  57. virtual InsightFaceRecognitionPreprocessor &GetPreprocessor() {
  58. return preprocessor_;
  59. }
  60. /// Get postprocessor reference of InsightFaceRecognition
  61. virtual InsightFaceRecognitionPostprocessor &GetPostprocessor() {
  62. return postprocessor_;
  63. }
  64. protected:
  65. bool Initialize();
  66. InsightFaceRecognitionPreprocessor preprocessor_;
  67. InsightFaceRecognitionPostprocessor postprocessor_;
  68. };
  69. } // namespace faceid
  70. } // namespace vision
  71. } // namespace ultra_infer