dgenerate-ultralytics-headless 8.3.137__py3-none-any.whl → 8.3.224__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 (215) hide show
  1. {dgenerate_ultralytics_headless-8.3.137.dist-info → dgenerate_ultralytics_headless-8.3.224.dist-info}/METADATA +41 -34
  2. dgenerate_ultralytics_headless-8.3.224.dist-info/RECORD +285 -0
  3. {dgenerate_ultralytics_headless-8.3.137.dist-info → dgenerate_ultralytics_headless-8.3.224.dist-info}/WHEEL +1 -1
  4. tests/__init__.py +7 -6
  5. tests/conftest.py +15 -39
  6. tests/test_cli.py +17 -17
  7. tests/test_cuda.py +17 -8
  8. tests/test_engine.py +36 -10
  9. tests/test_exports.py +98 -37
  10. tests/test_integrations.py +12 -15
  11. tests/test_python.py +126 -82
  12. tests/test_solutions.py +319 -135
  13. ultralytics/__init__.py +27 -9
  14. ultralytics/cfg/__init__.py +83 -87
  15. ultralytics/cfg/datasets/Argoverse.yaml +4 -4
  16. ultralytics/cfg/datasets/DOTAv1.5.yaml +2 -2
  17. ultralytics/cfg/datasets/DOTAv1.yaml +2 -2
  18. ultralytics/cfg/datasets/GlobalWheat2020.yaml +2 -2
  19. ultralytics/cfg/datasets/HomeObjects-3K.yaml +4 -5
  20. ultralytics/cfg/datasets/ImageNet.yaml +3 -3
  21. ultralytics/cfg/datasets/Objects365.yaml +24 -20
  22. ultralytics/cfg/datasets/SKU-110K.yaml +9 -9
  23. ultralytics/cfg/datasets/VOC.yaml +10 -13
  24. ultralytics/cfg/datasets/VisDrone.yaml +43 -33
  25. ultralytics/cfg/datasets/african-wildlife.yaml +5 -5
  26. ultralytics/cfg/datasets/brain-tumor.yaml +4 -5
  27. ultralytics/cfg/datasets/carparts-seg.yaml +5 -5
  28. ultralytics/cfg/datasets/coco-pose.yaml +26 -4
  29. ultralytics/cfg/datasets/coco.yaml +4 -4
  30. ultralytics/cfg/datasets/coco128-seg.yaml +2 -2
  31. ultralytics/cfg/datasets/coco128.yaml +2 -2
  32. ultralytics/cfg/datasets/coco8-grayscale.yaml +103 -0
  33. ultralytics/cfg/datasets/coco8-multispectral.yaml +2 -2
  34. ultralytics/cfg/datasets/coco8-pose.yaml +23 -2
  35. ultralytics/cfg/datasets/coco8-seg.yaml +2 -2
  36. ultralytics/cfg/datasets/coco8.yaml +2 -2
  37. ultralytics/cfg/datasets/construction-ppe.yaml +32 -0
  38. ultralytics/cfg/datasets/crack-seg.yaml +5 -5
  39. ultralytics/cfg/datasets/dog-pose.yaml +32 -4
  40. ultralytics/cfg/datasets/dota8-multispectral.yaml +2 -2
  41. ultralytics/cfg/datasets/dota8.yaml +2 -2
  42. ultralytics/cfg/datasets/hand-keypoints.yaml +29 -4
  43. ultralytics/cfg/datasets/lvis.yaml +9 -9
  44. ultralytics/cfg/datasets/medical-pills.yaml +4 -5
  45. ultralytics/cfg/datasets/open-images-v7.yaml +7 -10
  46. ultralytics/cfg/datasets/package-seg.yaml +5 -5
  47. ultralytics/cfg/datasets/signature.yaml +4 -4
  48. ultralytics/cfg/datasets/tiger-pose.yaml +20 -4
  49. ultralytics/cfg/datasets/xView.yaml +5 -5
  50. ultralytics/cfg/default.yaml +96 -93
  51. ultralytics/cfg/trackers/botsort.yaml +16 -17
  52. ultralytics/cfg/trackers/bytetrack.yaml +9 -11
  53. ultralytics/data/__init__.py +4 -4
  54. ultralytics/data/annotator.py +12 -12
  55. ultralytics/data/augment.py +531 -564
  56. ultralytics/data/base.py +76 -81
  57. ultralytics/data/build.py +206 -42
  58. ultralytics/data/converter.py +179 -78
  59. ultralytics/data/dataset.py +121 -121
  60. ultralytics/data/loaders.py +114 -91
  61. ultralytics/data/split.py +28 -15
  62. ultralytics/data/split_dota.py +67 -48
  63. ultralytics/data/utils.py +110 -89
  64. ultralytics/engine/exporter.py +422 -460
  65. ultralytics/engine/model.py +224 -252
  66. ultralytics/engine/predictor.py +94 -89
  67. ultralytics/engine/results.py +345 -595
  68. ultralytics/engine/trainer.py +231 -134
  69. ultralytics/engine/tuner.py +279 -73
  70. ultralytics/engine/validator.py +53 -46
  71. ultralytics/hub/__init__.py +26 -28
  72. ultralytics/hub/auth.py +30 -16
  73. ultralytics/hub/google/__init__.py +34 -36
  74. ultralytics/hub/session.py +53 -77
  75. ultralytics/hub/utils.py +23 -109
  76. ultralytics/models/__init__.py +1 -1
  77. ultralytics/models/fastsam/__init__.py +1 -1
  78. ultralytics/models/fastsam/model.py +36 -18
  79. ultralytics/models/fastsam/predict.py +33 -44
  80. ultralytics/models/fastsam/utils.py +4 -5
  81. ultralytics/models/fastsam/val.py +12 -14
  82. ultralytics/models/nas/__init__.py +1 -1
  83. ultralytics/models/nas/model.py +16 -20
  84. ultralytics/models/nas/predict.py +12 -14
  85. ultralytics/models/nas/val.py +4 -5
  86. ultralytics/models/rtdetr/__init__.py +1 -1
  87. ultralytics/models/rtdetr/model.py +9 -9
  88. ultralytics/models/rtdetr/predict.py +22 -17
  89. ultralytics/models/rtdetr/train.py +20 -16
  90. ultralytics/models/rtdetr/val.py +79 -59
  91. ultralytics/models/sam/__init__.py +8 -2
  92. ultralytics/models/sam/amg.py +53 -38
  93. ultralytics/models/sam/build.py +29 -31
  94. ultralytics/models/sam/model.py +33 -38
  95. ultralytics/models/sam/modules/blocks.py +159 -182
  96. ultralytics/models/sam/modules/decoders.py +38 -47
  97. ultralytics/models/sam/modules/encoders.py +114 -133
  98. ultralytics/models/sam/modules/memory_attention.py +38 -31
  99. ultralytics/models/sam/modules/sam.py +114 -93
  100. ultralytics/models/sam/modules/tiny_encoder.py +268 -291
  101. ultralytics/models/sam/modules/transformer.py +59 -66
  102. ultralytics/models/sam/modules/utils.py +55 -72
  103. ultralytics/models/sam/predict.py +745 -341
  104. ultralytics/models/utils/loss.py +118 -107
  105. ultralytics/models/utils/ops.py +118 -71
  106. ultralytics/models/yolo/__init__.py +1 -1
  107. ultralytics/models/yolo/classify/predict.py +28 -26
  108. ultralytics/models/yolo/classify/train.py +50 -81
  109. ultralytics/models/yolo/classify/val.py +68 -61
  110. ultralytics/models/yolo/detect/predict.py +12 -15
  111. ultralytics/models/yolo/detect/train.py +56 -46
  112. ultralytics/models/yolo/detect/val.py +279 -223
  113. ultralytics/models/yolo/model.py +167 -86
  114. ultralytics/models/yolo/obb/predict.py +7 -11
  115. ultralytics/models/yolo/obb/train.py +23 -25
  116. ultralytics/models/yolo/obb/val.py +107 -99
  117. ultralytics/models/yolo/pose/__init__.py +1 -1
  118. ultralytics/models/yolo/pose/predict.py +12 -14
  119. ultralytics/models/yolo/pose/train.py +31 -69
  120. ultralytics/models/yolo/pose/val.py +119 -254
  121. ultralytics/models/yolo/segment/predict.py +21 -25
  122. ultralytics/models/yolo/segment/train.py +12 -66
  123. ultralytics/models/yolo/segment/val.py +126 -305
  124. ultralytics/models/yolo/world/train.py +53 -45
  125. ultralytics/models/yolo/world/train_world.py +51 -32
  126. ultralytics/models/yolo/yoloe/__init__.py +7 -7
  127. ultralytics/models/yolo/yoloe/predict.py +30 -37
  128. ultralytics/models/yolo/yoloe/train.py +89 -71
  129. ultralytics/models/yolo/yoloe/train_seg.py +15 -17
  130. ultralytics/models/yolo/yoloe/val.py +56 -41
  131. ultralytics/nn/__init__.py +9 -11
  132. ultralytics/nn/autobackend.py +179 -107
  133. ultralytics/nn/modules/__init__.py +67 -67
  134. ultralytics/nn/modules/activation.py +8 -7
  135. ultralytics/nn/modules/block.py +302 -323
  136. ultralytics/nn/modules/conv.py +61 -104
  137. ultralytics/nn/modules/head.py +488 -186
  138. ultralytics/nn/modules/transformer.py +183 -123
  139. ultralytics/nn/modules/utils.py +15 -20
  140. ultralytics/nn/tasks.py +327 -203
  141. ultralytics/nn/text_model.py +81 -65
  142. ultralytics/py.typed +1 -0
  143. ultralytics/solutions/__init__.py +12 -12
  144. ultralytics/solutions/ai_gym.py +19 -27
  145. ultralytics/solutions/analytics.py +36 -26
  146. ultralytics/solutions/config.py +29 -28
  147. ultralytics/solutions/distance_calculation.py +23 -24
  148. ultralytics/solutions/heatmap.py +17 -19
  149. ultralytics/solutions/instance_segmentation.py +21 -19
  150. ultralytics/solutions/object_blurrer.py +16 -17
  151. ultralytics/solutions/object_counter.py +48 -53
  152. ultralytics/solutions/object_cropper.py +22 -16
  153. ultralytics/solutions/parking_management.py +61 -58
  154. ultralytics/solutions/queue_management.py +19 -19
  155. ultralytics/solutions/region_counter.py +63 -50
  156. ultralytics/solutions/security_alarm.py +22 -25
  157. ultralytics/solutions/similarity_search.py +107 -60
  158. ultralytics/solutions/solutions.py +343 -262
  159. ultralytics/solutions/speed_estimation.py +35 -31
  160. ultralytics/solutions/streamlit_inference.py +104 -40
  161. ultralytics/solutions/templates/similarity-search.html +31 -24
  162. ultralytics/solutions/trackzone.py +24 -24
  163. ultralytics/solutions/vision_eye.py +11 -12
  164. ultralytics/trackers/__init__.py +1 -1
  165. ultralytics/trackers/basetrack.py +18 -27
  166. ultralytics/trackers/bot_sort.py +48 -39
  167. ultralytics/trackers/byte_tracker.py +94 -94
  168. ultralytics/trackers/track.py +7 -16
  169. ultralytics/trackers/utils/gmc.py +37 -69
  170. ultralytics/trackers/utils/kalman_filter.py +68 -76
  171. ultralytics/trackers/utils/matching.py +13 -17
  172. ultralytics/utils/__init__.py +251 -275
  173. ultralytics/utils/autobatch.py +19 -7
  174. ultralytics/utils/autodevice.py +68 -38
  175. ultralytics/utils/benchmarks.py +169 -130
  176. ultralytics/utils/callbacks/base.py +12 -13
  177. ultralytics/utils/callbacks/clearml.py +14 -15
  178. ultralytics/utils/callbacks/comet.py +139 -66
  179. ultralytics/utils/callbacks/dvc.py +19 -27
  180. ultralytics/utils/callbacks/hub.py +8 -6
  181. ultralytics/utils/callbacks/mlflow.py +6 -10
  182. ultralytics/utils/callbacks/neptune.py +11 -19
  183. ultralytics/utils/callbacks/platform.py +73 -0
  184. ultralytics/utils/callbacks/raytune.py +3 -4
  185. ultralytics/utils/callbacks/tensorboard.py +9 -12
  186. ultralytics/utils/callbacks/wb.py +33 -30
  187. ultralytics/utils/checks.py +163 -114
  188. ultralytics/utils/cpu.py +89 -0
  189. ultralytics/utils/dist.py +24 -20
  190. ultralytics/utils/downloads.py +176 -146
  191. ultralytics/utils/errors.py +11 -13
  192. ultralytics/utils/events.py +113 -0
  193. ultralytics/utils/export/__init__.py +7 -0
  194. ultralytics/utils/{export.py → export/engine.py} +81 -63
  195. ultralytics/utils/export/imx.py +294 -0
  196. ultralytics/utils/export/tensorflow.py +217 -0
  197. ultralytics/utils/files.py +33 -36
  198. ultralytics/utils/git.py +137 -0
  199. ultralytics/utils/instance.py +105 -120
  200. ultralytics/utils/logger.py +404 -0
  201. ultralytics/utils/loss.py +99 -61
  202. ultralytics/utils/metrics.py +649 -478
  203. ultralytics/utils/nms.py +337 -0
  204. ultralytics/utils/ops.py +263 -451
  205. ultralytics/utils/patches.py +70 -31
  206. ultralytics/utils/plotting.py +253 -223
  207. ultralytics/utils/tal.py +48 -61
  208. ultralytics/utils/torch_utils.py +244 -251
  209. ultralytics/utils/tqdm.py +438 -0
  210. ultralytics/utils/triton.py +22 -23
  211. ultralytics/utils/tuner.py +11 -10
  212. dgenerate_ultralytics_headless-8.3.137.dist-info/RECORD +0 -272
  213. {dgenerate_ultralytics_headless-8.3.137.dist-info → dgenerate_ultralytics_headless-8.3.224.dist-info}/entry_points.txt +0 -0
  214. {dgenerate_ultralytics_headless-8.3.137.dist-info → dgenerate_ultralytics_headless-8.3.224.dist-info}/licenses/LICENSE +0 -0
  215. {dgenerate_ultralytics_headless-8.3.137.dist-info → dgenerate_ultralytics_headless-8.3.224.dist-info}/top_level.txt +0 -0
ultralytics/data/base.py CHANGED
@@ -1,5 +1,7 @@
1
1
  # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2
2
 
3
+ from __future__ import annotations
4
+
3
5
  import glob
4
6
  import math
5
7
  import os
@@ -7,7 +9,7 @@ import random
7
9
  from copy import deepcopy
8
10
  from multiprocessing.pool import ThreadPool
9
11
  from pathlib import Path
10
- from typing import Optional
12
+ from typing import Any
11
13
 
12
14
  import cv2
13
15
  import numpy as np
@@ -19,11 +21,10 @@ from ultralytics.utils.patches import imread
19
21
 
20
22
 
21
23
  class BaseDataset(Dataset):
22
- """
23
- Base dataset class for loading and processing image data.
24
+ """Base dataset class for loading and processing image data.
24
25
 
25
- This class provides core functionality for loading images, caching, and preparing data for training and inference
26
- in object detection tasks.
26
+ This class provides core functionality for loading images, caching, and preparing data for training and inference in
27
+ object detection tasks.
27
28
 
28
29
  Attributes:
29
30
  img_path (str): Path to the folder containing images.
@@ -32,9 +33,10 @@ class BaseDataset(Dataset):
32
33
  single_cls (bool): Whether to treat all objects as a single class.
33
34
  prefix (str): Prefix to print in log messages.
34
35
  fraction (float): Fraction of dataset to utilize.
36
+ channels (int): Number of channels in the images (1 for grayscale, 3 for RGB).
35
37
  cv2_flag (int): OpenCV flag for reading images.
36
- im_files (List[str]): List of image file paths.
37
- labels (List[Dict]): List of label data dictionaries.
38
+ im_files (list[str]): List of image file paths.
39
+ labels (list[dict]): List of label data dictionaries.
38
40
  ni (int): Number of images in the dataset.
39
41
  rect (bool): Whether to use rectangular training.
40
42
  batch_size (int): Size of batches.
@@ -45,9 +47,11 @@ class BaseDataset(Dataset):
45
47
  ims (list): List of loaded images.
46
48
  im_hw0 (list): List of original image dimensions (h, w).
47
49
  im_hw (list): List of resized image dimensions (h, w).
48
- npy_files (List[Path]): List of numpy file paths.
50
+ npy_files (list[Path]): List of numpy file paths.
49
51
  cache (str): Cache images to RAM or disk during training.
50
52
  transforms (callable): Image transformation function.
53
+ batch_shapes (np.ndarray): Batch shapes for rectangular training.
54
+ batch (np.ndarray): Batch index of each image.
51
55
 
52
56
  Methods:
53
57
  get_img_files: Read image files from the specified path.
@@ -66,39 +70,38 @@ class BaseDataset(Dataset):
66
70
 
67
71
  def __init__(
68
72
  self,
69
- img_path,
70
- imgsz=640,
71
- cache=False,
72
- augment=True,
73
- hyp=DEFAULT_CFG,
74
- prefix="",
75
- rect=False,
76
- batch_size=16,
77
- stride=32,
78
- pad=0.5,
79
- single_cls=False,
80
- classes=None,
81
- fraction=1.0,
82
- channels=3,
73
+ img_path: str | list[str],
74
+ imgsz: int = 640,
75
+ cache: bool | str = False,
76
+ augment: bool = True,
77
+ hyp: dict[str, Any] = DEFAULT_CFG,
78
+ prefix: str = "",
79
+ rect: bool = False,
80
+ batch_size: int = 16,
81
+ stride: int = 32,
82
+ pad: float = 0.5,
83
+ single_cls: bool = False,
84
+ classes: list[int] | None = None,
85
+ fraction: float = 1.0,
86
+ channels: int = 3,
83
87
  ):
84
- """
85
- Initialize BaseDataset with given configuration and options.
88
+ """Initialize BaseDataset with given configuration and options.
86
89
 
87
90
  Args:
88
- img_path (str): Path to the folder containing images.
89
- imgsz (int, optional): Image size for resizing.
90
- cache (bool | str, optional): Cache images to RAM or disk during training.
91
- augment (bool, optional): If True, data augmentation is applied.
92
- hyp (dict, optional): Hyperparameters to apply data augmentation.
93
- prefix (str, optional): Prefix to print in log messages.
94
- rect (bool, optional): If True, rectangular training is used.
95
- batch_size (int, optional): Size of batches.
96
- stride (int, optional): Stride used in the model.
97
- pad (float, optional): Padding value.
98
- single_cls (bool, optional): If True, single class training is used.
99
- classes (list, optional): List of included classes.
100
- fraction (float, optional): Fraction of dataset to utilize.
101
- channels (int, optional): Number of channels in the images (1 for grayscale, 3 for RGB).
91
+ img_path (str | list[str]): Path to the folder containing images or list of image paths.
92
+ imgsz (int): Image size for resizing.
93
+ cache (bool | str): Cache images to RAM or disk during training.
94
+ augment (bool): If True, data augmentation is applied.
95
+ hyp (dict[str, Any]): Hyperparameters to apply data augmentation.
96
+ prefix (str): Prefix to print in log messages.
97
+ rect (bool): If True, rectangular training is used.
98
+ batch_size (int): Size of batches.
99
+ stride (int): Stride used in the model.
100
+ pad (float): Padding value.
101
+ single_cls (bool): If True, single class training is used.
102
+ classes (list[int], optional): List of included classes.
103
+ fraction (float): Fraction of dataset to utilize.
104
+ channels (int): Number of channels in the images (1 for grayscale, 3 for RGB).
102
105
  """
103
106
  super().__init__()
104
107
  self.img_path = img_path
@@ -142,15 +145,14 @@ class BaseDataset(Dataset):
142
145
  # Transforms
143
146
  self.transforms = self.build_transforms(hyp=hyp)
144
147
 
145
- def get_img_files(self, img_path):
146
- """
147
- Read image files from the specified path.
148
+ def get_img_files(self, img_path: str | list[str]) -> list[str]:
149
+ """Read image files from the specified path.
148
150
 
149
151
  Args:
150
- img_path (str | List[str]): Path or list of paths to image directories or files.
152
+ img_path (str | list[str]): Path or list of paths to image directories or files.
151
153
 
152
154
  Returns:
153
- (List[str]): List of image file paths.
155
+ (list[str]): List of image file paths.
154
156
 
155
157
  Raises:
156
158
  FileNotFoundError: If no images are found or the path doesn't exist.
@@ -170,7 +172,7 @@ class BaseDataset(Dataset):
170
172
  # F += [p.parent / x.lstrip(os.sep) for x in t] # local to global path (pathlib)
171
173
  else:
172
174
  raise FileNotFoundError(f"{self.prefix}{p} does not exist")
173
- im_files = sorted(x.replace("/", os.sep) for x in f if x.split(".")[-1].lower() in IMG_FORMATS)
175
+ im_files = sorted(x.replace("/", os.sep) for x in f if x.rpartition(".")[-1].lower() in IMG_FORMATS)
174
176
  # self.img_files = sorted([x for x in f if x.suffix[1:].lower() in IMG_FORMATS]) # pathlib
175
177
  assert im_files, f"{self.prefix}No images found in {img_path}. {FORMATS_HELP_MSG}"
176
178
  except Exception as e:
@@ -180,12 +182,11 @@ class BaseDataset(Dataset):
180
182
  check_file_speeds(im_files, prefix=self.prefix) # check image read speeds
181
183
  return im_files
182
184
 
183
- def update_labels(self, include_class: Optional[list]):
184
- """
185
- Update labels to include only specified classes.
185
+ def update_labels(self, include_class: list[int] | None) -> None:
186
+ """Update labels to include only specified classes.
186
187
 
187
188
  Args:
188
- include_class (list, optional): List of classes to include. If None, all classes are included.
189
+ include_class (list[int], optional): List of classes to include. If None, all classes are included.
189
190
  """
190
191
  include_class_array = np.array(include_class).reshape(1, -1)
191
192
  for i in range(len(self.labels)):
@@ -204,18 +205,17 @@ class BaseDataset(Dataset):
204
205
  if self.single_cls:
205
206
  self.labels[i]["cls"][:, 0] = 0
206
207
 
207
- def load_image(self, i, rect_mode=True):
208
- """
209
- Load an image from dataset index 'i'.
208
+ def load_image(self, i: int, rect_mode: bool = True) -> tuple[np.ndarray, tuple[int, int], tuple[int, int]]:
209
+ """Load an image from dataset index 'i'.
210
210
 
211
211
  Args:
212
212
  i (int): Index of the image to load.
213
- rect_mode (bool, optional): Whether to use rectangular resizing.
213
+ rect_mode (bool): Whether to use rectangular resizing.
214
214
 
215
215
  Returns:
216
- (np.ndarray): Loaded image as a NumPy array.
217
- (Tuple[int, int]): Original image dimensions in (height, width) format.
218
- (Tuple[int, int]): Resized image dimensions in (height, width) format.
216
+ im (np.ndarray): Loaded image as a NumPy array.
217
+ hw_original (tuple[int, int]): Original image dimensions in (height, width) format.
218
+ hw_resized (tuple[int, int]): Resized image dimensions in (height, width) format.
219
219
 
220
220
  Raises:
221
221
  FileNotFoundError: If the image file is not found.
@@ -258,7 +258,7 @@ class BaseDataset(Dataset):
258
258
 
259
259
  return self.ims[i], self.im_hw0[i], self.im_hw[i]
260
260
 
261
- def cache_images(self):
261
+ def cache_images(self) -> None:
262
262
  """Cache images to memory or disk for faster training."""
263
263
  b, gb = 0, 1 << 30 # bytes of cached images, bytes per gigabytes
264
264
  fcn, storage = (self.cache_images_to_disk, "Disk") if self.cache == "disk" else (self.load_image, "RAM")
@@ -274,18 +274,17 @@ class BaseDataset(Dataset):
274
274
  pbar.desc = f"{self.prefix}Caching images ({b / gb:.1f}GB {storage})"
275
275
  pbar.close()
276
276
 
277
- def cache_images_to_disk(self, i):
277
+ def cache_images_to_disk(self, i: int) -> None:
278
278
  """Save an image as an *.npy file for faster loading."""
279
279
  f = self.npy_files[i]
280
280
  if not f.exists():
281
281
  np.save(f.as_posix(), imread(self.im_files[i]), allow_pickle=False)
282
282
 
283
- def check_cache_disk(self, safety_margin=0.5):
284
- """
285
- Check if there's enough disk space for caching images.
283
+ def check_cache_disk(self, safety_margin: float = 0.5) -> bool:
284
+ """Check if there's enough disk space for caching images.
286
285
 
287
286
  Args:
288
- safety_margin (float, optional): Safety margin factor for disk space calculation.
287
+ safety_margin (float): Safety margin factor for disk space calculation.
289
288
 
290
289
  Returns:
291
290
  (bool): True if there's enough disk space, False otherwise.
@@ -302,10 +301,10 @@ class BaseDataset(Dataset):
302
301
  b += im.nbytes
303
302
  if not os.access(Path(im_file).parent, os.W_OK):
304
303
  self.cache = None
305
- LOGGER.warning(f"{self.prefix}Skipping caching images to disk, directory not writeable")
304
+ LOGGER.warning(f"{self.prefix}Skipping caching images to disk, directory not writable")
306
305
  return False
307
306
  disk_required = b * self.ni / n * (1 + safety_margin) # bytes required to cache dataset to disk
308
- total, used, free = shutil.disk_usage(Path(self.im_files[0]).parent)
307
+ total, _used, free = shutil.disk_usage(Path(self.im_files[0]).parent)
309
308
  if disk_required > free:
310
309
  self.cache = None
311
310
  LOGGER.warning(
@@ -316,12 +315,11 @@ class BaseDataset(Dataset):
316
315
  return False
317
316
  return True
318
317
 
319
- def check_cache_ram(self, safety_margin=0.5):
320
- """
321
- Check if there's enough RAM for caching images.
318
+ def check_cache_ram(self, safety_margin: float = 0.5) -> bool:
319
+ """Check if there's enough RAM for caching images.
322
320
 
323
321
  Args:
324
- safety_margin (float, optional): Safety margin factor for RAM calculation.
322
+ safety_margin (float): Safety margin factor for RAM calculation.
325
323
 
326
324
  Returns:
327
325
  (bool): True if there's enough RAM, False otherwise.
@@ -346,7 +344,7 @@ class BaseDataset(Dataset):
346
344
  return False
347
345
  return True
348
346
 
349
- def set_rectangle(self):
347
+ def set_rectangle(self) -> None:
350
348
  """Set the shape of bounding boxes for YOLO detections as rectangles."""
351
349
  bi = np.floor(np.arange(self.ni) / self.batch_size).astype(int) # batch index
352
350
  nb = bi[-1] + 1 # number of batches
@@ -371,19 +369,18 @@ class BaseDataset(Dataset):
371
369
  self.batch_shapes = np.ceil(np.array(shapes) * self.imgsz / self.stride + self.pad).astype(int) * self.stride
372
370
  self.batch = bi # batch index of image
373
371
 
374
- def __getitem__(self, index):
372
+ def __getitem__(self, index: int) -> dict[str, Any]:
375
373
  """Return transformed label information for given index."""
376
374
  return self.transforms(self.get_image_and_label(index))
377
375
 
378
- def get_image_and_label(self, index):
379
- """
380
- Get and return label information from the dataset.
376
+ def get_image_and_label(self, index: int) -> dict[str, Any]:
377
+ """Get and return label information from the dataset.
381
378
 
382
379
  Args:
383
380
  index (int): Index of the image to retrieve.
384
381
 
385
382
  Returns:
386
- (dict): Label dictionary with image and metadata.
383
+ (dict[str, Any]): Label dictionary with image and metadata.
387
384
  """
388
385
  label = deepcopy(self.labels[index]) # requires deepcopy() https://github.com/ultralytics/ultralytics/pull/1948
389
386
  label.pop("shape", None) # shape is for rect, remove it
@@ -396,17 +393,16 @@ class BaseDataset(Dataset):
396
393
  label["rect_shape"] = self.batch_shapes[self.batch[index]]
397
394
  return self.update_labels_info(label)
398
395
 
399
- def __len__(self):
396
+ def __len__(self) -> int:
400
397
  """Return the length of the labels list for the dataset."""
401
398
  return len(self.labels)
402
399
 
403
- def update_labels_info(self, label):
400
+ def update_labels_info(self, label: dict[str, Any]) -> dict[str, Any]:
404
401
  """Custom your label format here."""
405
402
  return label
406
403
 
407
- def build_transforms(self, hyp=None):
408
- """
409
- Users can customize augmentations here.
404
+ def build_transforms(self, hyp: dict[str, Any] | None = None):
405
+ """Users can customize augmentations here.
410
406
 
411
407
  Examples:
412
408
  >>> if self.augment:
@@ -418,9 +414,8 @@ class BaseDataset(Dataset):
418
414
  """
419
415
  raise NotImplementedError
420
416
 
421
- def get_labels(self):
422
- """
423
- Users can customize their own format here.
417
+ def get_labels(self) -> list[dict[str, Any]]:
418
+ """Users can customize their own format here.
424
419
 
425
420
  Examples:
426
421
  Ensure output is a dictionary with the following keys: