picodet_openvino.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright (c) 2021 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. // reference from https://github.com/RangiLyu/nanodet/tree/main/demo_openvino
  15. #ifndef _PICODET_OPENVINO_H_
  16. #define _PICODET_OPENVINO_H_
  17. #include <inference_engine.hpp>
  18. #include <opencv2/core.hpp>
  19. #include <string>
  20. #define image_size 416
  21. typedef struct HeadInfo {
  22. std::string cls_layer;
  23. std::string dis_layer;
  24. int stride;
  25. } HeadInfo;
  26. typedef struct BoxInfo {
  27. float x1;
  28. float y1;
  29. float x2;
  30. float y2;
  31. float score;
  32. int label;
  33. } BoxInfo;
  34. class PicoDet {
  35. public:
  36. PicoDet(const char *param);
  37. ~PicoDet();
  38. InferenceEngine::ExecutableNetwork network_;
  39. InferenceEngine::InferRequest infer_request_;
  40. // static bool hasGPU;
  41. std::vector<HeadInfo> heads_info_{
  42. // cls_pred|dis_pred|stride
  43. {"transpose_0.tmp_0", "transpose_1.tmp_0", 8},
  44. {"transpose_2.tmp_0", "transpose_3.tmp_0", 16},
  45. {"transpose_4.tmp_0", "transpose_5.tmp_0", 32},
  46. {"transpose_6.tmp_0", "transpose_7.tmp_0", 64},
  47. };
  48. std::vector<BoxInfo> detect(cv::Mat image, float score_threshold,
  49. float nms_threshold);
  50. private:
  51. void preprocess(cv::Mat &image, InferenceEngine::Blob::Ptr &blob);
  52. void decode_infer(const float *&cls_pred, const float *&dis_pred, int stride,
  53. float threshold,
  54. std::vector<std::vector<BoxInfo>> &results);
  55. BoxInfo disPred2Bbox(const float *&dfl_det, int label, float score, int x,
  56. int y, int stride);
  57. static void nms(std::vector<BoxInfo> &result, float nms_threshold);
  58. std::string input_name_;
  59. int input_size_ = image_size;
  60. int num_class_ = 80;
  61. int reg_max_ = 7;
  62. };
  63. #endif