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.
Files changed (158) hide show
  1. {dgenerate_ultralytics_headless-8.3.222.dist-info → dgenerate_ultralytics_headless-8.3.225.dist-info}/METADATA +2 -2
  2. dgenerate_ultralytics_headless-8.3.225.dist-info/RECORD +286 -0
  3. tests/conftest.py +5 -8
  4. tests/test_cli.py +1 -8
  5. tests/test_python.py +1 -2
  6. ultralytics/__init__.py +1 -1
  7. ultralytics/cfg/__init__.py +34 -49
  8. ultralytics/cfg/datasets/ImageNet.yaml +1 -1
  9. ultralytics/cfg/datasets/kitti.yaml +27 -0
  10. ultralytics/cfg/datasets/lvis.yaml +5 -5
  11. ultralytics/cfg/datasets/open-images-v7.yaml +1 -1
  12. ultralytics/data/annotator.py +3 -4
  13. ultralytics/data/augment.py +244 -323
  14. ultralytics/data/base.py +12 -22
  15. ultralytics/data/build.py +47 -40
  16. ultralytics/data/converter.py +32 -42
  17. ultralytics/data/dataset.py +43 -71
  18. ultralytics/data/loaders.py +22 -34
  19. ultralytics/data/split.py +5 -6
  20. ultralytics/data/split_dota.py +8 -15
  21. ultralytics/data/utils.py +27 -36
  22. ultralytics/engine/exporter.py +49 -116
  23. ultralytics/engine/model.py +144 -180
  24. ultralytics/engine/predictor.py +18 -29
  25. ultralytics/engine/results.py +165 -231
  26. ultralytics/engine/trainer.py +11 -19
  27. ultralytics/engine/tuner.py +13 -23
  28. ultralytics/engine/validator.py +6 -10
  29. ultralytics/hub/__init__.py +7 -12
  30. ultralytics/hub/auth.py +6 -12
  31. ultralytics/hub/google/__init__.py +7 -10
  32. ultralytics/hub/session.py +15 -25
  33. ultralytics/hub/utils.py +3 -6
  34. ultralytics/models/fastsam/model.py +6 -8
  35. ultralytics/models/fastsam/predict.py +5 -10
  36. ultralytics/models/fastsam/utils.py +1 -2
  37. ultralytics/models/fastsam/val.py +2 -4
  38. ultralytics/models/nas/model.py +5 -8
  39. ultralytics/models/nas/predict.py +7 -9
  40. ultralytics/models/nas/val.py +1 -2
  41. ultralytics/models/rtdetr/model.py +5 -8
  42. ultralytics/models/rtdetr/predict.py +15 -18
  43. ultralytics/models/rtdetr/train.py +10 -13
  44. ultralytics/models/rtdetr/val.py +13 -20
  45. ultralytics/models/sam/amg.py +12 -18
  46. ultralytics/models/sam/build.py +6 -9
  47. ultralytics/models/sam/model.py +16 -23
  48. ultralytics/models/sam/modules/blocks.py +62 -84
  49. ultralytics/models/sam/modules/decoders.py +17 -24
  50. ultralytics/models/sam/modules/encoders.py +40 -56
  51. ultralytics/models/sam/modules/memory_attention.py +10 -16
  52. ultralytics/models/sam/modules/sam.py +41 -47
  53. ultralytics/models/sam/modules/tiny_encoder.py +64 -83
  54. ultralytics/models/sam/modules/transformer.py +17 -27
  55. ultralytics/models/sam/modules/utils.py +31 -42
  56. ultralytics/models/sam/predict.py +172 -209
  57. ultralytics/models/utils/loss.py +14 -26
  58. ultralytics/models/utils/ops.py +13 -17
  59. ultralytics/models/yolo/classify/predict.py +8 -11
  60. ultralytics/models/yolo/classify/train.py +8 -16
  61. ultralytics/models/yolo/classify/val.py +13 -20
  62. ultralytics/models/yolo/detect/predict.py +4 -8
  63. ultralytics/models/yolo/detect/train.py +11 -20
  64. ultralytics/models/yolo/detect/val.py +38 -48
  65. ultralytics/models/yolo/model.py +35 -47
  66. ultralytics/models/yolo/obb/predict.py +5 -8
  67. ultralytics/models/yolo/obb/train.py +11 -14
  68. ultralytics/models/yolo/obb/val.py +20 -28
  69. ultralytics/models/yolo/pose/predict.py +5 -8
  70. ultralytics/models/yolo/pose/train.py +4 -8
  71. ultralytics/models/yolo/pose/val.py +31 -39
  72. ultralytics/models/yolo/segment/predict.py +9 -14
  73. ultralytics/models/yolo/segment/train.py +3 -6
  74. ultralytics/models/yolo/segment/val.py +16 -26
  75. ultralytics/models/yolo/world/train.py +8 -14
  76. ultralytics/models/yolo/world/train_world.py +11 -16
  77. ultralytics/models/yolo/yoloe/predict.py +16 -23
  78. ultralytics/models/yolo/yoloe/train.py +30 -43
  79. ultralytics/models/yolo/yoloe/train_seg.py +5 -10
  80. ultralytics/models/yolo/yoloe/val.py +15 -20
  81. ultralytics/nn/autobackend.py +10 -18
  82. ultralytics/nn/modules/activation.py +4 -6
  83. ultralytics/nn/modules/block.py +99 -185
  84. ultralytics/nn/modules/conv.py +45 -90
  85. ultralytics/nn/modules/head.py +44 -98
  86. ultralytics/nn/modules/transformer.py +44 -76
  87. ultralytics/nn/modules/utils.py +14 -19
  88. ultralytics/nn/tasks.py +86 -146
  89. ultralytics/nn/text_model.py +25 -40
  90. ultralytics/solutions/ai_gym.py +10 -16
  91. ultralytics/solutions/analytics.py +7 -10
  92. ultralytics/solutions/config.py +4 -5
  93. ultralytics/solutions/distance_calculation.py +9 -12
  94. ultralytics/solutions/heatmap.py +7 -13
  95. ultralytics/solutions/instance_segmentation.py +5 -8
  96. ultralytics/solutions/object_blurrer.py +7 -10
  97. ultralytics/solutions/object_counter.py +8 -12
  98. ultralytics/solutions/object_cropper.py +5 -8
  99. ultralytics/solutions/parking_management.py +12 -14
  100. ultralytics/solutions/queue_management.py +4 -6
  101. ultralytics/solutions/region_counter.py +7 -10
  102. ultralytics/solutions/security_alarm.py +14 -19
  103. ultralytics/solutions/similarity_search.py +7 -12
  104. ultralytics/solutions/solutions.py +31 -53
  105. ultralytics/solutions/speed_estimation.py +6 -9
  106. ultralytics/solutions/streamlit_inference.py +2 -4
  107. ultralytics/solutions/trackzone.py +7 -10
  108. ultralytics/solutions/vision_eye.py +5 -8
  109. ultralytics/trackers/basetrack.py +2 -4
  110. ultralytics/trackers/bot_sort.py +6 -11
  111. ultralytics/trackers/byte_tracker.py +10 -15
  112. ultralytics/trackers/track.py +3 -6
  113. ultralytics/trackers/utils/gmc.py +6 -12
  114. ultralytics/trackers/utils/kalman_filter.py +35 -43
  115. ultralytics/trackers/utils/matching.py +6 -10
  116. ultralytics/utils/__init__.py +61 -100
  117. ultralytics/utils/autobatch.py +2 -4
  118. ultralytics/utils/autodevice.py +11 -13
  119. ultralytics/utils/benchmarks.py +25 -35
  120. ultralytics/utils/callbacks/base.py +8 -10
  121. ultralytics/utils/callbacks/clearml.py +2 -4
  122. ultralytics/utils/callbacks/comet.py +30 -44
  123. ultralytics/utils/callbacks/dvc.py +13 -18
  124. ultralytics/utils/callbacks/mlflow.py +4 -5
  125. ultralytics/utils/callbacks/neptune.py +4 -6
  126. ultralytics/utils/callbacks/raytune.py +3 -4
  127. ultralytics/utils/callbacks/tensorboard.py +4 -6
  128. ultralytics/utils/callbacks/wb.py +10 -13
  129. ultralytics/utils/checks.py +29 -56
  130. ultralytics/utils/cpu.py +1 -2
  131. ultralytics/utils/dist.py +8 -12
  132. ultralytics/utils/downloads.py +17 -27
  133. ultralytics/utils/errors.py +6 -8
  134. ultralytics/utils/events.py +2 -4
  135. ultralytics/utils/export/__init__.py +4 -239
  136. ultralytics/utils/export/engine.py +237 -0
  137. ultralytics/utils/export/imx.py +11 -17
  138. ultralytics/utils/export/tensorflow.py +217 -0
  139. ultralytics/utils/files.py +10 -15
  140. ultralytics/utils/git.py +5 -7
  141. ultralytics/utils/instance.py +30 -51
  142. ultralytics/utils/logger.py +11 -15
  143. ultralytics/utils/loss.py +8 -14
  144. ultralytics/utils/metrics.py +98 -138
  145. ultralytics/utils/nms.py +13 -16
  146. ultralytics/utils/ops.py +47 -74
  147. ultralytics/utils/patches.py +11 -18
  148. ultralytics/utils/plotting.py +29 -42
  149. ultralytics/utils/tal.py +25 -39
  150. ultralytics/utils/torch_utils.py +45 -73
  151. ultralytics/utils/tqdm.py +6 -8
  152. ultralytics/utils/triton.py +9 -12
  153. ultralytics/utils/tuner.py +1 -2
  154. dgenerate_ultralytics_headless-8.3.222.dist-info/RECORD +0 -283
  155. {dgenerate_ultralytics_headless-8.3.222.dist-info → dgenerate_ultralytics_headless-8.3.225.dist-info}/WHEEL +0 -0
  156. {dgenerate_ultralytics_headless-8.3.222.dist-info → dgenerate_ultralytics_headless-8.3.225.dist-info}/entry_points.txt +0 -0
  157. {dgenerate_ultralytics_headless-8.3.222.dist-info → dgenerate_ultralytics_headless-8.3.225.dist-info}/licenses/LICENSE +0 -0
  158. {dgenerate_ultralytics_headless-8.3.222.dist-info → dgenerate_ultralytics_headless-8.3.225.dist-info}/top_level.txt +0 -0
@@ -47,8 +47,7 @@ DATASET_CACHE_VERSION = "1.0.3"
47
47
 
48
48
 
49
49
  class YOLODataset(BaseDataset):
50
- """
51
- Dataset class for loading object detection and/or segmentation labels in YOLO format.
50
+ """Dataset class for loading object detection and/or segmentation labels in YOLO format.
52
51
 
53
52
  This class supports loading data for object detection, segmentation, pose estimation, and oriented bounding box
54
53
  (OBB) tasks using the YOLO format.
@@ -73,8 +72,7 @@ class YOLODataset(BaseDataset):
73
72
  """
74
73
 
75
74
  def __init__(self, *args, data: dict | None = None, task: str = "detect", **kwargs):
76
- """
77
- Initialize the YOLODataset.
75
+ """Initialize the YOLODataset.
78
76
 
79
77
  Args:
80
78
  data (dict, optional): Dataset configuration dictionary.
@@ -90,8 +88,7 @@ class YOLODataset(BaseDataset):
90
88
  super().__init__(*args, channels=self.data.get("channels", 3), **kwargs)
91
89
 
92
90
  def cache_labels(self, path: Path = Path("./labels.cache")) -> dict:
93
- """
94
- Cache dataset labels, check images and read shapes.
91
+ """Cache dataset labels, check images and read shapes.
95
92
 
96
93
  Args:
97
94
  path (Path): Path where to save the cache file.
@@ -158,8 +155,7 @@ class YOLODataset(BaseDataset):
158
155
  return x
159
156
 
160
157
  def get_labels(self) -> list[dict]:
161
- """
162
- Return dictionary of labels for YOLO training.
158
+ """Return dictionary of labels for YOLO training.
163
159
 
164
160
  This method loads labels from disk or cache, verifies their integrity, and prepares them for training.
165
161
 
@@ -208,8 +204,7 @@ class YOLODataset(BaseDataset):
208
204
  return labels
209
205
 
210
206
  def build_transforms(self, hyp: dict | None = None) -> Compose:
211
- """
212
- Build and append transforms to the list.
207
+ """Build and append transforms to the list.
213
208
 
214
209
  Args:
215
210
  hyp (dict, optional): Hyperparameters for transforms.
@@ -240,8 +235,7 @@ class YOLODataset(BaseDataset):
240
235
  return transforms
241
236
 
242
237
  def close_mosaic(self, hyp: dict) -> None:
243
- """
244
- Disable mosaic, copy_paste, mixup and cutmix augmentations by setting their probabilities to 0.0.
238
+ """Disable mosaic, copy_paste, mixup and cutmix augmentations by setting their probabilities to 0.0.
245
239
 
246
240
  Args:
247
241
  hyp (dict): Hyperparameters for transforms.
@@ -253,8 +247,7 @@ class YOLODataset(BaseDataset):
253
247
  self.transforms = self.build_transforms(hyp)
254
248
 
255
249
  def update_labels_info(self, label: dict) -> dict:
256
- """
257
- Update label format for different tasks.
250
+ """Update label format for different tasks.
258
251
 
259
252
  Args:
260
253
  label (dict): Label dictionary containing bboxes, segments, keypoints, etc.
@@ -262,7 +255,7 @@ class YOLODataset(BaseDataset):
262
255
  Returns:
263
256
  (dict): Updated label dictionary with instances.
264
257
 
265
- Note:
258
+ Notes:
266
259
  cls is not with bboxes now, classification and semantic segmentation need an independent cls label
267
260
  Can also support classification and semantic segmentation by adding or removing dict keys there.
268
261
  """
@@ -287,8 +280,7 @@ class YOLODataset(BaseDataset):
287
280
 
288
281
  @staticmethod
289
282
  def collate_fn(batch: list[dict]) -> dict:
290
- """
291
- Collate data samples into batches.
283
+ """Collate data samples into batches.
292
284
 
293
285
  Args:
294
286
  batch (list[dict]): List of dictionaries containing sample data.
@@ -317,11 +309,10 @@ class YOLODataset(BaseDataset):
317
309
 
318
310
 
319
311
  class YOLOMultiModalDataset(YOLODataset):
320
- """
321
- Dataset class for loading object detection and/or segmentation labels in YOLO format with multi-modal support.
312
+ """Dataset class for loading object detection and/or segmentation labels in YOLO format with multi-modal support.
322
313
 
323
- This class extends YOLODataset to add text information for multi-modal model training, enabling models to
324
- process both image and text data.
314
+ This class extends YOLODataset to add text information for multi-modal model training, enabling models to process
315
+ both image and text data.
325
316
 
326
317
  Methods:
327
318
  update_labels_info: Add text information for multi-modal model training.
@@ -334,8 +325,7 @@ class YOLOMultiModalDataset(YOLODataset):
334
325
  """
335
326
 
336
327
  def __init__(self, *args, data: dict | None = None, task: str = "detect", **kwargs):
337
- """
338
- Initialize a YOLOMultiModalDataset.
328
+ """Initialize a YOLOMultiModalDataset.
339
329
 
340
330
  Args:
341
331
  data (dict, optional): Dataset configuration dictionary.
@@ -346,8 +336,7 @@ class YOLOMultiModalDataset(YOLODataset):
346
336
  super().__init__(*args, data=data, task=task, **kwargs)
347
337
 
348
338
  def update_labels_info(self, label: dict) -> dict:
349
- """
350
- Add text information for multi-modal model training.
339
+ """Add text information for multi-modal model training.
351
340
 
352
341
  Args:
353
342
  label (dict): Label dictionary containing bboxes, segments, keypoints, etc.
@@ -363,8 +352,7 @@ class YOLOMultiModalDataset(YOLODataset):
363
352
  return labels
364
353
 
365
354
  def build_transforms(self, hyp: dict | None = None) -> Compose:
366
- """
367
- Enhance data transformations with optional text augmentation for multi-modal training.
355
+ """Enhance data transformations with optional text augmentation for multi-modal training.
368
356
 
369
357
  Args:
370
358
  hyp (dict, optional): Hyperparameters for transforms.
@@ -388,8 +376,7 @@ class YOLOMultiModalDataset(YOLODataset):
388
376
 
389
377
  @property
390
378
  def category_names(self):
391
- """
392
- Return category names for the dataset.
379
+ """Return category names for the dataset.
393
380
 
394
381
  Returns:
395
382
  (set[str]): List of class names.
@@ -418,11 +405,10 @@ class YOLOMultiModalDataset(YOLODataset):
418
405
 
419
406
 
420
407
  class GroundingDataset(YOLODataset):
421
- """
422
- Dataset class for object detection tasks using annotations from a JSON file in grounding format.
408
+ """Dataset class for object detection tasks using annotations from a JSON file in grounding format.
423
409
 
424
- This dataset is designed for grounding tasks where annotations are provided in a JSON file rather than
425
- the standard YOLO format text files.
410
+ This dataset is designed for grounding tasks where annotations are provided in a JSON file rather than the standard
411
+ YOLO format text files.
426
412
 
427
413
  Attributes:
428
414
  json_file (str): Path to the JSON file containing annotations.
@@ -438,8 +424,7 @@ class GroundingDataset(YOLODataset):
438
424
  """
439
425
 
440
426
  def __init__(self, *args, task: str = "detect", json_file: str = "", max_samples: int = 80, **kwargs):
441
- """
442
- Initialize a GroundingDataset for object detection.
427
+ """Initialize a GroundingDataset for object detection.
443
428
 
444
429
  Args:
445
430
  json_file (str): Path to the JSON file containing annotations.
@@ -454,8 +439,7 @@ class GroundingDataset(YOLODataset):
454
439
  super().__init__(*args, task=task, data={"channels": 3}, **kwargs)
455
440
 
456
441
  def get_img_files(self, img_path: str) -> list:
457
- """
458
- The image files would be read in `get_labels` function, return empty list here.
442
+ """The image files would be read in `get_labels` function, return empty list here.
459
443
 
460
444
  Args:
461
445
  img_path (str): Path to the directory containing images.
@@ -466,23 +450,21 @@ class GroundingDataset(YOLODataset):
466
450
  return []
467
451
 
468
452
  def verify_labels(self, labels: list[dict[str, Any]]) -> None:
469
- """
470
- Verify the number of instances in the dataset matches expected counts.
453
+ """Verify the number of instances in the dataset matches expected counts.
471
454
 
472
- This method checks if the total number of bounding box instances in the provided
473
- labels matches the expected count for known datasets. It performs validation
474
- against a predefined set of datasets with known instance counts.
455
+ This method checks if the total number of bounding box instances in the provided labels matches the expected
456
+ count for known datasets. It performs validation against a predefined set of datasets with known instance
457
+ counts.
475
458
 
476
459
  Args:
477
- labels (list[dict[str, Any]]): List of label dictionaries, where each dictionary
478
- contains dataset annotations. Each label dict must have a 'bboxes' key with
479
- a numpy array or tensor containing bounding box coordinates.
460
+ labels (list[dict[str, Any]]): List of label dictionaries, where each dictionary contains dataset
461
+ annotations. Each label dict must have a 'bboxes' key with a numpy array or tensor containing bounding
462
+ box coordinates.
480
463
 
481
464
  Raises:
482
- AssertionError: If the actual instance count doesn't match the expected count
483
- for a recognized dataset.
465
+ AssertionError: If the actual instance count doesn't match the expected count for a recognized dataset.
484
466
 
485
- Note:
467
+ Notes:
486
468
  For unrecognized datasets (those not in the predefined expected_counts),
487
469
  a warning is logged and verification is skipped.
488
470
  """
@@ -501,8 +483,7 @@ class GroundingDataset(YOLODataset):
501
483
  LOGGER.warning(f"Skipping instance count verification for unrecognized dataset '{self.json_file}'")
502
484
 
503
485
  def cache_labels(self, path: Path = Path("./labels.cache")) -> dict[str, Any]:
504
- """
505
- Load annotations from a JSON file, filter, and normalize bounding boxes for each image.
486
+ """Load annotations from a JSON file, filter, and normalize bounding boxes for each image.
506
487
 
507
488
  Args:
508
489
  path (Path): Path where to save the cache file.
@@ -592,8 +573,7 @@ class GroundingDataset(YOLODataset):
592
573
  return x
593
574
 
594
575
  def get_labels(self) -> list[dict]:
595
- """
596
- Load labels from cache or generate them from JSON file.
576
+ """Load labels from cache or generate them from JSON file.
597
577
 
598
578
  Returns:
599
579
  (list[dict]): List of label dictionaries, each containing information about an image and its annotations.
@@ -614,8 +594,7 @@ class GroundingDataset(YOLODataset):
614
594
  return labels
615
595
 
616
596
  def build_transforms(self, hyp: dict | None = None) -> Compose:
617
- """
618
- Configure augmentations for training with optional text loading.
597
+ """Configure augmentations for training with optional text loading.
619
598
 
620
599
  Args:
621
600
  hyp (dict, optional): Hyperparameters for transforms.
@@ -661,11 +640,10 @@ class GroundingDataset(YOLODataset):
661
640
 
662
641
 
663
642
  class YOLOConcatDataset(ConcatDataset):
664
- """
665
- Dataset as a concatenation of multiple datasets.
643
+ """Dataset as a concatenation of multiple datasets.
666
644
 
667
- This class is useful to assemble different existing datasets for YOLO training, ensuring they use the same
668
- collation function.
645
+ This class is useful to assemble different existing datasets for YOLO training, ensuring they use the same collation
646
+ function.
669
647
 
670
648
  Methods:
671
649
  collate_fn: Static method that collates data samples into batches using YOLODataset's collation function.
@@ -678,8 +656,7 @@ class YOLOConcatDataset(ConcatDataset):
678
656
 
679
657
  @staticmethod
680
658
  def collate_fn(batch: list[dict]) -> dict:
681
- """
682
- Collate data samples into batches.
659
+ """Collate data samples into batches.
683
660
 
684
661
  Args:
685
662
  batch (list[dict]): List of dictionaries containing sample data.
@@ -690,8 +667,7 @@ class YOLOConcatDataset(ConcatDataset):
690
667
  return YOLODataset.collate_fn(batch)
691
668
 
692
669
  def close_mosaic(self, hyp: dict) -> None:
693
- """
694
- Set mosaic, copy_paste and mixup options to 0.0 and build transformations.
670
+ """Set mosaic, copy_paste and mixup options to 0.0 and build transformations.
695
671
 
696
672
  Args:
697
673
  hyp (dict): Hyperparameters for transforms.
@@ -712,8 +688,7 @@ class SemanticDataset(BaseDataset):
712
688
 
713
689
 
714
690
  class ClassificationDataset:
715
- """
716
- Dataset class for image classification tasks extending torchvision ImageFolder functionality.
691
+ """Dataset class for image classification tasks extending torchvision ImageFolder functionality.
717
692
 
718
693
  This class offers functionalities like image augmentation, caching, and verification. It's designed to efficiently
719
694
  handle large datasets for training deep learning models, with optional image transformations and caching mechanisms
@@ -723,7 +698,7 @@ class ClassificationDataset:
723
698
  cache_ram (bool): Indicates if caching in RAM is enabled.
724
699
  cache_disk (bool): Indicates if caching on disk is enabled.
725
700
  samples (list): A list of tuples, each containing the path to an image, its class index, path to its .npy cache
726
- file (if caching on disk), and optionally the loaded image array (if caching in RAM).
701
+ file (if caching on disk), and optionally the loaded image array (if caching in RAM).
727
702
  torch_transforms (callable): PyTorch transforms to be applied to the images.
728
703
  root (str): Root directory of the dataset.
729
704
  prefix (str): Prefix for logging and cache filenames.
@@ -735,8 +710,7 @@ class ClassificationDataset:
735
710
  """
736
711
 
737
712
  def __init__(self, root: str, args, augment: bool = False, prefix: str = ""):
738
- """
739
- Initialize YOLO classification dataset with root directory, arguments, augmentations, and cache settings.
713
+ """Initialize YOLO classification dataset with root directory, arguments, augmentations, and cache settings.
740
714
 
741
715
  Args:
742
716
  root (str): Path to the dataset directory where images are stored in a class-specific folder structure.
@@ -787,8 +761,7 @@ class ClassificationDataset:
787
761
  )
788
762
 
789
763
  def __getitem__(self, i: int) -> dict:
790
- """
791
- Return subset of data and targets corresponding to given indices.
764
+ """Return subset of data and targets corresponding to given indices.
792
765
 
793
766
  Args:
794
767
  i (int): Index of the sample to retrieve.
@@ -816,8 +789,7 @@ class ClassificationDataset:
816
789
  return len(self.samples)
817
790
 
818
791
  def verify_images(self) -> list[tuple]:
819
- """
820
- Verify all images in dataset.
792
+ """Verify all images in dataset.
821
793
 
822
794
  Returns:
823
795
  (list): List of valid samples after verification.
@@ -25,11 +25,10 @@ from ultralytics.utils.patches import imread
25
25
 
26
26
  @dataclass
27
27
  class SourceTypes:
28
- """
29
- Class to represent various types of input sources for predictions.
28
+ """Class to represent various types of input sources for predictions.
30
29
 
31
- This class uses dataclass to define boolean flags for different types of input sources that can be used for
32
- making predictions with YOLO models.
30
+ This class uses dataclass to define boolean flags for different types of input sources that can be used for making
31
+ predictions with YOLO models.
33
32
 
34
33
  Attributes:
35
34
  stream (bool): Flag indicating if the input source is a video stream.
@@ -52,11 +51,10 @@ class SourceTypes:
52
51
 
53
52
 
54
53
  class LoadStreams:
55
- """
56
- Stream Loader for various types of video streams.
54
+ """Stream Loader for various types of video streams.
57
55
 
58
- Supports RTSP, RTMP, HTTP, and TCP streams. This class handles the loading and processing of multiple video
59
- streams simultaneously, making it suitable for real-time video analysis tasks.
56
+ Supports RTSP, RTMP, HTTP, and TCP streams. This class handles the loading and processing of multiple video streams
57
+ simultaneously, making it suitable for real-time video analysis tasks.
60
58
 
61
59
  Attributes:
62
60
  sources (list[str]): The source input paths or URLs for the video streams.
@@ -94,8 +92,7 @@ class LoadStreams:
94
92
  """
95
93
 
96
94
  def __init__(self, sources: str = "file.streams", vid_stride: int = 1, buffer: bool = False, channels: int = 3):
97
- """
98
- Initialize stream loader for multiple video sources, supporting various stream types.
95
+ """Initialize stream loader for multiple video sources, supporting various stream types.
99
96
 
100
97
  Args:
101
98
  sources (str): Path to streams file or single stream URL.
@@ -227,11 +224,10 @@ class LoadStreams:
227
224
 
228
225
 
229
226
  class LoadScreenshots:
230
- """
231
- Ultralytics screenshot dataloader for capturing and processing screen images.
227
+ """Ultralytics screenshot dataloader for capturing and processing screen images.
232
228
 
233
- This class manages the loading of screenshot images for processing with YOLO. It is suitable for use with
234
- `yolo predict source=screen`.
229
+ This class manages the loading of screenshot images for processing with YOLO. It is suitable for use with `yolo
230
+ predict source=screen`.
235
231
 
236
232
  Attributes:
237
233
  source (str): The source input indicating which screen to capture.
@@ -259,8 +255,7 @@ class LoadScreenshots:
259
255
  """
260
256
 
261
257
  def __init__(self, source: str, channels: int = 3):
262
- """
263
- Initialize screenshot capture with specified screen and region parameters.
258
+ """Initialize screenshot capture with specified screen and region parameters.
264
259
 
265
260
  Args:
266
261
  source (str): Screen capture source string in format "screen_num left top width height".
@@ -307,11 +302,10 @@ class LoadScreenshots:
307
302
 
308
303
 
309
304
  class LoadImagesAndVideos:
310
- """
311
- A class for loading and processing images and videos for YOLO object detection.
305
+ """A class for loading and processing images and videos for YOLO object detection.
312
306
 
313
- This class manages the loading and pre-processing of image and video data from various sources, including
314
- single image files, video files, and lists of image and video paths.
307
+ This class manages the loading and pre-processing of image and video data from various sources, including single
308
+ image files, video files, and lists of image and video paths.
315
309
 
316
310
  Attributes:
317
311
  files (list[str]): List of image and video file paths.
@@ -347,8 +341,7 @@ class LoadImagesAndVideos:
347
341
  """
348
342
 
349
343
  def __init__(self, path: str | Path | list, batch: int = 1, vid_stride: int = 1, channels: int = 3):
350
- """
351
- Initialize dataloader for images and videos, supporting various input formats.
344
+ """Initialize dataloader for images and videos, supporting various input formats.
352
345
 
353
346
  Args:
354
347
  path (str | Path | list): Path to images/videos, directory, or list of paths.
@@ -490,8 +483,7 @@ class LoadImagesAndVideos:
490
483
 
491
484
 
492
485
  class LoadPilAndNumpy:
493
- """
494
- Load images from PIL and Numpy arrays for batch processing.
486
+ """Load images from PIL and Numpy arrays for batch processing.
495
487
 
496
488
  This class manages loading and pre-processing of image data from both PIL and Numpy formats. It performs basic
497
489
  validation and format conversion to ensure that the images are in the required format for downstream processing.
@@ -517,8 +509,7 @@ class LoadPilAndNumpy:
517
509
  """
518
510
 
519
511
  def __init__(self, im0: Image.Image | np.ndarray | list, channels: int = 3):
520
- """
521
- Initialize a loader for PIL and Numpy images, converting inputs to a standardized format.
512
+ """Initialize a loader for PIL and Numpy images, converting inputs to a standardized format.
522
513
 
523
514
  Args:
524
515
  im0 (PIL.Image.Image | np.ndarray | list): Single image or list of images in PIL or numpy format.
@@ -564,11 +555,10 @@ class LoadPilAndNumpy:
564
555
 
565
556
 
566
557
  class LoadTensor:
567
- """
568
- A class for loading and processing tensor data for object detection tasks.
558
+ """A class for loading and processing tensor data for object detection tasks.
569
559
 
570
- This class handles the loading and pre-processing of image data from PyTorch tensors, preparing them for
571
- further processing in object detection pipelines.
560
+ This class handles the loading and pre-processing of image data from PyTorch tensors, preparing them for further
561
+ processing in object detection pipelines.
572
562
 
573
563
  Attributes:
574
564
  im0 (torch.Tensor): The input tensor containing the image(s) with shape (B, C, H, W).
@@ -588,8 +578,7 @@ class LoadTensor:
588
578
  """
589
579
 
590
580
  def __init__(self, im0: torch.Tensor) -> None:
591
- """
592
- Initialize LoadTensor object for processing torch.Tensor image data.
581
+ """Initialize LoadTensor object for processing torch.Tensor image data.
593
582
 
594
583
  Args:
595
584
  im0 (torch.Tensor): Input tensor with shape (B, C, H, W).
@@ -656,8 +645,7 @@ def autocast_list(source: list[Any]) -> list[Image.Image | np.ndarray]:
656
645
 
657
646
 
658
647
  def get_best_youtube_url(url: str, method: str = "pytube") -> str | None:
659
- """
660
- Retrieve the URL of the best quality MP4 video stream from a given YouTube video.
648
+ """Retrieve the URL of the best quality MP4 video stream from a given YouTube video.
661
649
 
662
650
  Args:
663
651
  url (str): The URL of the YouTube video.
ultralytics/data/split.py CHANGED
@@ -11,11 +11,10 @@ from ultralytics.utils import DATASETS_DIR, LOGGER, TQDM
11
11
 
12
12
 
13
13
  def split_classify_dataset(source_dir: str | Path, train_ratio: float = 0.8) -> Path:
14
- """
15
- Split classification dataset into train and val directories in a new directory.
14
+ """Split classification dataset into train and val directories in a new directory.
16
15
 
17
- Creates a new directory '{source_dir}_split' with train/val subdirectories, preserving the original class
18
- structure with an 80/20 split by default.
16
+ Creates a new directory '{source_dir}_split' with train/val subdirectories, preserving the original class structure
17
+ with an 80/20 split by default.
19
18
 
20
19
  Directory structure:
21
20
  Before:
@@ -101,8 +100,8 @@ def autosplit(
101
100
  weights: tuple[float, float, float] = (0.9, 0.1, 0.0),
102
101
  annotated_only: bool = False,
103
102
  ) -> None:
104
- """
105
- Automatically split a dataset into train/val/test splits and save the resulting splits into autosplit_*.txt files.
103
+ """Automatically split a dataset into train/val/test splits and save the resulting splits into autosplit_*.txt
104
+ files.
106
105
 
107
106
  Args:
108
107
  path (Path): Path to images directory.
@@ -18,8 +18,7 @@ from ultralytics.utils.checks import check_requirements
18
18
 
19
19
 
20
20
  def bbox_iof(polygon1: np.ndarray, bbox2: np.ndarray, eps: float = 1e-6) -> np.ndarray:
21
- """
22
- Calculate Intersection over Foreground (IoF) between polygons and bounding boxes.
21
+ """Calculate Intersection over Foreground (IoF) between polygons and bounding boxes.
23
22
 
24
23
  Args:
25
24
  polygon1 (np.ndarray): Polygon coordinates with shape (N, 8).
@@ -65,8 +64,7 @@ def bbox_iof(polygon1: np.ndarray, bbox2: np.ndarray, eps: float = 1e-6) -> np.n
65
64
 
66
65
 
67
66
  def load_yolo_dota(data_root: str, split: str = "train") -> list[dict[str, Any]]:
68
- """
69
- Load DOTA dataset annotations and image information.
67
+ """Load DOTA dataset annotations and image information.
70
68
 
71
69
  Args:
72
70
  data_root (str): Data root directory.
@@ -107,8 +105,7 @@ def get_windows(
107
105
  im_rate_thr: float = 0.6,
108
106
  eps: float = 0.01,
109
107
  ) -> np.ndarray:
110
- """
111
- Get the coordinates of sliding windows for image cropping.
108
+ """Get the coordinates of sliding windows for image cropping.
112
109
 
113
110
  Args:
114
111
  im_size (tuple[int, int]): Original image size, (H, W).
@@ -118,7 +115,7 @@ def get_windows(
118
115
  eps (float, optional): Epsilon value for math operations.
119
116
 
120
117
  Returns:
121
- (np.ndarray): Array of window coordinates with shape (N, 4) where each row is [x_start, y_start, x_stop, y_stop].
118
+ (np.ndarray): Array of window coordinates of shape (N, 4) where each row is [x_start, y_start, x_stop, y_stop].
122
119
  """
123
120
  h, w = im_size
124
121
  windows = []
@@ -175,8 +172,7 @@ def crop_and_save(
175
172
  lb_dir: str,
176
173
  allow_background_images: bool = True,
177
174
  ) -> None:
178
- """
179
- Crop images and save new labels for each window.
175
+ """Crop images and save new labels for each window.
180
176
 
181
177
  Args:
182
178
  anno (dict[str, Any]): Annotation dict, including 'filepath', 'label', 'ori_size' as its keys.
@@ -226,8 +222,7 @@ def split_images_and_labels(
226
222
  crop_sizes: tuple[int, ...] = (1024,),
227
223
  gaps: tuple[int, ...] = (200,),
228
224
  ) -> None:
229
- """
230
- Split both images and labels for a given dataset split.
225
+ """Split both images and labels for a given dataset split.
231
226
 
232
227
  Args:
233
228
  data_root (str): Root directory of the dataset.
@@ -265,8 +260,7 @@ def split_images_and_labels(
265
260
  def split_trainval(
266
261
  data_root: str, save_dir: str, crop_size: int = 1024, gap: int = 200, rates: tuple[float, ...] = (1.0,)
267
262
  ) -> None:
268
- """
269
- Split train and val sets of DOTA dataset with multiple scaling rates.
263
+ """Split train and val sets of DOTA dataset with multiple scaling rates.
270
264
 
271
265
  Args:
272
266
  data_root (str): Root directory of the dataset.
@@ -304,8 +298,7 @@ def split_trainval(
304
298
  def split_test(
305
299
  data_root: str, save_dir: str, crop_size: int = 1024, gap: int = 200, rates: tuple[float, ...] = (1.0,)
306
300
  ) -> None:
307
- """
308
- Split test set of DOTA dataset, labels are not included within this set.
301
+ """Split test set of DOTA dataset, labels are not included within this set.
309
302
 
310
303
  Args:
311
304
  data_root (str): Root directory of the dataset.