model.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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/vision/detection/contrib/rknpu2/rkyolo.h"
  16. namespace ultra_infer {
  17. namespace vision {
  18. namespace detection {
  19. class ULTRAINFER_DECL RKYOLOV5 : public RKYOLO {
  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 picodet/model.pdmodel
  25. * \param[in] custom_option RuntimeOption for inference, the default will use
  26. * cpu, and choose the backend defined in `valid_cpu_backends` \param[in]
  27. * model_format Model format of the loaded model, default is Paddle format
  28. */
  29. RKYOLOV5(const std::string &model_file,
  30. const RuntimeOption &custom_option = RuntimeOption(),
  31. const ModelFormat &model_format = ModelFormat::RKNN)
  32. : RKYOLO(model_file, custom_option, model_format) {
  33. valid_cpu_backends = {};
  34. valid_gpu_backends = {};
  35. valid_rknpu_backends = {Backend::RKNPU2};
  36. std::vector<int> anchors = {10, 13, 16, 30, 33, 23, 30, 61, 62,
  37. 45, 59, 119, 116, 90, 156, 198, 373, 326};
  38. int anchor_per_branch_ = 3;
  39. GetPostprocessor().SetAnchor(anchors);
  40. GetPostprocessor().SetAnchorPerBranch(anchor_per_branch_);
  41. }
  42. virtual std::string ModelName() const { return "RKYOLOV5"; }
  43. };
  44. class ULTRAINFER_DECL RKYOLOV7 : public RKYOLO {
  45. public:
  46. /** \brief Set path of model file and configuration file, and the
  47. * configuration of runtime
  48. *
  49. * \param[in] model_file Path of model file, e.g picodet/model.pdmodel
  50. * \param[in] custom_option RuntimeOption for inference, the default will use
  51. * cpu, and choose the backend defined in `valid_cpu_backends` \param[in]
  52. * model_format Model format of the loaded model, default is Paddle format
  53. */
  54. RKYOLOV7(const std::string &model_file,
  55. const RuntimeOption &custom_option = RuntimeOption(),
  56. const ModelFormat &model_format = ModelFormat::RKNN)
  57. : RKYOLO(model_file, custom_option, model_format) {
  58. valid_cpu_backends = {};
  59. valid_gpu_backends = {};
  60. valid_rknpu_backends = {Backend::RKNPU2};
  61. std::vector<int> anchors = {12, 16, 19, 36, 40, 28, 36, 75, 76,
  62. 55, 72, 146, 142, 110, 192, 243, 459, 401};
  63. int anchor_per_branch_ = 3;
  64. GetPostprocessor().SetAnchor(anchors);
  65. GetPostprocessor().SetAnchorPerBranch(anchor_per_branch_);
  66. }
  67. virtual std::string ModelName() const { return "RKYOLOV7"; }
  68. };
  69. class ULTRAINFER_DECL RKYOLOX : public RKYOLO {
  70. public:
  71. /** \brief Set path of model file and configuration file, and the
  72. * configuration of runtime
  73. *
  74. * \param[in] model_file Path of model file, e.g picodet/model.pdmodel
  75. * \param[in] custom_option RuntimeOption for inference, the default will use
  76. * cpu, and choose the backend defined in `valid_cpu_backends` \param[in]
  77. * model_format Model format of the loaded model, default is Paddle format
  78. */
  79. RKYOLOX(const std::string &model_file,
  80. const RuntimeOption &custom_option = RuntimeOption(),
  81. const ModelFormat &model_format = ModelFormat::RKNN)
  82. : RKYOLO(model_file, custom_option, model_format) {
  83. valid_cpu_backends = {};
  84. valid_gpu_backends = {};
  85. valid_rknpu_backends = {Backend::RKNPU2};
  86. std::vector<int> anchors = {1, 1, 1, 1, 1, 1, 1, 1, 1,
  87. 1, 1, 1, 1, 1, 1, 1, 1, 1};
  88. int anchor_per_branch_ = 1;
  89. GetPostprocessor().SetAnchor(anchors);
  90. GetPostprocessor().SetAnchorPerBranch(anchor_per_branch_);
  91. }
  92. virtual std::string ModelName() const { return "RKYOLOV7"; }
  93. };
  94. } // namespace detection
  95. } // namespace vision
  96. } // namespace ultra_infer