pfld.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. namespace ultra_infer {
  19. namespace vision {
  20. namespace facealign {
  21. /*! @brief PFLD model object used when to load a PFLD model exported by PFLD.
  22. */
  23. class ULTRAINFER_DECL PFLD : public UltraInferModel {
  24. public:
  25. /** \brief Set path of model file and the configuration of runtime.
  26. *
  27. * \param[in] model_file Path of model file, e.g ./pfld.onnx
  28. * \param[in] params_file Path of parameter file, e.g ppyoloe/model.pdiparams,
  29. * if the model format is ONNX, this parameter will be ignored \param[in]
  30. * custom_option RuntimeOption for inference, the default will use cpu, and
  31. * choose the backend defined in "valid_cpu_backends" \param[in] model_format
  32. * Model format of the loaded model, default is ONNX format
  33. */
  34. PFLD(const std::string &model_file, const std::string &params_file = "",
  35. const RuntimeOption &custom_option = RuntimeOption(),
  36. const ModelFormat &model_format = ModelFormat::ONNX);
  37. std::string ModelName() const { return "PFLD"; }
  38. /** \brief Predict the face detection result for an input image
  39. *
  40. * \param[in] im The input image data, comes from cv::imread(), is a 3-D array
  41. * with layout HWC, BGR format \param[in] result The output face detection
  42. * result will be written to this structure \return true if the prediction
  43. * succeeded, otherwise false
  44. */
  45. virtual bool Predict(cv::Mat *im, FaceAlignmentResult *result);
  46. /// tuple of (width, height), default (112, 112)
  47. std::vector<int> size;
  48. private:
  49. bool Initialize();
  50. bool Preprocess(Mat *mat, FDTensor *outputs,
  51. std::map<std::string, std::array<int, 2>> *im_info);
  52. bool Postprocess(FDTensor &infer_result, FaceAlignmentResult *result,
  53. const std::map<std::string, std::array<int, 2>> &im_info);
  54. };
  55. } // namespace facealign
  56. } // namespace vision
  57. } // namespace ultra_infer