Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

inference.h 1.9 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
  1. // Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
  2. #pragma once
  3. #define RET_OK nullptr
  4. #ifdef _WIN32
  5. #include <Windows.h>
  6. #include <direct.h>
  7. #include <io.h>
  8. #endif
  9. #include <string>
  10. #include <vector>
  11. #include <cstdio>
  12. #include <opencv2/opencv.hpp>
  13. #include "onnxruntime_cxx_api.h"
  14. #ifdef USE_CUDA
  15. #include <cuda_fp16.h>
  16. #endif
  17. enum MODEL_TYPE
  18. {
  19. //FLOAT32 MODEL
  20. YOLO_DETECT_V8 = 1,
  21. YOLO_POSE = 2,
  22. YOLO_CLS = 3,
  23. //FLOAT16 MODEL
  24. YOLO_DETECT_V8_HALF = 4,
  25. YOLO_POSE_V8_HALF = 5,
  26. YOLO_CLS_HALF = 6
  27. };
  28. typedef struct _DL_INIT_PARAM
  29. {
  30. std::string modelPath;
  31. MODEL_TYPE modelType = YOLO_DETECT_V8;
  32. std::vector<int> imgSize = { 640, 640 };
  33. float rectConfidenceThreshold = 0.6;
  34. float iouThreshold = 0.5;
  35. int keyPointsNum = 2;//Note:kpt number for pose
  36. bool cudaEnable = false;
  37. int logSeverityLevel = 3;
  38. int intraOpNumThreads = 1;
  39. } DL_INIT_PARAM;
  40. typedef struct _DL_RESULT
  41. {
  42. int classId;
  43. float confidence;
  44. cv::Rect box;
  45. std::vector<cv::Point2f> keyPoints;
  46. } DL_RESULT;
  47. class YOLO_V8
  48. {
  49. public:
  50. YOLO_V8();
  51. ~YOLO_V8();
  52. public:
  53. char* CreateSession(DL_INIT_PARAM& iParams);
  54. char* RunSession(cv::Mat& iImg, std::vector<DL_RESULT>& oResult);
  55. char* WarmUpSession();
  56. template<typename N>
  57. char* TensorProcess(clock_t& starttime_1, cv::Mat& iImg, N& blob, std::vector<int64_t>& inputNodeDims,
  58. std::vector<DL_RESULT>& oResult);
  59. char* PreProcess(cv::Mat& iImg, std::vector<int> iImgSize, cv::Mat& oImg);
  60. std::vector<std::string> classes{};
  61. private:
  62. Ort::Env env;
  63. Ort::Session* session;
  64. bool cudaEnable;
  65. Ort::RunOptions options;
  66. std::vector<const char*> inputNodeNames;
  67. std::vector<const char*> outputNodeNames;
  68. MODEL_TYPE modelType;
  69. std::vector<int> imgSize;
  70. float rectConfidenceThreshold;
  71. float iouThreshold;
  72. float resizeScales;//letterbox scale
  73. };
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...