model.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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/vision/faceid/contrib/insightface/base.h"
  16. namespace ultra_infer {
  17. namespace vision {
  18. namespace faceid {
  19. class ULTRAINFER_DECL ArcFace : public InsightFaceRecognitionBase {
  20. public:
  21. /** \brief Set path of model file and configuration file, and the
  22. * configuration of runtime
  23. *
  24. * \param[in] model_file Path of model file, e.g ArcFace/model.pdmodel
  25. * \param[in] params_file Path of parameter file, e.g ArcFace/model.pdiparams,
  26. * if the model format is ONNX, this parameter will be ignored \param[in]
  27. * custom_option RuntimeOption for inference, the default will use cpu, and
  28. * choose the backend defined in `valid_cpu_backends` \param[in] model_format
  29. * Model format of the loaded model, default is Paddle format
  30. */
  31. ArcFace(const std::string &model_file, const std::string &params_file = "",
  32. const RuntimeOption &custom_option = RuntimeOption(),
  33. const ModelFormat &model_format = ModelFormat::ONNX)
  34. : InsightFaceRecognitionBase(model_file, params_file, custom_option,
  35. model_format) {
  36. if (model_format == ModelFormat::ONNX) {
  37. valid_cpu_backends = {Backend::ORT};
  38. valid_gpu_backends = {Backend::ORT, Backend::TRT};
  39. } else if (model_format == ModelFormat::RKNN) {
  40. valid_rknpu_backends = {Backend::RKNPU2};
  41. } else {
  42. valid_cpu_backends = {Backend::PDINFER, Backend::ORT, Backend::LITE};
  43. valid_gpu_backends = {Backend::PDINFER, Backend::ORT, Backend::TRT};
  44. valid_kunlunxin_backends = {Backend::LITE};
  45. }
  46. initialized = Initialize();
  47. }
  48. virtual std::string ModelName() const { return "ArcFace"; }
  49. };
  50. class ULTRAINFER_DECL CosFace : public InsightFaceRecognitionBase {
  51. public:
  52. /** \brief Set path of model file and configuration file, and the
  53. * configuration of runtime
  54. *
  55. * \param[in] model_file Path of model file, e.g CosFace/model.pdmodel
  56. * \param[in] params_file Path of parameter file, e.g CosFace/model.pdiparams,
  57. * if the model format is ONNX, this parameter will be ignored \param[in]
  58. * custom_option RuntimeOption for inference, the default will use cpu, and
  59. * choose the backend defined in `valid_cpu_backends` \param[in] model_format
  60. * Model format of the loaded model, default is Paddle format
  61. */
  62. CosFace(const std::string &model_file, const std::string &params_file = "",
  63. const RuntimeOption &custom_option = RuntimeOption(),
  64. const ModelFormat &model_format = ModelFormat::ONNX)
  65. : InsightFaceRecognitionBase(model_file, params_file, custom_option,
  66. model_format) {
  67. if (model_format == ModelFormat::ONNX) {
  68. valid_cpu_backends = {Backend::ORT};
  69. valid_gpu_backends = {Backend::ORT, Backend::TRT};
  70. } else if (model_format == ModelFormat::RKNN) {
  71. valid_rknpu_backends = {Backend::RKNPU2};
  72. } else {
  73. valid_cpu_backends = {Backend::PDINFER, Backend::ORT, Backend::LITE};
  74. valid_gpu_backends = {Backend::PDINFER, Backend::ORT, Backend::TRT};
  75. valid_kunlunxin_backends = {Backend::LITE};
  76. }
  77. initialized = Initialize();
  78. }
  79. virtual std::string ModelName() const { return "CosFace"; }
  80. };
  81. class ULTRAINFER_DECL PartialFC : public InsightFaceRecognitionBase {
  82. public:
  83. /** \brief Set path of model file and configuration file, and the
  84. * configuration of runtime
  85. *
  86. * \param[in] model_file Path of model file, e.g PartialFC/model.pdmodel
  87. * \param[in] params_file Path of parameter file, e.g
  88. * PartialFC/model.pdiparams, if the model format is ONNX, this parameter will
  89. * be ignored \param[in] custom_option RuntimeOption for inference, the
  90. * default will use cpu, and choose the backend defined in
  91. * `valid_cpu_backends` \param[in] model_format Model format of the loaded
  92. * model, default is Paddle format
  93. */
  94. PartialFC(const std::string &model_file, const std::string &params_file = "",
  95. const RuntimeOption &custom_option = RuntimeOption(),
  96. const ModelFormat &model_format = ModelFormat::ONNX)
  97. : InsightFaceRecognitionBase(model_file, params_file, custom_option,
  98. model_format) {
  99. if (model_format == ModelFormat::ONNX) {
  100. valid_cpu_backends = {Backend::ORT};
  101. valid_gpu_backends = {Backend::ORT, Backend::TRT};
  102. } else if (model_format == ModelFormat::RKNN) {
  103. valid_rknpu_backends = {Backend::RKNPU2};
  104. } else {
  105. valid_cpu_backends = {Backend::PDINFER, Backend::ORT, Backend::LITE};
  106. valid_gpu_backends = {Backend::PDINFER, Backend::ORT, Backend::TRT};
  107. valid_kunlunxin_backends = {Backend::LITE};
  108. }
  109. initialized = Initialize();
  110. }
  111. virtual std::string ModelName() const { return "PartialFC"; }
  112. };
  113. class ULTRAINFER_DECL VPL : public InsightFaceRecognitionBase {
  114. public:
  115. /** \brief Set path of model file and configuration file, and the
  116. * configuration of runtime
  117. *
  118. * \param[in] model_file Path of model file, e.g VPL/model.pdmodel
  119. * \param[in] params_file Path of parameter file, e.g VPL/model.pdiparams, if
  120. * the model format is ONNX, this parameter will be ignored \param[in]
  121. * custom_option RuntimeOption for inference, the default will use cpu, and
  122. * choose the backend defined in `valid_cpu_backends` \param[in] model_format
  123. * Model format of the loaded model, default is Paddle format
  124. */
  125. VPL(const std::string &model_file, const std::string &params_file = "",
  126. const RuntimeOption &custom_option = RuntimeOption(),
  127. const ModelFormat &model_format = ModelFormat::ONNX)
  128. : InsightFaceRecognitionBase(model_file, params_file, custom_option,
  129. model_format) {
  130. if (model_format == ModelFormat::ONNX) {
  131. valid_cpu_backends = {Backend::ORT};
  132. valid_gpu_backends = {Backend::ORT, Backend::TRT};
  133. } else if (model_format == ModelFormat::RKNN) {
  134. valid_rknpu_backends = {Backend::RKNPU2};
  135. } else {
  136. valid_cpu_backends = {Backend::PDINFER, Backend::ORT, Backend::LITE};
  137. valid_gpu_backends = {Backend::PDINFER, Backend::ORT, Backend::TRT};
  138. valid_kunlunxin_backends = {Backend::LITE};
  139. }
  140. initialized = Initialize();
  141. }
  142. virtual std::string ModelName() const { return "VPL"; }
  143. };
  144. } // namespace faceid
  145. } // namespace vision
  146. } // namespace ultra_infer