DaoAI World C++ SDK industrial 2.24.8.0
Loading...
Searching...
No Matches
model.h
Go to the documentation of this file.
1// Copyright (c) 2024, DaoAI Robotics. All rights reserved.
2// Version: 0.0.0
3
4#pragma once
5#include "API_EXPORT.h"
6#include <string>
7#include <map>
8#include <filesystem>
9#include "common.h"
10#include "prediction.h"
11#include "config.h"
12namespace DaoAI
13{
14
15 namespace DeepLearning
16 {
25
26 // Initialize DaoAI Deep Learning SDK
27 DAOAI_API void initialize(const bool& use_shared_memory = false, const size_t& reserved_vram_size = 500000000);
28
30
36
37 struct ModelInfo
38 {
41 std::vector<std::string> class_labels;
42 std::vector<int> num_keypoints;
43 std::vector<std::string> keypoint_labels;
44 std::string extra_infos = "";
45 };
46
47 class ModelInstance;
48
49 class Model
50 {
51 public:
52 Model() = default;
53 Model(const std::filesystem::path& model_config_path, const std::filesystem::path& model_weights_path, const DaoAI::DeepLearning::DeviceType& device = DeviceType::GPU, const int& device_idx = -1);
54 Model(const std::filesystem::path& model_path, const DaoAI::DeepLearning::DeviceType& device = DeviceType::GPU, const int& device_idx = -1);
55
56 DAOAI_API virtual ~Model();
57
59
60 /*
61 * @brief Set the batch size for inference
62 * @param batch_size: the batch size for inference
63 */
64 DAOAI_API void setBatchSize(const size_t& batch_size);
65
66 /*
67 * @brief Get the batch size for inference
68 */
69 DAOAI_API size_t getBatchSize() const;
70
71 protected:
72 std::shared_ptr<ModelInstance> model_instance_ = nullptr;
73 };
74
75 namespace Vision
76 {
77 class Detection : public Model
78 {
79 public:
80 using Model::Model;
81
82 /*
83 * @brief Set the threshold for how confident the model should be in its predictions
84 * @param threshold: the threshold for how confident the model should be in its predictions
85 */
86 DAOAI_API void setConfidenceThreshold(const float& threshold);
87
88 /*
89 * @brief Get the threshold for how confident the model should be in its predictions
90 */
92
93 /*
94 * @brief Set the threshold for the IOU between the predicted bounding box and the ground truth bounding box
95 * @param threshold: the threshold for the IOU between the predicted bounding box and the ground truth bounding box
96 */
97 DAOAI_API void setIOUThreshold(const float& threshold);
98
99 /*
100 * @brief Get the threshold for the IOU between the predicted bounding box and the ground truth bounding box
101 */
103 };
104
105 class ObjectDetection final : public Detection
106 {
107 public:
108 DAOAI_API ObjectDetection(const std::filesystem::path& model_file, const DeviceType& device = DeviceType::GPU, const int& device_idx = -1);
109 DAOAI_API ObjectDetection(const std::filesystem::path& model_config_path, const std::filesystem::path& model_weights_path, const DeviceType& device = DeviceType::GPU, const int& device_idx = -1);
111 DAOAI_API std::vector<ObjectDetectionResult> inference(const std::vector<Image>& images);
112 };
113 class InstanceSegmentation final : public Detection
114 {
115 public:
116 DAOAI_API InstanceSegmentation(const std::filesystem::path& model_file, const DeviceType& device = DeviceType::GPU, const int& device_idx = -1);
117 DAOAI_API InstanceSegmentation(const std::filesystem::path& model_config_path, const std::filesystem::path& model_weights_path, const DeviceType& device = DeviceType::GPU, const int& device_idx = -1);
119 DAOAI_API std::vector<InstanceSegmentationResult> inference(const std::vector<Image>& images);
120 };
121 class KeypointDetection final : public Detection
122 {
123 public:
124 DAOAI_API KeypointDetection(const std::filesystem::path& model_file, const DeviceType& device = DeviceType::GPU, const int& device_idx = -1);
125 DAOAI_API KeypointDetection(const std::filesystem::path& model_config_path, const std::filesystem::path& model_weights_path, const DeviceType& device = DeviceType::GPU, const int& device_idx = -1);
127 DAOAI_API std::vector<KeypointDetectionResult> inference(const std::vector<Image>& images);
128 };
129 class OCR final : public Model
130 {
131 public:
132 DAOAI_API OCR(const std::filesystem::path& model_file, const DeviceType& device = DeviceType::GPU, const int& device_idx = -1);
133 DAOAI_API OCR(const std::filesystem::path& model_config_path, const std::filesystem::path& model_weights_path, const DeviceType& device = DeviceType::GPU, const int& device_idx = -1);
135 DAOAI_API std::vector<OCRResult> inference(const std::vector<Image>& images);
136 };
137 class Classification final : public Model
138 {
139 public:
140 DAOAI_API Classification(const std::filesystem::path& model_file, const DeviceType& device = DeviceType::GPU, const int& device_idx = -1);
141 DAOAI_API Classification(const std::filesystem::path& model_config_path, const std::filesystem::path& model_weights_path, const DeviceType& device = DeviceType::GPU, const int& device_idx = -1);
143 DAOAI_API std::vector<ClassificationResult> inference(const std::vector<Image>& images);
144 };
146 {
147 public:
148 DAOAI_API SupervisedDefectSegmentation(const std::filesystem::path& model_file, const DeviceType& device = DeviceType::GPU, const int& device_idx = -1);
149 DAOAI_API SupervisedDefectSegmentation(const std::filesystem::path& model_config_path, const std::filesystem::path& model_weights_path, const DeviceType& device = DeviceType::GPU, const int& device_idx = -1);
151 DAOAI_API std::vector<SupervisedDefectSegmentationResult> inference(const std::vector<Image>& images);
152 };
153 class AutoSegmentation final : public Model
154 {
155 public:
156 DAOAI_API AutoSegmentation(const std::filesystem::path& model_file, const DeviceType& device = DeviceType::GPU, const int& device_idx = -1);
157 DAOAI_API std::vector<ImageEmbedding> generateImageEmbeddings(const std::vector<Image>& images);
159 DAOAI_API std::vector<AutoSegmentationResult> inference(const std::vector<ImageEmbedding>& embeddings, const std::vector<std::vector<Box>>& boxes, const std::vector<std::vector<Point>>& points = std::vector<std::vector<Point>>());
160 DAOAI_API std::vector<AutoSegmentationResult> inference(const std::vector<ImageEmbedding>& embeddings, const std::vector<std::vector<Point>>& points);
161 DAOAI_API AutoSegmentationResult inference(const ImageEmbedding& embedding, const std::vector<Box>& boxes, const std::vector<Point>& points = std::vector<Point>());
162 DAOAI_API AutoSegmentationResult inference(const ImageEmbedding& embedding, const std::vector<Point>& points);
163 };
164
165#ifdef INDUSTRIAL
166 class PresenceChecking final : public Detection
167 {
168 public:
169 DAOAI_API PresenceChecking(const std::filesystem::path& model_file, const DeviceType& device = DeviceType::GPU, const int& device_idx = -1);
170 DAOAI_API PresenceChecking(const std::filesystem::path& model_config_path, const std::filesystem::path& model_weights_path, const DeviceType& device = DeviceType::GPU, const int& device_idx = -1);
172 DAOAI_API std::vector<PresenceCheckingResult> inference(const std::vector<Image>& images);
173 };
174
175 class Positioning final : public Detection
176 {
177 public:
178 DAOAI_API Positioning(const std::filesystem::path& model_file, const DeviceType& device = DeviceType::GPU, const int& device_idx = -1);
179 DAOAI_API Positioning(const std::filesystem::path& model_config_path, const std::filesystem::path& model_weights_path, const DeviceType& device = DeviceType::GPU, const int& device_idx = -1);
181 DAOAI_API std::vector<PositioningResult> inference(const std::vector<Image>& images);
182 };
183#endif // INDUSTRIAL
184 }
185 }
186}
#define DAOAI_API
Definition API_EXPORT.h:13
Definition common.h:181
Definition model.h:50
DAOAI_API ModelInfo getModelInfo()
virtual DAOAI_API ~Model()
std::shared_ptr< ModelInstance > model_instance_
Definition model.h:72
DAOAI_API void setBatchSize(const size_t &batch_size)
DAOAI_API size_t getBatchSize() const
Model(const std::filesystem::path &model_config_path, const std::filesystem::path &model_weights_path, const DaoAI::DeepLearning::DeviceType &device=DeviceType::GPU, const int &device_idx=-1)
Model(const std::filesystem::path &model_path, const DaoAI::DeepLearning::DeviceType &device=DeviceType::GPU, const int &device_idx=-1)
DAOAI_API std::vector< ImageEmbedding > generateImageEmbeddings(const std::vector< Image > &images)
DAOAI_API AutoSegmentationResult inference(const ImageEmbedding &embedding, const std::vector< Point > &points)
DAOAI_API std::vector< AutoSegmentationResult > inference(const std::vector< ImageEmbedding > &embeddings, const std::vector< std::vector< Point > > &points)
DAOAI_API AutoSegmentation(const std::filesystem::path &model_file, const DeviceType &device=DeviceType::GPU, const int &device_idx=-1)
DAOAI_API ImageEmbedding generateImageEmbeddings(const Image &image)
DAOAI_API std::vector< AutoSegmentationResult > inference(const std::vector< ImageEmbedding > &embeddings, const std::vector< std::vector< Box > > &boxes, const std::vector< std::vector< Point > > &points=std::vector< std::vector< Point > >())
DAOAI_API AutoSegmentationResult inference(const ImageEmbedding &embedding, const std::vector< Box > &boxes, const std::vector< Point > &points=std::vector< Point >())
DAOAI_API std::vector< ClassificationResult > inference(const std::vector< Image > &images)
DAOAI_API ClassificationResult inference(const Image &image)
DAOAI_API Classification(const std::filesystem::path &model_file, const DeviceType &device=DeviceType::GPU, const int &device_idx=-1)
DAOAI_API Classification(const std::filesystem::path &model_config_path, const std::filesystem::path &model_weights_path, const DeviceType &device=DeviceType::GPU, const int &device_idx=-1)
DAOAI_API void setIOUThreshold(const float &threshold)
DAOAI_API void setConfidenceThreshold(const float &threshold)
DAOAI_API float getConfidenceThreshold() const
DAOAI_API float getIOUThreshold() const
DAOAI_API InstanceSegmentation(const std::filesystem::path &model_file, const DeviceType &device=DeviceType::GPU, const int &device_idx=-1)
DAOAI_API InstanceSegmentation(const std::filesystem::path &model_config_path, const std::filesystem::path &model_weights_path, const DeviceType &device=DeviceType::GPU, const int &device_idx=-1)
DAOAI_API std::vector< InstanceSegmentationResult > inference(const std::vector< Image > &images)
DAOAI_API InstanceSegmentationResult inference(const Image &image)
DAOAI_API std::vector< KeypointDetectionResult > inference(const std::vector< Image > &images)
DAOAI_API KeypointDetection(const std::filesystem::path &model_config_path, const std::filesystem::path &model_weights_path, const DeviceType &device=DeviceType::GPU, const int &device_idx=-1)
DAOAI_API KeypointDetectionResult inference(const Image &image)
DAOAI_API KeypointDetection(const std::filesystem::path &model_file, const DeviceType &device=DeviceType::GPU, const int &device_idx=-1)
Definition model.h:130
DAOAI_API OCRResult inference(const Image &image)
DAOAI_API OCR(const std::filesystem::path &model_file, const DeviceType &device=DeviceType::GPU, const int &device_idx=-1)
DAOAI_API std::vector< OCRResult > inference(const std::vector< Image > &images)
DAOAI_API OCR(const std::filesystem::path &model_config_path, const std::filesystem::path &model_weights_path, const DeviceType &device=DeviceType::GPU, const int &device_idx=-1)
Definition prediction.h:97
DAOAI_API ObjectDetection(const std::filesystem::path &model_file, const DeviceType &device=DeviceType::GPU, const int &device_idx=-1)
DAOAI_API ObjectDetectionResult inference(const Image &image)
DAOAI_API std::vector< ObjectDetectionResult > inference(const std::vector< Image > &images)
DAOAI_API ObjectDetection(const std::filesystem::path &model_config_path, const std::filesystem::path &model_weights_path, const DeviceType &device=DeviceType::GPU, const int &device_idx=-1)
DAOAI_API Positioning(const std::filesystem::path &model_config_path, const std::filesystem::path &model_weights_path, const DeviceType &device=DeviceType::GPU, const int &device_idx=-1)
DAOAI_API Positioning(const std::filesystem::path &model_file, const DeviceType &device=DeviceType::GPU, const int &device_idx=-1)
DAOAI_API std::vector< PositioningResult > inference(const std::vector< Image > &images)
DAOAI_API PositioningResult inference(const Image &image)
DAOAI_API PresenceChecking(const std::filesystem::path &model_config_path, const std::filesystem::path &model_weights_path, const DeviceType &device=DeviceType::GPU, const int &device_idx=-1)
DAOAI_API PresenceChecking(const std::filesystem::path &model_file, const DeviceType &device=DeviceType::GPU, const int &device_idx=-1)
DAOAI_API PresenceCheckingResult inference(const Image &image)
DAOAI_API std::vector< PresenceCheckingResult > inference(const std::vector< Image > &images)
DAOAI_API std::vector< SupervisedDefectSegmentationResult > inference(const std::vector< Image > &images)
DAOAI_API SupervisedDefectSegmentation(const std::filesystem::path &model_file, const DeviceType &device=DeviceType::GPU, const int &device_idx=-1)
DAOAI_API SupervisedDefectSegmentation(const std::filesystem::path &model_config_path, const std::filesystem::path &model_weights_path, const DeviceType &device=DeviceType::GPU, const int &device_idx=-1)
DAOAI_API SupervisedDefectSegmentationResult inference(const Image &image)
DAOAI_API int getNumCUDADevices()
DeviceType
Definition common.h:18
ModelType
Definition model.h:18
DAOAI_API void clearGPUMemory()
DAOAI_API void initialize(const bool &use_shared_memory=false, const size_t &reserved_vram_size=500000000)
Definition common.h:14
Definition model.h:38
std::vector< std::string > keypoint_labels
Definition model.h:43
std::string extra_infos
Definition model.h:44
std::vector< std::string > class_labels
Definition model.h:41
std::vector< int > num_keypoints
Definition model.h:42
ModelType model_type
Definition model.h:39
DeviceType device
Definition model.h:40