dgenerate-ultralytics-headless 8.3.222__py3-none-any.whl → 8.3.225__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dgenerate_ultralytics_headless-8.3.222.dist-info → dgenerate_ultralytics_headless-8.3.225.dist-info}/METADATA +2 -2
- dgenerate_ultralytics_headless-8.3.225.dist-info/RECORD +286 -0
- tests/conftest.py +5 -8
- tests/test_cli.py +1 -8
- tests/test_python.py +1 -2
- ultralytics/__init__.py +1 -1
- ultralytics/cfg/__init__.py +34 -49
- ultralytics/cfg/datasets/ImageNet.yaml +1 -1
- ultralytics/cfg/datasets/kitti.yaml +27 -0
- ultralytics/cfg/datasets/lvis.yaml +5 -5
- ultralytics/cfg/datasets/open-images-v7.yaml +1 -1
- ultralytics/data/annotator.py +3 -4
- ultralytics/data/augment.py +244 -323
- ultralytics/data/base.py +12 -22
- ultralytics/data/build.py +47 -40
- ultralytics/data/converter.py +32 -42
- ultralytics/data/dataset.py +43 -71
- ultralytics/data/loaders.py +22 -34
- ultralytics/data/split.py +5 -6
- ultralytics/data/split_dota.py +8 -15
- ultralytics/data/utils.py +27 -36
- ultralytics/engine/exporter.py +49 -116
- ultralytics/engine/model.py +144 -180
- ultralytics/engine/predictor.py +18 -29
- ultralytics/engine/results.py +165 -231
- ultralytics/engine/trainer.py +11 -19
- ultralytics/engine/tuner.py +13 -23
- ultralytics/engine/validator.py +6 -10
- ultralytics/hub/__init__.py +7 -12
- ultralytics/hub/auth.py +6 -12
- ultralytics/hub/google/__init__.py +7 -10
- ultralytics/hub/session.py +15 -25
- ultralytics/hub/utils.py +3 -6
- ultralytics/models/fastsam/model.py +6 -8
- ultralytics/models/fastsam/predict.py +5 -10
- ultralytics/models/fastsam/utils.py +1 -2
- ultralytics/models/fastsam/val.py +2 -4
- ultralytics/models/nas/model.py +5 -8
- ultralytics/models/nas/predict.py +7 -9
- ultralytics/models/nas/val.py +1 -2
- ultralytics/models/rtdetr/model.py +5 -8
- ultralytics/models/rtdetr/predict.py +15 -18
- ultralytics/models/rtdetr/train.py +10 -13
- ultralytics/models/rtdetr/val.py +13 -20
- ultralytics/models/sam/amg.py +12 -18
- ultralytics/models/sam/build.py +6 -9
- ultralytics/models/sam/model.py +16 -23
- ultralytics/models/sam/modules/blocks.py +62 -84
- ultralytics/models/sam/modules/decoders.py +17 -24
- ultralytics/models/sam/modules/encoders.py +40 -56
- ultralytics/models/sam/modules/memory_attention.py +10 -16
- ultralytics/models/sam/modules/sam.py +41 -47
- ultralytics/models/sam/modules/tiny_encoder.py +64 -83
- ultralytics/models/sam/modules/transformer.py +17 -27
- ultralytics/models/sam/modules/utils.py +31 -42
- ultralytics/models/sam/predict.py +172 -209
- ultralytics/models/utils/loss.py +14 -26
- ultralytics/models/utils/ops.py +13 -17
- ultralytics/models/yolo/classify/predict.py +8 -11
- ultralytics/models/yolo/classify/train.py +8 -16
- ultralytics/models/yolo/classify/val.py +13 -20
- ultralytics/models/yolo/detect/predict.py +4 -8
- ultralytics/models/yolo/detect/train.py +11 -20
- ultralytics/models/yolo/detect/val.py +38 -48
- ultralytics/models/yolo/model.py +35 -47
- ultralytics/models/yolo/obb/predict.py +5 -8
- ultralytics/models/yolo/obb/train.py +11 -14
- ultralytics/models/yolo/obb/val.py +20 -28
- ultralytics/models/yolo/pose/predict.py +5 -8
- ultralytics/models/yolo/pose/train.py +4 -8
- ultralytics/models/yolo/pose/val.py +31 -39
- ultralytics/models/yolo/segment/predict.py +9 -14
- ultralytics/models/yolo/segment/train.py +3 -6
- ultralytics/models/yolo/segment/val.py +16 -26
- ultralytics/models/yolo/world/train.py +8 -14
- ultralytics/models/yolo/world/train_world.py +11 -16
- ultralytics/models/yolo/yoloe/predict.py +16 -23
- ultralytics/models/yolo/yoloe/train.py +30 -43
- ultralytics/models/yolo/yoloe/train_seg.py +5 -10
- ultralytics/models/yolo/yoloe/val.py +15 -20
- ultralytics/nn/autobackend.py +10 -18
- ultralytics/nn/modules/activation.py +4 -6
- ultralytics/nn/modules/block.py +99 -185
- ultralytics/nn/modules/conv.py +45 -90
- ultralytics/nn/modules/head.py +44 -98
- ultralytics/nn/modules/transformer.py +44 -76
- ultralytics/nn/modules/utils.py +14 -19
- ultralytics/nn/tasks.py +86 -146
- ultralytics/nn/text_model.py +25 -40
- ultralytics/solutions/ai_gym.py +10 -16
- ultralytics/solutions/analytics.py +7 -10
- ultralytics/solutions/config.py +4 -5
- ultralytics/solutions/distance_calculation.py +9 -12
- ultralytics/solutions/heatmap.py +7 -13
- ultralytics/solutions/instance_segmentation.py +5 -8
- ultralytics/solutions/object_blurrer.py +7 -10
- ultralytics/solutions/object_counter.py +8 -12
- ultralytics/solutions/object_cropper.py +5 -8
- ultralytics/solutions/parking_management.py +12 -14
- ultralytics/solutions/queue_management.py +4 -6
- ultralytics/solutions/region_counter.py +7 -10
- ultralytics/solutions/security_alarm.py +14 -19
- ultralytics/solutions/similarity_search.py +7 -12
- ultralytics/solutions/solutions.py +31 -53
- ultralytics/solutions/speed_estimation.py +6 -9
- ultralytics/solutions/streamlit_inference.py +2 -4
- ultralytics/solutions/trackzone.py +7 -10
- ultralytics/solutions/vision_eye.py +5 -8
- ultralytics/trackers/basetrack.py +2 -4
- ultralytics/trackers/bot_sort.py +6 -11
- ultralytics/trackers/byte_tracker.py +10 -15
- ultralytics/trackers/track.py +3 -6
- ultralytics/trackers/utils/gmc.py +6 -12
- ultralytics/trackers/utils/kalman_filter.py +35 -43
- ultralytics/trackers/utils/matching.py +6 -10
- ultralytics/utils/__init__.py +61 -100
- ultralytics/utils/autobatch.py +2 -4
- ultralytics/utils/autodevice.py +11 -13
- ultralytics/utils/benchmarks.py +25 -35
- ultralytics/utils/callbacks/base.py +8 -10
- ultralytics/utils/callbacks/clearml.py +2 -4
- ultralytics/utils/callbacks/comet.py +30 -44
- ultralytics/utils/callbacks/dvc.py +13 -18
- ultralytics/utils/callbacks/mlflow.py +4 -5
- ultralytics/utils/callbacks/neptune.py +4 -6
- ultralytics/utils/callbacks/raytune.py +3 -4
- ultralytics/utils/callbacks/tensorboard.py +4 -6
- ultralytics/utils/callbacks/wb.py +10 -13
- ultralytics/utils/checks.py +29 -56
- ultralytics/utils/cpu.py +1 -2
- ultralytics/utils/dist.py +8 -12
- ultralytics/utils/downloads.py +17 -27
- ultralytics/utils/errors.py +6 -8
- ultralytics/utils/events.py +2 -4
- ultralytics/utils/export/__init__.py +4 -239
- ultralytics/utils/export/engine.py +237 -0
- ultralytics/utils/export/imx.py +11 -17
- ultralytics/utils/export/tensorflow.py +217 -0
- ultralytics/utils/files.py +10 -15
- ultralytics/utils/git.py +5 -7
- ultralytics/utils/instance.py +30 -51
- ultralytics/utils/logger.py +11 -15
- ultralytics/utils/loss.py +8 -14
- ultralytics/utils/metrics.py +98 -138
- ultralytics/utils/nms.py +13 -16
- ultralytics/utils/ops.py +47 -74
- ultralytics/utils/patches.py +11 -18
- ultralytics/utils/plotting.py +29 -42
- ultralytics/utils/tal.py +25 -39
- ultralytics/utils/torch_utils.py +45 -73
- ultralytics/utils/tqdm.py +6 -8
- ultralytics/utils/triton.py +9 -12
- ultralytics/utils/tuner.py +1 -2
- dgenerate_ultralytics_headless-8.3.222.dist-info/RECORD +0 -283
- {dgenerate_ultralytics_headless-8.3.222.dist-info → dgenerate_ultralytics_headless-8.3.225.dist-info}/WHEEL +0 -0
- {dgenerate_ultralytics_headless-8.3.222.dist-info → dgenerate_ultralytics_headless-8.3.225.dist-info}/entry_points.txt +0 -0
- {dgenerate_ultralytics_headless-8.3.222.dist-info → dgenerate_ultralytics_headless-8.3.225.dist-info}/licenses/LICENSE +0 -0
- {dgenerate_ultralytics_headless-8.3.222.dist-info → dgenerate_ultralytics_headless-8.3.225.dist-info}/top_level.txt +0 -0
|
@@ -19,11 +19,10 @@ from .val import YOLOEDetectValidator
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
class YOLOETrainer(DetectionTrainer):
|
|
22
|
-
"""
|
|
23
|
-
A trainer class for YOLOE object detection models.
|
|
22
|
+
"""A trainer class for YOLOE object detection models.
|
|
24
23
|
|
|
25
|
-
This class extends DetectionTrainer to provide specialized training functionality for YOLOE models,
|
|
26
|
-
|
|
24
|
+
This class extends DetectionTrainer to provide specialized training functionality for YOLOE models, including custom
|
|
25
|
+
model initialization, validation, and dataset building with multi-modal support.
|
|
27
26
|
|
|
28
27
|
Attributes:
|
|
29
28
|
loss_names (tuple): Names of loss components used during training.
|
|
@@ -35,8 +34,7 @@ class YOLOETrainer(DetectionTrainer):
|
|
|
35
34
|
"""
|
|
36
35
|
|
|
37
36
|
def __init__(self, cfg=DEFAULT_CFG, overrides: dict | None = None, _callbacks=None):
|
|
38
|
-
"""
|
|
39
|
-
Initialize the YOLOE Trainer with specified configurations.
|
|
37
|
+
"""Initialize the YOLOE Trainer with specified configurations.
|
|
40
38
|
|
|
41
39
|
Args:
|
|
42
40
|
cfg (dict): Configuration dictionary with default training settings from DEFAULT_CFG.
|
|
@@ -50,12 +48,11 @@ class YOLOETrainer(DetectionTrainer):
|
|
|
50
48
|
super().__init__(cfg, overrides, _callbacks)
|
|
51
49
|
|
|
52
50
|
def get_model(self, cfg=None, weights=None, verbose: bool = True):
|
|
53
|
-
"""
|
|
54
|
-
Return a YOLOEModel initialized with the specified configuration and weights.
|
|
51
|
+
"""Return a YOLOEModel initialized with the specified configuration and weights.
|
|
55
52
|
|
|
56
53
|
Args:
|
|
57
|
-
cfg (dict | str, optional): Model configuration. Can be a dictionary containing a 'yaml_file' key,
|
|
58
|
-
|
|
54
|
+
cfg (dict | str, optional): Model configuration. Can be a dictionary containing a 'yaml_file' key, a direct
|
|
55
|
+
path to a YAML file, or None to use default configuration.
|
|
59
56
|
weights (str | Path, optional): Path to pretrained weights file to load into the model.
|
|
60
57
|
verbose (bool): Whether to display model information during initialization.
|
|
61
58
|
|
|
@@ -88,8 +85,7 @@ class YOLOETrainer(DetectionTrainer):
|
|
|
88
85
|
)
|
|
89
86
|
|
|
90
87
|
def build_dataset(self, img_path: str, mode: str = "train", batch: int | None = None):
|
|
91
|
-
"""
|
|
92
|
-
Build YOLO Dataset.
|
|
88
|
+
"""Build YOLO Dataset.
|
|
93
89
|
|
|
94
90
|
Args:
|
|
95
91
|
img_path (str): Path to the folder containing images.
|
|
@@ -106,19 +102,17 @@ class YOLOETrainer(DetectionTrainer):
|
|
|
106
102
|
|
|
107
103
|
|
|
108
104
|
class YOLOEPETrainer(DetectionTrainer):
|
|
109
|
-
"""
|
|
110
|
-
Fine-tune YOLOE model using linear probing approach.
|
|
105
|
+
"""Fine-tune YOLOE model using linear probing approach.
|
|
111
106
|
|
|
112
|
-
This trainer freezes most model layers and only trains specific projection layers for efficient
|
|
113
|
-
|
|
107
|
+
This trainer freezes most model layers and only trains specific projection layers for efficient fine-tuning on new
|
|
108
|
+
datasets while preserving pretrained features.
|
|
114
109
|
|
|
115
110
|
Methods:
|
|
116
111
|
get_model: Initialize YOLOEModel with frozen layers except projection layers.
|
|
117
112
|
"""
|
|
118
113
|
|
|
119
114
|
def get_model(self, cfg=None, weights=None, verbose: bool = True):
|
|
120
|
-
"""
|
|
121
|
-
Return YOLOEModel initialized with specified config and weights.
|
|
115
|
+
"""Return YOLOEModel initialized with specified config and weights.
|
|
122
116
|
|
|
123
117
|
Args:
|
|
124
118
|
cfg (dict | str, optional): Model configuration.
|
|
@@ -160,11 +154,10 @@ class YOLOEPETrainer(DetectionTrainer):
|
|
|
160
154
|
|
|
161
155
|
|
|
162
156
|
class YOLOETrainerFromScratch(YOLOETrainer, WorldTrainerFromScratch):
|
|
163
|
-
"""
|
|
164
|
-
Train YOLOE models from scratch with text embedding support.
|
|
157
|
+
"""Train YOLOE models from scratch with text embedding support.
|
|
165
158
|
|
|
166
|
-
This trainer combines YOLOE training capabilities with world training features, enabling
|
|
167
|
-
|
|
159
|
+
This trainer combines YOLOE training capabilities with world training features, enabling training from scratch with
|
|
160
|
+
text embeddings and grounding datasets.
|
|
168
161
|
|
|
169
162
|
Methods:
|
|
170
163
|
build_dataset: Build datasets for training with grounding support.
|
|
@@ -172,11 +165,10 @@ class YOLOETrainerFromScratch(YOLOETrainer, WorldTrainerFromScratch):
|
|
|
172
165
|
"""
|
|
173
166
|
|
|
174
167
|
def build_dataset(self, img_path: list[str] | str, mode: str = "train", batch: int | None = None):
|
|
175
|
-
"""
|
|
176
|
-
Build YOLO Dataset for training or validation.
|
|
168
|
+
"""Build YOLO Dataset for training or validation.
|
|
177
169
|
|
|
178
|
-
This method constructs appropriate datasets based on the mode and input paths, handling both
|
|
179
|
-
|
|
170
|
+
This method constructs appropriate datasets based on the mode and input paths, handling both standard YOLO
|
|
171
|
+
datasets and grounding datasets with different formats.
|
|
180
172
|
|
|
181
173
|
Args:
|
|
182
174
|
img_path (list[str] | str): Path to the folder containing images or list of paths.
|
|
@@ -189,8 +181,7 @@ class YOLOETrainerFromScratch(YOLOETrainer, WorldTrainerFromScratch):
|
|
|
189
181
|
return WorldTrainerFromScratch.build_dataset(self, img_path, mode, batch)
|
|
190
182
|
|
|
191
183
|
def generate_text_embeddings(self, texts: list[str], batch: int, cache_dir: Path):
|
|
192
|
-
"""
|
|
193
|
-
Generate text embeddings for a list of text samples.
|
|
184
|
+
"""Generate text embeddings for a list of text samples.
|
|
194
185
|
|
|
195
186
|
Args:
|
|
196
187
|
texts (list[str]): List of text samples to encode.
|
|
@@ -216,11 +207,10 @@ class YOLOETrainerFromScratch(YOLOETrainer, WorldTrainerFromScratch):
|
|
|
216
207
|
|
|
217
208
|
|
|
218
209
|
class YOLOEPEFreeTrainer(YOLOEPETrainer, YOLOETrainerFromScratch):
|
|
219
|
-
"""
|
|
220
|
-
Train prompt-free YOLOE model.
|
|
210
|
+
"""Train prompt-free YOLOE model.
|
|
221
211
|
|
|
222
|
-
This trainer combines linear probing capabilities with from-scratch training for prompt-free
|
|
223
|
-
|
|
212
|
+
This trainer combines linear probing capabilities with from-scratch training for prompt-free YOLOE models that don't
|
|
213
|
+
require text prompts during inference.
|
|
224
214
|
|
|
225
215
|
Methods:
|
|
226
216
|
get_validator: Return standard DetectionValidator for validation.
|
|
@@ -240,12 +230,11 @@ class YOLOEPEFreeTrainer(YOLOEPETrainer, YOLOETrainerFromScratch):
|
|
|
240
230
|
return DetectionTrainer.preprocess_batch(self, batch)
|
|
241
231
|
|
|
242
232
|
def set_text_embeddings(self, datasets, batch: int):
|
|
243
|
-
"""
|
|
244
|
-
Set text embeddings for datasets to accelerate training by caching category names.
|
|
233
|
+
"""Set text embeddings for datasets to accelerate training by caching category names.
|
|
245
234
|
|
|
246
|
-
This method collects unique category names from all datasets, generates text embeddings for them,
|
|
247
|
-
|
|
248
|
-
|
|
235
|
+
This method collects unique category names from all datasets, generates text embeddings for them, and caches
|
|
236
|
+
these embeddings to improve training efficiency. The embeddings are stored in a file in the parent directory of
|
|
237
|
+
the first dataset's image path.
|
|
249
238
|
|
|
250
239
|
Args:
|
|
251
240
|
datasets (list[Dataset]): List of datasets containing category names to process.
|
|
@@ -260,19 +249,17 @@ class YOLOEPEFreeTrainer(YOLOEPETrainer, YOLOETrainerFromScratch):
|
|
|
260
249
|
|
|
261
250
|
|
|
262
251
|
class YOLOEVPTrainer(YOLOETrainerFromScratch):
|
|
263
|
-
"""
|
|
264
|
-
Train YOLOE model with visual prompts.
|
|
252
|
+
"""Train YOLOE model with visual prompts.
|
|
265
253
|
|
|
266
|
-
This trainer extends YOLOETrainerFromScratch to support visual prompt-based training,
|
|
267
|
-
|
|
254
|
+
This trainer extends YOLOETrainerFromScratch to support visual prompt-based training, where visual cues are provided
|
|
255
|
+
alongside images to guide the detection process.
|
|
268
256
|
|
|
269
257
|
Methods:
|
|
270
258
|
build_dataset: Build dataset with visual prompt loading transforms.
|
|
271
259
|
"""
|
|
272
260
|
|
|
273
261
|
def build_dataset(self, img_path: list[str] | str, mode: str = "train", batch: int | None = None):
|
|
274
|
-
"""
|
|
275
|
-
Build YOLO Dataset for training or validation with visual prompts.
|
|
262
|
+
"""Build YOLO Dataset for training or validation with visual prompts.
|
|
276
263
|
|
|
277
264
|
Args:
|
|
278
265
|
img_path (list[str] | str): Path to the folder containing images or list of paths.
|
|
@@ -11,8 +11,7 @@ from .val import YOLOESegValidator
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
class YOLOESegTrainer(YOLOETrainer, SegmentationTrainer):
|
|
14
|
-
"""
|
|
15
|
-
Trainer class for YOLOE segmentation models.
|
|
14
|
+
"""Trainer class for YOLOE segmentation models.
|
|
16
15
|
|
|
17
16
|
This class combines YOLOETrainer and SegmentationTrainer to provide training functionality specifically for YOLOE
|
|
18
17
|
segmentation models, enabling both object detection and instance segmentation capabilities.
|
|
@@ -24,8 +23,7 @@ class YOLOESegTrainer(YOLOETrainer, SegmentationTrainer):
|
|
|
24
23
|
"""
|
|
25
24
|
|
|
26
25
|
def get_model(self, cfg=None, weights=None, verbose=True):
|
|
27
|
-
"""
|
|
28
|
-
Return YOLOESegModel initialized with specified config and weights.
|
|
26
|
+
"""Return YOLOESegModel initialized with specified config and weights.
|
|
29
27
|
|
|
30
28
|
Args:
|
|
31
29
|
cfg (dict | str, optional): Model configuration dictionary or YAML file path.
|
|
@@ -49,8 +47,7 @@ class YOLOESegTrainer(YOLOETrainer, SegmentationTrainer):
|
|
|
49
47
|
return model
|
|
50
48
|
|
|
51
49
|
def get_validator(self):
|
|
52
|
-
"""
|
|
53
|
-
Create and return a validator for YOLOE segmentation model evaluation.
|
|
50
|
+
"""Create and return a validator for YOLOE segmentation model evaluation.
|
|
54
51
|
|
|
55
52
|
Returns:
|
|
56
53
|
(YOLOESegValidator): Validator for YOLOE segmentation models.
|
|
@@ -62,8 +59,7 @@ class YOLOESegTrainer(YOLOETrainer, SegmentationTrainer):
|
|
|
62
59
|
|
|
63
60
|
|
|
64
61
|
class YOLOEPESegTrainer(SegmentationTrainer):
|
|
65
|
-
"""
|
|
66
|
-
Fine-tune YOLOESeg model in linear probing way.
|
|
62
|
+
"""Fine-tune YOLOESeg model in linear probing way.
|
|
67
63
|
|
|
68
64
|
This trainer specializes in fine-tuning YOLOESeg models using a linear probing approach, which involves freezing
|
|
69
65
|
most of the model and only training specific layers for efficient adaptation to new tasks.
|
|
@@ -73,8 +69,7 @@ class YOLOEPESegTrainer(SegmentationTrainer):
|
|
|
73
69
|
"""
|
|
74
70
|
|
|
75
71
|
def get_model(self, cfg=None, weights=None, verbose=True):
|
|
76
|
-
"""
|
|
77
|
-
Return YOLOESegModel initialized with specified config and weights for linear probing.
|
|
72
|
+
"""Return YOLOESegModel initialized with specified config and weights for linear probing.
|
|
78
73
|
|
|
79
74
|
Args:
|
|
80
75
|
cfg (dict | str, optional): Model configuration dictionary or YAML file path.
|
|
@@ -21,12 +21,11 @@ from ultralytics.utils.torch_utils import select_device, smart_inference_mode
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
class YOLOEDetectValidator(DetectionValidator):
|
|
24
|
-
"""
|
|
25
|
-
A validator class for YOLOE detection models that handles both text and visual prompt embeddings.
|
|
24
|
+
"""A validator class for YOLOE detection models that handles both text and visual prompt embeddings.
|
|
26
25
|
|
|
27
|
-
This class extends DetectionValidator to provide specialized validation functionality for YOLOE models.
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
This class extends DetectionValidator to provide specialized validation functionality for YOLOE models. It supports
|
|
27
|
+
validation using either text prompts or visual prompt embeddings extracted from training samples, enabling flexible
|
|
28
|
+
evaluation strategies for prompt-based object detection.
|
|
30
29
|
|
|
31
30
|
Attributes:
|
|
32
31
|
device (torch.device): The device on which validation is performed.
|
|
@@ -50,12 +49,11 @@ class YOLOEDetectValidator(DetectionValidator):
|
|
|
50
49
|
|
|
51
50
|
@smart_inference_mode()
|
|
52
51
|
def get_visual_pe(self, dataloader: torch.utils.data.DataLoader, model: YOLOEModel) -> torch.Tensor:
|
|
53
|
-
"""
|
|
54
|
-
Extract visual prompt embeddings from training samples.
|
|
52
|
+
"""Extract visual prompt embeddings from training samples.
|
|
55
53
|
|
|
56
|
-
This method processes a dataloader to compute visual prompt embeddings for each class using a YOLOE model.
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
This method processes a dataloader to compute visual prompt embeddings for each class using a YOLOE model. It
|
|
55
|
+
normalizes the embeddings and handles cases where no samples exist for a class by setting their embeddings to
|
|
56
|
+
zero.
|
|
59
57
|
|
|
60
58
|
Args:
|
|
61
59
|
dataloader (torch.utils.data.DataLoader): The dataloader providing training samples.
|
|
@@ -99,12 +97,10 @@ class YOLOEDetectValidator(DetectionValidator):
|
|
|
99
97
|
return visual_pe.unsqueeze(0)
|
|
100
98
|
|
|
101
99
|
def get_vpe_dataloader(self, data: dict[str, Any]) -> torch.utils.data.DataLoader:
|
|
102
|
-
"""
|
|
103
|
-
Create a dataloader for LVIS training visual prompt samples.
|
|
100
|
+
"""Create a dataloader for LVIS training visual prompt samples.
|
|
104
101
|
|
|
105
|
-
This method prepares a dataloader for visual prompt embeddings (VPE) using the specified dataset.
|
|
106
|
-
|
|
107
|
-
for validation purposes.
|
|
102
|
+
This method prepares a dataloader for visual prompt embeddings (VPE) using the specified dataset. It applies
|
|
103
|
+
necessary transformations including LoadVisualPrompt and configurations to the dataset for validation purposes.
|
|
108
104
|
|
|
109
105
|
Args:
|
|
110
106
|
data (dict): Dataset configuration dictionary containing paths and settings.
|
|
@@ -141,12 +137,11 @@ class YOLOEDetectValidator(DetectionValidator):
|
|
|
141
137
|
refer_data: str | None = None,
|
|
142
138
|
load_vp: bool = False,
|
|
143
139
|
) -> dict[str, Any]:
|
|
144
|
-
"""
|
|
145
|
-
Run validation on the model using either text or visual prompt embeddings.
|
|
140
|
+
"""Run validation on the model using either text or visual prompt embeddings.
|
|
146
141
|
|
|
147
|
-
This method validates the model using either text prompts or visual prompts, depending on the load_vp flag.
|
|
148
|
-
|
|
149
|
-
|
|
142
|
+
This method validates the model using either text prompts or visual prompts, depending on the load_vp flag. It
|
|
143
|
+
supports validation during training (using a trainer object) or standalone validation with a provided model. For
|
|
144
|
+
visual prompts, reference data can be specified to extract embeddings from a different dataset.
|
|
150
145
|
|
|
151
146
|
Args:
|
|
152
147
|
trainer (object, optional): Trainer object containing the model and device.
|
ultralytics/nn/autobackend.py
CHANGED
|
@@ -23,8 +23,7 @@ from ultralytics.utils.nms import non_max_suppression
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
def check_class_names(names: list | dict) -> dict[int, str]:
|
|
26
|
-
"""
|
|
27
|
-
Check class names and convert to dict format if needed.
|
|
26
|
+
"""Check class names and convert to dict format if needed.
|
|
28
27
|
|
|
29
28
|
Args:
|
|
30
29
|
names (list | dict): Class names as list or dict format.
|
|
@@ -53,8 +52,7 @@ def check_class_names(names: list | dict) -> dict[int, str]:
|
|
|
53
52
|
|
|
54
53
|
|
|
55
54
|
def default_class_names(data: str | Path | None = None) -> dict[int, str]:
|
|
56
|
-
"""
|
|
57
|
-
Apply default class names to an input YAML file or return numerical class names.
|
|
55
|
+
"""Apply default class names to an input YAML file or return numerical class names.
|
|
58
56
|
|
|
59
57
|
Args:
|
|
60
58
|
data (str | Path, optional): Path to YAML file containing class names.
|
|
@@ -71,8 +69,7 @@ def default_class_names(data: str | Path | None = None) -> dict[int, str]:
|
|
|
71
69
|
|
|
72
70
|
|
|
73
71
|
class AutoBackend(nn.Module):
|
|
74
|
-
"""
|
|
75
|
-
Handle dynamic backend selection for running inference using Ultralytics YOLO models.
|
|
72
|
+
"""Handle dynamic backend selection for running inference using Ultralytics YOLO models.
|
|
76
73
|
|
|
77
74
|
The AutoBackend class is designed to provide an abstraction layer for various inference engines. It supports a wide
|
|
78
75
|
range of formats, each with specific naming conventions as outlined below:
|
|
@@ -148,8 +145,7 @@ class AutoBackend(nn.Module):
|
|
|
148
145
|
fuse: bool = True,
|
|
149
146
|
verbose: bool = True,
|
|
150
147
|
):
|
|
151
|
-
"""
|
|
152
|
-
Initialize the AutoBackend for inference.
|
|
148
|
+
"""Initialize the AutoBackend for inference.
|
|
153
149
|
|
|
154
150
|
Args:
|
|
155
151
|
model (str | torch.nn.Module): Path to the model weights file or a module instance.
|
|
@@ -249,7 +245,7 @@ class AutoBackend(nn.Module):
|
|
|
249
245
|
providers = ["CPUExecutionProvider"]
|
|
250
246
|
if cuda:
|
|
251
247
|
if "CUDAExecutionProvider" in onnxruntime.get_available_providers():
|
|
252
|
-
providers.insert(0, "CUDAExecutionProvider")
|
|
248
|
+
providers.insert(0, ("CUDAExecutionProvider", {"device_id": device.index}))
|
|
253
249
|
else: # Only log warning if CUDA was requested but unavailable
|
|
254
250
|
LOGGER.warning("Failed to start ONNX Runtime with CUDA. Using CPU...")
|
|
255
251
|
device = torch.device("cpu")
|
|
@@ -428,7 +424,7 @@ class AutoBackend(nn.Module):
|
|
|
428
424
|
LOGGER.info(f"Loading {w} for TensorFlow GraphDef inference...")
|
|
429
425
|
import tensorflow as tf
|
|
430
426
|
|
|
431
|
-
from ultralytics.
|
|
427
|
+
from ultralytics.utils.export.tensorflow import gd_outputs
|
|
432
428
|
|
|
433
429
|
def wrap_frozen_graph(gd, inputs, outputs):
|
|
434
430
|
"""Wrap frozen graphs for deployment."""
|
|
@@ -639,8 +635,7 @@ class AutoBackend(nn.Module):
|
|
|
639
635
|
embed: list | None = None,
|
|
640
636
|
**kwargs: Any,
|
|
641
637
|
) -> torch.Tensor | list[torch.Tensor]:
|
|
642
|
-
"""
|
|
643
|
-
Run inference on an AutoBackend model.
|
|
638
|
+
"""Run inference on an AutoBackend model.
|
|
644
639
|
|
|
645
640
|
Args:
|
|
646
641
|
im (torch.Tensor): The image tensor to perform inference on.
|
|
@@ -860,8 +855,7 @@ class AutoBackend(nn.Module):
|
|
|
860
855
|
return self.from_numpy(y)
|
|
861
856
|
|
|
862
857
|
def from_numpy(self, x: np.ndarray) -> torch.Tensor:
|
|
863
|
-
"""
|
|
864
|
-
Convert a numpy array to a tensor.
|
|
858
|
+
"""Convert a numpy array to a tensor.
|
|
865
859
|
|
|
866
860
|
Args:
|
|
867
861
|
x (np.ndarray): The array to be converted.
|
|
@@ -872,8 +866,7 @@ class AutoBackend(nn.Module):
|
|
|
872
866
|
return torch.tensor(x).to(self.device) if isinstance(x, np.ndarray) else x
|
|
873
867
|
|
|
874
868
|
def warmup(self, imgsz: tuple[int, int, int, int] = (1, 3, 640, 640)) -> None:
|
|
875
|
-
"""
|
|
876
|
-
Warm up the model by running one forward pass with a dummy input.
|
|
869
|
+
"""Warm up the model by running one forward pass with a dummy input.
|
|
877
870
|
|
|
878
871
|
Args:
|
|
879
872
|
imgsz (tuple): The shape of the dummy input tensor in the format (batch_size, channels, height, width)
|
|
@@ -889,8 +882,7 @@ class AutoBackend(nn.Module):
|
|
|
889
882
|
|
|
890
883
|
@staticmethod
|
|
891
884
|
def _model_type(p: str = "path/to/model.pt") -> list[bool]:
|
|
892
|
-
"""
|
|
893
|
-
Take a path to a model file and return the model type.
|
|
885
|
+
"""Take a path to a model file and return the model type.
|
|
894
886
|
|
|
895
887
|
Args:
|
|
896
888
|
p (str): Path to the model file.
|
|
@@ -6,8 +6,7 @@ import torch.nn as nn
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
class AGLU(nn.Module):
|
|
9
|
-
"""
|
|
10
|
-
Unified activation function module from AGLU.
|
|
9
|
+
"""Unified activation function module from AGLU.
|
|
11
10
|
|
|
12
11
|
This class implements a parameterized activation function with learnable parameters lambda and kappa, based on the
|
|
13
12
|
AGLU (Adaptive Gated Linear Unit) approach.
|
|
@@ -40,11 +39,10 @@ class AGLU(nn.Module):
|
|
|
40
39
|
self.kappa = nn.Parameter(nn.init.uniform_(torch.empty(1, device=device, dtype=dtype))) # kappa parameter
|
|
41
40
|
|
|
42
41
|
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
|
43
|
-
"""
|
|
44
|
-
Apply the Adaptive Gated Linear Unit (AGLU) activation function.
|
|
42
|
+
"""Apply the Adaptive Gated Linear Unit (AGLU) activation function.
|
|
45
43
|
|
|
46
|
-
This forward method implements the AGLU activation function with learnable parameters lambda and kappa.
|
|
47
|
-
|
|
44
|
+
This forward method implements the AGLU activation function with learnable parameters lambda and kappa. The
|
|
45
|
+
function applies a transformation that adaptively combines linear and non-linear components.
|
|
48
46
|
|
|
49
47
|
Args:
|
|
50
48
|
x (torch.Tensor): Input tensor to apply the activation function to.
|