DaoAI World C++ SDK INDUSTRIAL 2025.3.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: 2025.3.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"
12#include "component_memory.h"
13namespace DaoAI
14{
15
16 namespace DeepLearning
17 {
25
26 // Initialize DaoAI Deep Learning SDK
28
30
36
40 struct ModelInfo
41 {
44 std::vector<std::string> class_labels;
45 std::vector<int> num_keypoints;
46 std::vector<std::string> keypoint_labels;
47 std::string extra_infos = "";
48 std::vector<int> num_attributes;
49 };
50
51 class ModelInstance;
52
53 class Model
54 {
55 public:
56 Model() = default;
57
58 DAOAI_API virtual ~Model();
59
61
62 /*
63 * @brief Set the batch size for inference
64 * @param batch_size: the batch size for inference
65 */
66 DAOAI_API void setBatchSize(const size_t& batch_size);
67
68 /*
69 * @brief Get the batch size for inference
70 */
71 DAOAI_API size_t getBatchSize() const;
72
73 protected:
74 std::shared_ptr<ModelInstance> model_instance_ = nullptr;
75 };
76
77 class UnsupervisedDefectSegmentationImpl;
78
79 namespace Vision
80 {
81
82
83 class Detection : public Model
84 {
85 public:
86 using Model::Model;
87
88 /*
89 * @brief Set the threshold for how confident the model should be in its predictions
90 * @param threshold: the threshold for how confident the model should be in its predictions
91 */
92 DAOAI_API void setConfidenceThreshold(const float& threshold);
93
94 /*
95 * @brief Get the threshold for how confident the model should be in its predictions
96 */
98
99 /*
100 * @brief Set the threshold for the IOU between the predicted bounding box and the ground truth bounding box
101 * @param threshold: the threshold for the IOU between the predicted bounding box and the ground truth bounding box
102 */
103 DAOAI_API void setIOUThreshold(const float& threshold);
104
105 /*
106 * @brief Get the threshold for the IOU between the predicted bounding box and the ground truth bounding box
107 */
109 };
110
111 class ObjectDetection final : public Detection
112 {
113 public:
114 DAOAI_API ObjectDetection(const std::filesystem::path& model_file, const DeviceType& device = DeviceType::GPU, const int& device_idx = -1);
115 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);
117 DAOAI_API std::vector<ObjectDetectionResult> inference(const std::vector<Image>& images);
118 };
120 {
121 public:
122 DAOAI_API RotatedObjectDetection(const std::filesystem::path& model_file, const DeviceType& device = DeviceType::GPU, const int& device_idx = -1);
123 DAOAI_API RotatedObjectDetection(const std::filesystem::path& model_config_path, const std::filesystem::path& model_weights_path, const DeviceType& device = DeviceType::GPU, const int& device_idx = -1);
125 DAOAI_API std::vector<RotatedObjectDetectionResult> inference(const std::vector<Image>& images);
126 };
127 class InstanceSegmentation final : public Detection
128 {
129 public:
130 DAOAI_API InstanceSegmentation(const std::filesystem::path& model_file, const DeviceType& device = DeviceType::GPU, const int& device_idx = -1);
131 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);
133 DAOAI_API std::vector<InstanceSegmentationResult> inference(const std::vector<Image>& images);
134 };
135 class KeypointDetection final : public Detection
136 {
137 public:
138 DAOAI_API KeypointDetection(const std::filesystem::path& model_file, const DeviceType& device = DeviceType::GPU, const int& device_idx = -1);
139 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);
141 DAOAI_API std::vector<KeypointDetectionResult> inference(const std::vector<Image>& images);
142 };
143 class MultilabelDetection final : public Detection
144 {
145 public:
146 DAOAI_API MultilabelDetection(const std::filesystem::path& model_file, const DeviceType& device = DeviceType::GPU, const int& device_idx = -1);
147 DAOAI_API MultilabelDetection(const std::filesystem::path& model_config_path, const std::filesystem::path& model_weights_path, const DeviceType& device = DeviceType::GPU, const int& device_idx = -1);
149 DAOAI_API std::vector<MultilabelDetectionResult> inference(const std::vector<Image>& images);
150 };
151 class OCR final : public Model
152 {
153 public:
154 DAOAI_API OCR(const std::filesystem::path& model_file, const DeviceType& device = DeviceType::GPU, const int& device_idx = -1);
155 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);
157 DAOAI_API std::vector<OCRResult> inference(const std::vector<Image>& images);
158 };
159 class Classification final : public Model
160 {
161 public:
162 DAOAI_API Classification(const std::filesystem::path& model_file, const DeviceType& device = DeviceType::GPU, const int& device_idx = -1);
163 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);
165 DAOAI_API std::vector<ClassificationResult> inference(const std::vector<Image>& images);
166 };
168 {
169 public:
170 DAOAI_API SupervisedDefectSegmentation(const std::filesystem::path& model_file, const DeviceType& device = DeviceType::GPU, const int& device_idx = -1);
171 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);
173 DAOAI_API std::vector<SupervisedDefectSegmentationResult> inference(const std::vector<Image>& images);
174 };
175 class AutoSegmentation final : public Model
176 {
177 public:
178 DAOAI_API AutoSegmentation(const std::filesystem::path& model_file, const DeviceType& device = DeviceType::GPU, const int& device_idx = -1);
179 DAOAI_API std::vector<ImageEmbedding> generateImageEmbeddings(const std::vector<Image>& images);
181 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>>());
182 DAOAI_API std::vector<AutoSegmentationResult> inference(const std::vector<ImageEmbedding>& embeddings, const std::vector<std::vector<Point>>& points);
183 DAOAI_API AutoSegmentationResult inference(const ImageEmbedding& embedding, const std::vector<Box>& boxes, const std::vector<Point>& points = std::vector<Point>());
184 DAOAI_API AutoSegmentationResult inference(const ImageEmbedding& embedding, const std::vector<Point>& points);
185 };
186
187#ifdef INDUSTRIAL
188 class PresenceChecking final : public Detection
189 {
190 public:
191 DAOAI_API PresenceChecking(const std::filesystem::path& model_file, const DeviceType& device = DeviceType::GPU, const int& device_idx = -1);
192 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);
194 DAOAI_API std::vector<PresenceCheckingResult> inference(const std::vector<Image>& images);
195 };
196
197 class Positioning final : public Detection
198 {
199 public:
200 DAOAI_API Positioning(const std::filesystem::path& model_file, const DeviceType& device = DeviceType::GPU, const int& device_idx = -1);
201 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);
203 DAOAI_API std::vector<PositioningResult> inference(const std::vector<Image>& images);
204 };
205
206
208 {
209 public:
214
219
227 const Image& image, const std::string& component_name);
228
235 DAOAI_API std::vector<UnsupervisedDefectSegmentationResult> inference(
236 const std::vector<Image>& images,
237 const std::vector<std::string>& component_names);
238
239 DAOAI_API std::vector<UnsupervisedDefectSegmentationResult> inference(const std::vector<Image>& images);
240
242
248 DAOAI_API void addComponentMemory(const std::string& component_name, const std::filesystem::path& component_memory_file_path);
249
255 DAOAI_API void addComponentMemory(const std::string& component_name, const ComponentMemory& component_memory);
256
261 DAOAI_API void addComponentArchive(const std::string& archive_path);
262
267 DAOAI_API void removeComponentMemory(const std::string& component_name);
268
273 DAOAI_API std::unordered_map<std::string, ComponentMemory> listComponentMemory();
274
280
287 DAOAI_API ComponentMemory createComponentMemory(const std::string& component_name, const std::vector<Image>& good_images, const std::vector<Image>& bad_images = {}, const std::vector<Image>& masks = {}, const bool& append_memory = false);
288 };
289#endif // INDUSTRIAL
290 }
291 }
292}
#define DAOAI_API
Definition API_EXPORT.h:13
Definition component_memory.h:19
Definition common.h:189
Definition model.h:54
DAOAI_API ModelInfo getModelInfo()
virtual DAOAI_API ~Model()
std::shared_ptr< ModelInstance > model_instance_
Definition model.h:74
DAOAI_API void setBatchSize(const size_t &batch_size)
DAOAI_API size_t getBatchSize() const
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)
DAOAI_API MultilabelDetection(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 MultilabelDetectionResult inference(const Image &image)
DAOAI_API std::vector< MultilabelDetectionResult > inference(const std::vector< Image > &images)
DAOAI_API MultilabelDetection(const std::filesystem::path &model_file, const DeviceType &device=DeviceType::GPU, const int &device_idx=-1)
Definition model.h:152
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:115
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< RotatedObjectDetectionResult > inference(const std::vector< Image > &images)
DAOAI_API RotatedObjectDetectionResult inference(const Image &image)
DAOAI_API RotatedObjectDetection(const std::filesystem::path &model_file, const DeviceType &device=DeviceType::GPU, const int &device_idx=-1)
DAOAI_API RotatedObjectDetection(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< 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 void addComponentMemory(const std::string &component_name, const ComponentMemory &component_memory)
Add a component memory to the component memory list.
DAOAI_API std::vector< UnsupervisedDefectSegmentationResult > inference(const std::vector< Image > &images, const std::vector< std::string > &component_names)
Inference function for unsupervised defect segmentation.
DAOAI_API void removeComponentMemory(const std::string &component_name)
Remove a component memory from the component memory list.
DAOAI_API std::vector< UnsupervisedDefectSegmentationResult > inference(const std::vector< Image > &images)
DAOAI_API UnsupervisedDefectSegmentationResult inference(const Image &image, const std::string &component_name)
Inference function for unsupervised defect segmentation.
DAOAI_API UnsupervisedDefectSegmentation(const DeviceType &device)
Constructor.
DAOAI_API void addComponentMemory(const std::string &component_name, const std::filesystem::path &component_memory_file_path)
Add a component memory to the component memory list.
DAOAI_API void setDetectionLevel(const DetectionLevel &value)
Set the detection level for the base model, whether image-level or pixel-level.
DAOAI_API UnsupervisedDefectSegmentationResult inference(const Image &image)
DAOAI_API std::unordered_map< std::string, ComponentMemory > listComponentMemory()
Get the list of component memory objects.
DAOAI_API void addComponentArchive(const std::string &archive_path)
Add a component memory archive to the component memory list.
DAOAI_API ComponentMemory createComponentMemory(const std::string &component_name, const std::vector< Image > &good_images, const std::vector< Image > &bad_images={}, const std::vector< Image > &masks={}, const bool &append_memory=false)
Train a component memory.
DetectionLevel
Definition common.h:25
DAOAI_API int getNumCUDADevices()
DeviceType
Definition common.h:18
ModelType
Definition model.h:19
DAOAI_API void clearGPUMemory()
DAOAI_API void initialize()
Definition common.h:14
: Deprecated and not reliable, will be removed in the future
Definition model.h:41
std::vector< std::string > keypoint_labels
Definition model.h:46
std::string extra_infos
Definition model.h:47
std::vector< std::string > class_labels
Definition model.h:44
std::vector< int > num_keypoints
Definition model.h:45
std::vector< int > num_attributes
Definition model.h:48
ModelType model_type
Definition model.h:42
DeviceType device
Definition model.h:43