blazeface.h 3.3 KB

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