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 2.1 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
  1. // Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
  2. #ifndef INFERENCE_H
  3. #define INFERENCE_H
  4. // Cpp native
  5. #include <fstream>
  6. #include <vector>
  7. #include <string>
  8. #include <random>
  9. // OpenCV / DNN / Inference
  10. #include <opencv2/imgproc.hpp>
  11. #include <opencv2/opencv.hpp>
  12. #include <opencv2/dnn.hpp>
  13. struct Detection
  14. {
  15. int class_id{0};
  16. std::string className{};
  17. float confidence{0.0};
  18. cv::Scalar color{};
  19. cv::Rect box{};
  20. };
  21. class Inference
  22. {
  23. public:
  24. Inference(const std::string &onnxModelPath, const cv::Size &modelInputShape = {640, 640}, const std::string &classesTxtFile = "", const bool &runWithCuda = true);
  25. std::vector<Detection> runInference(const cv::Mat &input);
  26. private:
  27. void loadClassesFromFile();
  28. void loadOnnxNetwork();
  29. cv::Mat formatToSquare(const cv::Mat &source, int *pad_x, int *pad_y, float *scale);
  30. std::string modelPath{};
  31. std::string classesPath{};
  32. bool cudaEnabled{};
  33. std::vector<std::string> classes{"person", "bicycle", "car", "motorcycle", "airplane", "bus", "train", "truck", "boat", "traffic light", "fire hydrant", "stop sign", "parking meter", "bench", "bird", "cat", "dog", "horse", "sheep", "cow", "elephant", "bear", "zebra", "giraffe", "backpack", "umbrella", "handbag", "tie", "suitcase", "frisbee", "skis", "snowboard", "sports ball", "kite", "baseball bat", "baseball glove", "skateboard", "surfboard", "tennis racket", "bottle", "wine glass", "cup", "fork", "knife", "spoon", "bowl", "banana", "apple", "sandwich", "orange", "broccoli", "carrot", "hot dog", "pizza", "donut", "cake", "chair", "couch", "potted plant", "bed", "dining table", "toilet", "tv", "laptop", "mouse", "remote", "keyboard", "cell phone", "microwave", "oven", "toaster", "sink", "refrigerator", "book", "clock", "vase", "scissors", "teddy bear", "hair drier", "toothbrush"};
  34. cv::Size2f modelShape{};
  35. float modelConfidenceThreshold {0.25};
  36. float modelScoreThreshold {0.45};
  37. float modelNMSThreshold {0.50};
  38. bool letterBoxForSquare = true;
  39. cv::dnn::Net net;
  40. };
  41. #endif // INFERENCE_H
Tip!

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

Comments

Loading...