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.8 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
  1. #pragma once
  2. #define RET_OK nullptr
  3. #ifdef _WIN32
  4. #include <Windows.h>
  5. #include <direct.h>
  6. #include <io.h>
  7. #endif
  8. #include <string>
  9. #include <vector>
  10. #include <cstdio>
  11. #include <opencv2/opencv.hpp>
  12. #include "onnxruntime_cxx_api.h"
  13. #ifdef USE_CUDA
  14. #include <cuda_fp16.h>
  15. #endif
  16. enum MODEL_TYPE
  17. {
  18. //FLOAT32 MODEL
  19. YOLO_DETECT_V8 = 1,
  20. YOLO_POSE = 2,
  21. YOLO_CLS = 3,
  22. //FLOAT16 MODEL
  23. YOLO_DETECT_V8_HALF = 4,
  24. YOLO_POSE_V8_HALF = 5,
  25. };
  26. typedef struct _DL_INIT_PARAM
  27. {
  28. std::string modelPath;
  29. MODEL_TYPE modelType = YOLO_DETECT_V8;
  30. std::vector<int> imgSize = { 640, 640 };
  31. float rectConfidenceThreshold = 0.6;
  32. float iouThreshold = 0.5;
  33. int keyPointsNum = 2;//Note:kpt number for pose
  34. bool cudaEnable = false;
  35. int logSeverityLevel = 3;
  36. int intraOpNumThreads = 1;
  37. } DL_INIT_PARAM;
  38. typedef struct _DL_RESULT
  39. {
  40. int classId;
  41. float confidence;
  42. cv::Rect box;
  43. std::vector<cv::Point2f> keyPoints;
  44. } DL_RESULT;
  45. class YOLO_V8
  46. {
  47. public:
  48. YOLO_V8();
  49. ~YOLO_V8();
  50. public:
  51. char* CreateSession(DL_INIT_PARAM& iParams);
  52. char* RunSession(cv::Mat& iImg, std::vector<DL_RESULT>& oResult);
  53. char* WarmUpSession();
  54. template<typename N>
  55. char* TensorProcess(clock_t& starttime_1, cv::Mat& iImg, N& blob, std::vector<int64_t>& inputNodeDims,
  56. std::vector<DL_RESULT>& oResult);
  57. char* PreProcess(cv::Mat& iImg, std::vector<int> iImgSize, cv::Mat& oImg);
  58. std::vector<std::string> classes{};
  59. private:
  60. Ort::Env env;
  61. Ort::Session* session;
  62. bool cudaEnable;
  63. Ort::RunOptions options;
  64. std::vector<const char*> inputNodeNames;
  65. std::vector<const char*> outputNodeNames;
  66. MODEL_TYPE modelType;
  67. std::vector<int> imgSize;
  68. float rectConfidenceThreshold;
  69. float iouThreshold;
  70. float resizeScales;//letterbox scale
  71. };
Tip!

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

Comments

Loading...