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
ultralytics/data/base.py
CHANGED
|
@@ -21,11 +21,10 @@ from ultralytics.utils.patches import imread
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
class BaseDataset(Dataset):
|
|
24
|
-
"""
|
|
25
|
-
Base dataset class for loading and processing image data.
|
|
24
|
+
"""Base dataset class for loading and processing image data.
|
|
26
25
|
|
|
27
|
-
This class provides core functionality for loading images, caching, and preparing data for training and inference
|
|
28
|
-
|
|
26
|
+
This class provides core functionality for loading images, caching, and preparing data for training and inference in
|
|
27
|
+
object detection tasks.
|
|
29
28
|
|
|
30
29
|
Attributes:
|
|
31
30
|
img_path (str): Path to the folder containing images.
|
|
@@ -86,8 +85,7 @@ class BaseDataset(Dataset):
|
|
|
86
85
|
fraction: float = 1.0,
|
|
87
86
|
channels: int = 3,
|
|
88
87
|
):
|
|
89
|
-
"""
|
|
90
|
-
Initialize BaseDataset with given configuration and options.
|
|
88
|
+
"""Initialize BaseDataset with given configuration and options.
|
|
91
89
|
|
|
92
90
|
Args:
|
|
93
91
|
img_path (str | list[str]): Path to the folder containing images or list of image paths.
|
|
@@ -148,8 +146,7 @@ class BaseDataset(Dataset):
|
|
|
148
146
|
self.transforms = self.build_transforms(hyp=hyp)
|
|
149
147
|
|
|
150
148
|
def get_img_files(self, img_path: str | list[str]) -> list[str]:
|
|
151
|
-
"""
|
|
152
|
-
Read image files from the specified path.
|
|
149
|
+
"""Read image files from the specified path.
|
|
153
150
|
|
|
154
151
|
Args:
|
|
155
152
|
img_path (str | list[str]): Path or list of paths to image directories or files.
|
|
@@ -186,8 +183,7 @@ class BaseDataset(Dataset):
|
|
|
186
183
|
return im_files
|
|
187
184
|
|
|
188
185
|
def update_labels(self, include_class: list[int] | None) -> None:
|
|
189
|
-
"""
|
|
190
|
-
Update labels to include only specified classes.
|
|
186
|
+
"""Update labels to include only specified classes.
|
|
191
187
|
|
|
192
188
|
Args:
|
|
193
189
|
include_class (list[int], optional): List of classes to include. If None, all classes are included.
|
|
@@ -210,8 +206,7 @@ class BaseDataset(Dataset):
|
|
|
210
206
|
self.labels[i]["cls"][:, 0] = 0
|
|
211
207
|
|
|
212
208
|
def load_image(self, i: int, rect_mode: bool = True) -> tuple[np.ndarray, tuple[int, int], tuple[int, int]]:
|
|
213
|
-
"""
|
|
214
|
-
Load an image from dataset index 'i'.
|
|
209
|
+
"""Load an image from dataset index 'i'.
|
|
215
210
|
|
|
216
211
|
Args:
|
|
217
212
|
i (int): Index of the image to load.
|
|
@@ -286,8 +281,7 @@ class BaseDataset(Dataset):
|
|
|
286
281
|
np.save(f.as_posix(), imread(self.im_files[i]), allow_pickle=False)
|
|
287
282
|
|
|
288
283
|
def check_cache_disk(self, safety_margin: float = 0.5) -> bool:
|
|
289
|
-
"""
|
|
290
|
-
Check if there's enough disk space for caching images.
|
|
284
|
+
"""Check if there's enough disk space for caching images.
|
|
291
285
|
|
|
292
286
|
Args:
|
|
293
287
|
safety_margin (float): Safety margin factor for disk space calculation.
|
|
@@ -322,8 +316,7 @@ class BaseDataset(Dataset):
|
|
|
322
316
|
return True
|
|
323
317
|
|
|
324
318
|
def check_cache_ram(self, safety_margin: float = 0.5) -> bool:
|
|
325
|
-
"""
|
|
326
|
-
Check if there's enough RAM for caching images.
|
|
319
|
+
"""Check if there's enough RAM for caching images.
|
|
327
320
|
|
|
328
321
|
Args:
|
|
329
322
|
safety_margin (float): Safety margin factor for RAM calculation.
|
|
@@ -381,8 +374,7 @@ class BaseDataset(Dataset):
|
|
|
381
374
|
return self.transforms(self.get_image_and_label(index))
|
|
382
375
|
|
|
383
376
|
def get_image_and_label(self, index: int) -> dict[str, Any]:
|
|
384
|
-
"""
|
|
385
|
-
Get and return label information from the dataset.
|
|
377
|
+
"""Get and return label information from the dataset.
|
|
386
378
|
|
|
387
379
|
Args:
|
|
388
380
|
index (int): Index of the image to retrieve.
|
|
@@ -410,8 +402,7 @@ class BaseDataset(Dataset):
|
|
|
410
402
|
return label
|
|
411
403
|
|
|
412
404
|
def build_transforms(self, hyp: dict[str, Any] | None = None):
|
|
413
|
-
"""
|
|
414
|
-
Users can customize augmentations here.
|
|
405
|
+
"""Users can customize augmentations here.
|
|
415
406
|
|
|
416
407
|
Examples:
|
|
417
408
|
>>> if self.augment:
|
|
@@ -424,8 +415,7 @@ class BaseDataset(Dataset):
|
|
|
424
415
|
raise NotImplementedError
|
|
425
416
|
|
|
426
417
|
def get_labels(self) -> list[dict[str, Any]]:
|
|
427
|
-
"""
|
|
428
|
-
Users can customize their own format here.
|
|
418
|
+
"""Users can customize their own format here.
|
|
429
419
|
|
|
430
420
|
Examples:
|
|
431
421
|
Ensure output is a dictionary with the following keys:
|
ultralytics/data/build.py
CHANGED
|
@@ -14,7 +14,7 @@ import numpy as np
|
|
|
14
14
|
import torch
|
|
15
15
|
import torch.distributed as dist
|
|
16
16
|
from PIL import Image
|
|
17
|
-
from torch.utils.data import dataloader, distributed
|
|
17
|
+
from torch.utils.data import Dataset, dataloader, distributed
|
|
18
18
|
|
|
19
19
|
from ultralytics.cfg import IterableSimpleNamespace
|
|
20
20
|
from ultralytics.data.dataset import GroundingDataset, YOLODataset, YOLOMultiModalDataset
|
|
@@ -35,8 +35,7 @@ from ultralytics.utils.torch_utils import TORCH_2_0
|
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
class InfiniteDataLoader(dataloader.DataLoader):
|
|
38
|
-
"""
|
|
39
|
-
Dataloader that reuses workers for infinite iteration.
|
|
38
|
+
"""Dataloader that reuses workers for infinite iteration.
|
|
40
39
|
|
|
41
40
|
This dataloader extends the PyTorch DataLoader to provide infinite recycling of workers, which improves efficiency
|
|
42
41
|
for training loops that need to iterate through the dataset multiple times without recreating workers.
|
|
@@ -94,11 +93,10 @@ class InfiniteDataLoader(dataloader.DataLoader):
|
|
|
94
93
|
|
|
95
94
|
|
|
96
95
|
class _RepeatSampler:
|
|
97
|
-
"""
|
|
98
|
-
Sampler that repeats forever for infinite iteration.
|
|
96
|
+
"""Sampler that repeats forever for infinite iteration.
|
|
99
97
|
|
|
100
|
-
This sampler wraps another sampler and yields its contents indefinitely, allowing for infinite iteration
|
|
101
|
-
|
|
98
|
+
This sampler wraps another sampler and yields its contents indefinitely, allowing for infinite iteration over a
|
|
99
|
+
dataset without recreating the sampler.
|
|
102
100
|
|
|
103
101
|
Attributes:
|
|
104
102
|
sampler (Dataset.sampler): The sampler to repeat.
|
|
@@ -115,27 +113,26 @@ class _RepeatSampler:
|
|
|
115
113
|
|
|
116
114
|
|
|
117
115
|
class ContiguousDistributedSampler(torch.utils.data.Sampler):
|
|
118
|
-
"""
|
|
119
|
-
Distributed sampler that assigns contiguous batch-aligned chunks of the dataset to each GPU.
|
|
116
|
+
"""Distributed sampler that assigns contiguous batch-aligned chunks of the dataset to each GPU.
|
|
120
117
|
|
|
121
118
|
Unlike PyTorch's DistributedSampler which distributes samples in a round-robin fashion (GPU 0 gets indices
|
|
122
|
-
[0,2,4,...], GPU 1 gets [1,3,5,...]), this sampler gives each GPU contiguous batches of the dataset
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
119
|
+
[0,2,4,...], GPU 1 gets [1,3,5,...]), this sampler gives each GPU contiguous batches of the dataset (GPU 0 gets
|
|
120
|
+
batches [0,1,2,...], GPU 1 gets batches [k,k+1,...], etc.). This preserves any ordering or grouping in the original
|
|
121
|
+
dataset, which is critical when samples are organized by similarity (e.g., images sorted by size to enable efficient
|
|
122
|
+
batching without padding when using rect=True).
|
|
126
123
|
|
|
127
|
-
The sampler handles uneven batch counts by distributing remainder batches to the first few ranks, ensuring
|
|
128
|
-
|
|
124
|
+
The sampler handles uneven batch counts by distributing remainder batches to the first few ranks, ensuring all
|
|
125
|
+
samples are covered exactly once across all GPUs.
|
|
129
126
|
|
|
130
127
|
Args:
|
|
131
|
-
dataset (
|
|
128
|
+
dataset (Dataset): Dataset to sample from. Must implement __len__.
|
|
132
129
|
num_replicas (int, optional): Number of distributed processes. Defaults to world size.
|
|
133
130
|
batch_size (int, optional): Batch size used by dataloader. Defaults to dataset batch size.
|
|
134
131
|
rank (int, optional): Rank of current process. Defaults to current rank.
|
|
135
|
-
shuffle (bool, optional): Whether to shuffle indices within each rank's chunk. Defaults to False.
|
|
136
|
-
|
|
132
|
+
shuffle (bool, optional): Whether to shuffle indices within each rank's chunk. Defaults to False. When True,
|
|
133
|
+
shuffling is deterministic and controlled by set_epoch() for reproducibility.
|
|
137
134
|
|
|
138
|
-
|
|
135
|
+
Examples:
|
|
139
136
|
>>> # For validation with size-grouped images
|
|
140
137
|
>>> sampler = ContiguousDistributedSampler(val_dataset, batch_size=32, shuffle=False)
|
|
141
138
|
>>> loader = DataLoader(val_dataset, batch_size=32, sampler=sampler)
|
|
@@ -147,7 +144,14 @@ class ContiguousDistributedSampler(torch.utils.data.Sampler):
|
|
|
147
144
|
... ...
|
|
148
145
|
"""
|
|
149
146
|
|
|
150
|
-
def __init__(
|
|
147
|
+
def __init__(
|
|
148
|
+
self,
|
|
149
|
+
dataset: Dataset,
|
|
150
|
+
num_replicas: int | None = None,
|
|
151
|
+
batch_size: int | None = None,
|
|
152
|
+
rank: int | None = None,
|
|
153
|
+
shuffle: bool = False,
|
|
154
|
+
) -> None:
|
|
151
155
|
"""Initialize the sampler with dataset and distributed training parameters."""
|
|
152
156
|
if num_replicas is None:
|
|
153
157
|
num_replicas = dist.get_world_size() if dist.is_initialized() else 1
|
|
@@ -156,7 +160,6 @@ class ContiguousDistributedSampler(torch.utils.data.Sampler):
|
|
|
156
160
|
if batch_size is None:
|
|
157
161
|
batch_size = getattr(dataset, "batch_size", 1)
|
|
158
162
|
|
|
159
|
-
self.dataset = dataset
|
|
160
163
|
self.num_replicas = num_replicas
|
|
161
164
|
self.batch_size = batch_size
|
|
162
165
|
self.rank = rank
|
|
@@ -165,7 +168,7 @@ class ContiguousDistributedSampler(torch.utils.data.Sampler):
|
|
|
165
168
|
self.total_size = len(dataset)
|
|
166
169
|
self.num_batches = math.ceil(self.total_size / self.batch_size)
|
|
167
170
|
|
|
168
|
-
def _get_rank_indices(self):
|
|
171
|
+
def _get_rank_indices(self) -> tuple[int, int]:
|
|
169
172
|
"""Calculate the start and end sample indices for this rank."""
|
|
170
173
|
# Calculate which batches this rank handles
|
|
171
174
|
batches_per_rank_base = self.num_batches // self.num_replicas
|
|
@@ -184,7 +187,7 @@ class ContiguousDistributedSampler(torch.utils.data.Sampler):
|
|
|
184
187
|
|
|
185
188
|
return start_idx, end_idx
|
|
186
189
|
|
|
187
|
-
def __iter__(self):
|
|
190
|
+
def __iter__(self) -> Iterator:
|
|
188
191
|
"""Generate indices for this rank's contiguous chunk of the dataset."""
|
|
189
192
|
start_idx, end_idx = self._get_rank_indices()
|
|
190
193
|
indices = list(range(start_idx, end_idx))
|
|
@@ -196,14 +199,13 @@ class ContiguousDistributedSampler(torch.utils.data.Sampler):
|
|
|
196
199
|
|
|
197
200
|
return iter(indices)
|
|
198
201
|
|
|
199
|
-
def __len__(self):
|
|
202
|
+
def __len__(self) -> int:
|
|
200
203
|
"""Return the number of samples in this rank's chunk."""
|
|
201
204
|
start_idx, end_idx = self._get_rank_indices()
|
|
202
205
|
return end_idx - start_idx
|
|
203
206
|
|
|
204
|
-
def set_epoch(self, epoch):
|
|
205
|
-
"""
|
|
206
|
-
Set the epoch for this sampler to ensure different shuffling patterns across epochs.
|
|
207
|
+
def set_epoch(self, epoch: int) -> None:
|
|
208
|
+
"""Set the epoch for this sampler to ensure different shuffling patterns across epochs.
|
|
207
209
|
|
|
208
210
|
Args:
|
|
209
211
|
epoch (int): Epoch number to use as the random seed for shuffling.
|
|
@@ -211,7 +213,7 @@ class ContiguousDistributedSampler(torch.utils.data.Sampler):
|
|
|
211
213
|
self.epoch = epoch
|
|
212
214
|
|
|
213
215
|
|
|
214
|
-
def seed_worker(worker_id: int):
|
|
216
|
+
def seed_worker(worker_id: int) -> None:
|
|
215
217
|
"""Set dataloader worker seed for reproducibility across worker processes."""
|
|
216
218
|
worker_seed = torch.initial_seed() % 2**32
|
|
217
219
|
np.random.seed(worker_seed)
|
|
@@ -227,7 +229,7 @@ def build_yolo_dataset(
|
|
|
227
229
|
rect: bool = False,
|
|
228
230
|
stride: int = 32,
|
|
229
231
|
multi_modal: bool = False,
|
|
230
|
-
):
|
|
232
|
+
) -> Dataset:
|
|
231
233
|
"""Build and return a YOLO dataset based on configuration parameters."""
|
|
232
234
|
dataset = YOLOMultiModalDataset if multi_modal else YOLODataset
|
|
233
235
|
return dataset(
|
|
@@ -258,7 +260,7 @@ def build_grounding(
|
|
|
258
260
|
rect: bool = False,
|
|
259
261
|
stride: int = 32,
|
|
260
262
|
max_samples: int = 80,
|
|
261
|
-
):
|
|
263
|
+
) -> Dataset:
|
|
262
264
|
"""Build and return a GroundingDataset based on configuration parameters."""
|
|
263
265
|
return GroundingDataset(
|
|
264
266
|
img_path=img_path,
|
|
@@ -288,9 +290,8 @@ def build_dataloader(
|
|
|
288
290
|
rank: int = -1,
|
|
289
291
|
drop_last: bool = False,
|
|
290
292
|
pin_memory: bool = True,
|
|
291
|
-
):
|
|
292
|
-
"""
|
|
293
|
-
Create and return an InfiniteDataLoader or DataLoader for training or validation.
|
|
293
|
+
) -> InfiniteDataLoader:
|
|
294
|
+
"""Create and return an InfiniteDataLoader or DataLoader for training or validation.
|
|
294
295
|
|
|
295
296
|
Args:
|
|
296
297
|
dataset (Dataset): Dataset to load data from.
|
|
@@ -336,9 +337,10 @@ def build_dataloader(
|
|
|
336
337
|
)
|
|
337
338
|
|
|
338
339
|
|
|
339
|
-
def check_source(
|
|
340
|
-
|
|
341
|
-
|
|
340
|
+
def check_source(
|
|
341
|
+
source: str | int | Path | list | tuple | np.ndarray | Image.Image | torch.Tensor,
|
|
342
|
+
) -> tuple[Any, bool, bool, bool, bool, bool]:
|
|
343
|
+
"""Check the type of input source and return corresponding flag values.
|
|
342
344
|
|
|
343
345
|
Args:
|
|
344
346
|
source (str | int | Path | list | tuple | np.ndarray | PIL.Image | torch.Tensor): The input source to check.
|
|
@@ -385,12 +387,17 @@ def check_source(source):
|
|
|
385
387
|
return source, webcam, screenshot, from_img, in_memory, tensor
|
|
386
388
|
|
|
387
389
|
|
|
388
|
-
def load_inference_source(
|
|
389
|
-
|
|
390
|
-
|
|
390
|
+
def load_inference_source(
|
|
391
|
+
source: str | int | Path | list | tuple | np.ndarray | Image.Image | torch.Tensor,
|
|
392
|
+
batch: int = 1,
|
|
393
|
+
vid_stride: int = 1,
|
|
394
|
+
buffer: bool = False,
|
|
395
|
+
channels: int = 3,
|
|
396
|
+
):
|
|
397
|
+
"""Load an inference source for object detection and apply necessary transformations.
|
|
391
398
|
|
|
392
399
|
Args:
|
|
393
|
-
source (str | Path | torch.Tensor | PIL.Image | np.ndarray
|
|
400
|
+
source (str | Path | list | tuple | torch.Tensor | PIL.Image | np.ndarray): The input source for inference.
|
|
394
401
|
batch (int, optional): Batch size for dataloaders.
|
|
395
402
|
vid_stride (int, optional): The frame interval for video sources.
|
|
396
403
|
buffer (bool, optional): Whether stream frames will be buffered.
|
ultralytics/data/converter.py
CHANGED
|
@@ -21,12 +21,11 @@ from ultralytics.utils.files import increment_path
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
def coco91_to_coco80_class() -> list[int]:
|
|
24
|
-
"""
|
|
25
|
-
Convert 91-index COCO class IDs to 80-index COCO class IDs.
|
|
24
|
+
"""Convert 91-index COCO class IDs to 80-index COCO class IDs.
|
|
26
25
|
|
|
27
26
|
Returns:
|
|
28
|
-
(list[int]): A list of 91 class IDs where the index represents the 80-index class ID and the value
|
|
29
|
-
|
|
27
|
+
(list[int]): A list of 91 class IDs where the index represents the 80-index class ID and the value is the
|
|
28
|
+
corresponding 91-index class ID.
|
|
30
29
|
"""
|
|
31
30
|
return [
|
|
32
31
|
0,
|
|
@@ -124,15 +123,11 @@ def coco91_to_coco80_class() -> list[int]:
|
|
|
124
123
|
|
|
125
124
|
|
|
126
125
|
def coco80_to_coco91_class() -> list[int]:
|
|
127
|
-
r"""
|
|
128
|
-
Convert 80-index (val2014) to 91-index (paper).
|
|
126
|
+
r"""Convert 80-index (val2014) to 91-index (paper).
|
|
129
127
|
|
|
130
128
|
Returns:
|
|
131
129
|
(list[int]): A list of 80 class IDs where each value is the corresponding 91-index class ID.
|
|
132
130
|
|
|
133
|
-
References:
|
|
134
|
-
https://tech.amikelive.com/node-718/what-object-categories-labels-are-in-coco-dataset/
|
|
135
|
-
|
|
136
131
|
Examples:
|
|
137
132
|
>>> import numpy as np
|
|
138
133
|
>>> a = np.loadtxt("data/coco.names", dtype="str", delimiter="\n")
|
|
@@ -143,6 +138,9 @@ def coco80_to_coco91_class() -> list[int]:
|
|
|
143
138
|
|
|
144
139
|
Convert the COCO to darknet format
|
|
145
140
|
>>> x2 = [list(b[i] == a).index(True) if any(b[i] == a) else None for i in range(91)]
|
|
141
|
+
|
|
142
|
+
References:
|
|
143
|
+
https://tech.amikelive.com/node-718/what-object-categories-labels-are-in-coco-dataset/
|
|
146
144
|
"""
|
|
147
145
|
return [
|
|
148
146
|
1,
|
|
@@ -236,8 +234,7 @@ def convert_coco(
|
|
|
236
234
|
cls91to80: bool = True,
|
|
237
235
|
lvis: bool = False,
|
|
238
236
|
):
|
|
239
|
-
"""
|
|
240
|
-
Convert COCO dataset annotations to a YOLO annotation format suitable for training YOLO models.
|
|
237
|
+
"""Convert COCO dataset annotations to a YOLO annotation format suitable for training YOLO models.
|
|
241
238
|
|
|
242
239
|
Args:
|
|
243
240
|
labels_dir (str, optional): Path to directory containing COCO dataset annotation files.
|
|
@@ -348,8 +345,7 @@ def convert_coco(
|
|
|
348
345
|
|
|
349
346
|
|
|
350
347
|
def convert_segment_masks_to_yolo_seg(masks_dir: str, output_dir: str, classes: int):
|
|
351
|
-
"""
|
|
352
|
-
Convert a dataset of segmentation mask images to the YOLO segmentation format.
|
|
348
|
+
"""Convert a dataset of segmentation mask images to the YOLO segmentation format.
|
|
353
349
|
|
|
354
350
|
This function takes the directory containing the binary format mask images and converts them into YOLO segmentation
|
|
355
351
|
format. The converted masks are saved in the specified output directory.
|
|
@@ -424,8 +420,7 @@ def convert_segment_masks_to_yolo_seg(masks_dir: str, output_dir: str, classes:
|
|
|
424
420
|
|
|
425
421
|
|
|
426
422
|
def convert_dota_to_yolo_obb(dota_root_path: str):
|
|
427
|
-
"""
|
|
428
|
-
Convert DOTA dataset annotations to YOLO OBB (Oriented Bounding Box) format.
|
|
423
|
+
"""Convert DOTA dataset annotations to YOLO OBB (Oriented Bounding Box) format.
|
|
429
424
|
|
|
430
425
|
The function processes images in the 'train' and 'val' folders of the DOTA dataset. For each image, it reads the
|
|
431
426
|
associated label from the original labels directory and writes new labels in YOLO OBB format to a new directory.
|
|
@@ -517,8 +512,7 @@ def convert_dota_to_yolo_obb(dota_root_path: str):
|
|
|
517
512
|
|
|
518
513
|
|
|
519
514
|
def min_index(arr1: np.ndarray, arr2: np.ndarray):
|
|
520
|
-
"""
|
|
521
|
-
Find a pair of indexes with the shortest distance between two arrays of 2D points.
|
|
515
|
+
"""Find a pair of indexes with the shortest distance between two arrays of 2D points.
|
|
522
516
|
|
|
523
517
|
Args:
|
|
524
518
|
arr1 (np.ndarray): A NumPy array of shape (N, 2) representing N 2D points.
|
|
@@ -533,14 +527,14 @@ def min_index(arr1: np.ndarray, arr2: np.ndarray):
|
|
|
533
527
|
|
|
534
528
|
|
|
535
529
|
def merge_multi_segment(segments: list[list]):
|
|
536
|
-
"""
|
|
537
|
-
|
|
530
|
+
"""Merge multiple segments into one list by connecting the coordinates with the minimum distance between each
|
|
531
|
+
segment.
|
|
538
532
|
|
|
539
533
|
This function connects these coordinates with a thin line to merge all segments into one.
|
|
540
534
|
|
|
541
535
|
Args:
|
|
542
|
-
segments (list[list]): Original segmentations in COCO's JSON file.
|
|
543
|
-
|
|
536
|
+
segments (list[list]): Original segmentations in COCO's JSON file. Each element is a list of coordinates, like
|
|
537
|
+
[segmentation1, segmentation2,...].
|
|
544
538
|
|
|
545
539
|
Returns:
|
|
546
540
|
s (list[np.ndarray]): A list of connected segments represented as NumPy arrays.
|
|
@@ -584,14 +578,13 @@ def merge_multi_segment(segments: list[list]):
|
|
|
584
578
|
|
|
585
579
|
|
|
586
580
|
def yolo_bbox2segment(im_dir: str | Path, save_dir: str | Path | None = None, sam_model: str = "sam_b.pt", device=None):
|
|
587
|
-
"""
|
|
588
|
-
|
|
589
|
-
YOLO format. Generate segmentation data using SAM auto-annotator as needed.
|
|
581
|
+
"""Convert existing object detection dataset (bounding boxes) to segmentation dataset or oriented bounding box (OBB)
|
|
582
|
+
in YOLO format. Generate segmentation data using SAM auto-annotator as needed.
|
|
590
583
|
|
|
591
584
|
Args:
|
|
592
585
|
im_dir (str | Path): Path to image directory to convert.
|
|
593
|
-
save_dir (str | Path, optional): Path to save the generated labels, labels will be saved
|
|
594
|
-
|
|
586
|
+
save_dir (str | Path, optional): Path to save the generated labels, labels will be saved into `labels-segment`
|
|
587
|
+
in the same directory level of `im_dir` if save_dir is None.
|
|
595
588
|
sam_model (str): Segmentation model to use for intermediate segmentation data.
|
|
596
589
|
device (int | str, optional): The specific device to run SAM models.
|
|
597
590
|
|
|
@@ -648,12 +641,11 @@ def yolo_bbox2segment(im_dir: str | Path, save_dir: str | Path | None = None, sa
|
|
|
648
641
|
|
|
649
642
|
|
|
650
643
|
def create_synthetic_coco_dataset():
|
|
651
|
-
"""
|
|
652
|
-
Create a synthetic COCO dataset with random images based on filenames from label lists.
|
|
644
|
+
"""Create a synthetic COCO dataset with random images based on filenames from label lists.
|
|
653
645
|
|
|
654
|
-
This function downloads COCO labels, reads image filenames from label list files,
|
|
655
|
-
|
|
656
|
-
|
|
646
|
+
This function downloads COCO labels, reads image filenames from label list files, creates synthetic images for
|
|
647
|
+
train2017 and val2017 subsets, and organizes them in the COCO dataset structure. It uses multithreading to generate
|
|
648
|
+
images efficiently.
|
|
657
649
|
|
|
658
650
|
Examples:
|
|
659
651
|
>>> from ultralytics.data.converter import create_synthetic_coco_dataset
|
|
@@ -704,11 +696,10 @@ def create_synthetic_coco_dataset():
|
|
|
704
696
|
|
|
705
697
|
|
|
706
698
|
def convert_to_multispectral(path: str | Path, n_channels: int = 10, replace: bool = False, zip: bool = False):
|
|
707
|
-
"""
|
|
708
|
-
Convert RGB images to multispectral images by interpolating across wavelength bands.
|
|
699
|
+
"""Convert RGB images to multispectral images by interpolating across wavelength bands.
|
|
709
700
|
|
|
710
|
-
This function takes RGB images and interpolates them to create multispectral images with a specified number
|
|
711
|
-
|
|
701
|
+
This function takes RGB images and interpolates them to create multispectral images with a specified number of
|
|
702
|
+
channels. It can process either a single image or a directory of images.
|
|
712
703
|
|
|
713
704
|
Args:
|
|
714
705
|
path (str | Path): Path to an image file or directory containing images to convert.
|
|
@@ -756,12 +747,11 @@ def convert_to_multispectral(path: str | Path, n_channels: int = 10, replace: bo
|
|
|
756
747
|
|
|
757
748
|
|
|
758
749
|
async def convert_ndjson_to_yolo(ndjson_path: str | Path, output_path: str | Path | None = None) -> Path:
|
|
759
|
-
"""
|
|
760
|
-
Convert NDJSON dataset format to Ultralytics YOLO11 dataset structure.
|
|
750
|
+
"""Convert NDJSON dataset format to Ultralytics YOLO11 dataset structure.
|
|
761
751
|
|
|
762
|
-
This function converts datasets stored in NDJSON (Newline Delimited JSON) format to the standard YOLO
|
|
763
|
-
|
|
764
|
-
|
|
752
|
+
This function converts datasets stored in NDJSON (Newline Delimited JSON) format to the standard YOLO format with
|
|
753
|
+
separate directories for images and labels. It supports parallel processing for efficient conversion of large
|
|
754
|
+
datasets and can download images from URLs if they don't exist locally.
|
|
765
755
|
|
|
766
756
|
The NDJSON format consists of:
|
|
767
757
|
- First line: Dataset metadata with class names and configuration
|
|
@@ -769,8 +759,8 @@ async def convert_ndjson_to_yolo(ndjson_path: str | Path, output_path: str | Pat
|
|
|
769
759
|
|
|
770
760
|
Args:
|
|
771
761
|
ndjson_path (Union[str, Path]): Path to the input NDJSON file containing dataset information.
|
|
772
|
-
output_path (Optional[Union[str, Path]], optional): Directory where the converted YOLO dataset
|
|
773
|
-
|
|
762
|
+
output_path (Optional[Union[str, Path]], optional): Directory where the converted YOLO dataset will be saved. If
|
|
763
|
+
None, uses the parent directory of the NDJSON file. Defaults to None.
|
|
774
764
|
|
|
775
765
|
Returns:
|
|
776
766
|
(Path): Path to the generated data.yaml file that can be used for YOLO training.
|