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
@@ -1,8 +1,13 @@
1
1
  # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2
2
  """Monkey patches to update/extend functionality of existing functions."""
3
3
 
4
+ from __future__ import annotations
5
+
4
6
  import time
7
+ from contextlib import contextmanager
8
+ from copy import copy
5
9
  from pathlib import Path
10
+ from typing import Any
6
11
 
7
12
  import cv2
8
13
  import numpy as np
@@ -12,16 +17,15 @@ import torch
12
17
  _imshow = cv2.imshow # copy to avoid recursion errors
13
18
 
14
19
 
15
- def imread(filename: str, flags: int = cv2.IMREAD_COLOR):
16
- """
17
- Read an image from a file.
20
+ def imread(filename: str, flags: int = cv2.IMREAD_COLOR) -> np.ndarray | None:
21
+ """Read an image from a file with multilanguage filename support.
18
22
 
19
23
  Args:
20
24
  filename (str): Path to the file to read.
21
- flags (int): Flag that can take values of cv2.IMREAD_*. Controls how the image is read.
25
+ flags (int, optional): Flag that can take values of cv2.IMREAD_*. Controls how the image is read.
22
26
 
23
27
  Returns:
24
- (np.ndarray): The read image.
28
+ (np.ndarray | None): The read image array, or None if reading fails.
25
29
 
26
30
  Examples:
27
31
  >>> img = imread("path/to/image.jpg")
@@ -31,22 +35,21 @@ def imread(filename: str, flags: int = cv2.IMREAD_COLOR):
31
35
  if filename.endswith((".tiff", ".tif")):
32
36
  success, frames = cv2.imdecodemulti(file_bytes, cv2.IMREAD_UNCHANGED)
33
37
  if success:
34
- # handle RGB images in tif/tiff format
38
+ # Handle RGB images in tif/tiff format
35
39
  return frames[0] if len(frames) == 1 and frames[0].ndim == 3 else np.stack(frames, axis=2)
36
40
  return None
37
41
  else:
38
42
  im = cv2.imdecode(file_bytes, flags)
39
- return im[..., None] if im.ndim == 2 else im # always make sure there's 3 dimensions
43
+ return im[..., None] if im is not None and im.ndim == 2 else im # Always ensure 3 dimensions
40
44
 
41
45
 
42
- def imwrite(filename: str, img: np.ndarray, params=None):
43
- """
44
- Write an image to a file.
46
+ def imwrite(filename: str, img: np.ndarray, params: list[int] | None = None) -> bool:
47
+ """Write an image to a file with multilanguage filename support.
45
48
 
46
49
  Args:
47
50
  filename (str): Path to the file to write.
48
51
  img (np.ndarray): Image to write.
49
- params (List[int], optional): Additional parameters for image encoding.
52
+ params (list[int], optional): Additional parameters for image encoding.
50
53
 
51
54
  Returns:
52
55
  (bool): True if the file was written successfully, False otherwise.
@@ -65,16 +68,15 @@ def imwrite(filename: str, img: np.ndarray, params=None):
65
68
  return False
66
69
 
67
70
 
68
- def imshow(winname: str, mat: np.ndarray):
69
- """
70
- Display an image in the specified window.
71
+ def imshow(winname: str, mat: np.ndarray) -> None:
72
+ """Display an image in the specified window with multilanguage window name support.
71
73
 
72
- This function is a wrapper around OpenCV's imshow function that displays an image in a named window. It is
73
- particularly useful for visualizing images during development and debugging.
74
+ This function is a wrapper around OpenCV's imshow function that displays an image in a named window. It handles
75
+ multilanguage window names by encoding them properly for OpenCV compatibility.
74
76
 
75
77
  Args:
76
- winname (str): Name of the window where the image will be displayed. If a window with this name already
77
- exists, the image will be displayed in that window.
78
+ winname (str): Name of the window where the image will be displayed. If a window with this name already exists,
79
+ the image will be displayed in that window.
78
80
  mat (np.ndarray): Image to be shown. Should be a valid numpy array representing an image.
79
81
 
80
82
  Examples:
@@ -87,13 +89,11 @@ def imshow(winname: str, mat: np.ndarray):
87
89
 
88
90
 
89
91
  # PyTorch functions ----------------------------------------------------------------------------------------------------
90
- _torch_load = torch.load # copy to avoid recursion errors
91
92
  _torch_save = torch.save
92
93
 
93
94
 
94
95
  def torch_load(*args, **kwargs):
95
- """
96
- Load a PyTorch model with updated arguments to avoid warnings.
96
+ """Load a PyTorch model with updated arguments to avoid warnings.
97
97
 
98
98
  This function wraps torch.load and adds the 'weights_only' argument for PyTorch 1.13.0+ to prevent warnings.
99
99
 
@@ -113,23 +113,19 @@ def torch_load(*args, **kwargs):
113
113
  if TORCH_1_13 and "weights_only" not in kwargs:
114
114
  kwargs["weights_only"] = False
115
115
 
116
- return _torch_load(*args, **kwargs)
116
+ return torch.load(*args, **kwargs)
117
117
 
118
118
 
119
119
  def torch_save(*args, **kwargs):
120
- """
121
- Save PyTorch objects with retry mechanism for robustness.
120
+ """Save PyTorch objects with retry mechanism for robustness.
122
121
 
123
- This function wraps torch.save with 3 retries and exponential backoff in case of save failures, which can occur
124
- due to device flushing delays or antivirus scanning.
122
+ This function wraps torch.save with 3 retries and exponential backoff in case of save failures, which can occur due
123
+ to device flushing delays or antivirus scanning.
125
124
 
126
125
  Args:
127
126
  *args (Any): Positional arguments to pass to torch.save.
128
127
  **kwargs (Any): Keyword arguments to pass to torch.save.
129
128
 
130
- Returns:
131
- (Any): Result of torch.save operation if successful, None otherwise.
132
-
133
129
  Examples:
134
130
  >>> model = torch.nn.Linear(10, 1)
135
131
  >>> torch_save(model.state_dict(), "model.pt")
@@ -137,7 +133,50 @@ def torch_save(*args, **kwargs):
137
133
  for i in range(4): # 3 retries
138
134
  try:
139
135
  return _torch_save(*args, **kwargs)
140
- except RuntimeError as e: # unable to save, possibly waiting for device to flush or antivirus scan
136
+ except RuntimeError as e: # Unable to save, possibly waiting for device to flush or antivirus scan
141
137
  if i == 3:
142
138
  raise e
143
- time.sleep((2**i) / 2) # exponential standoff: 0.5s, 1.0s, 2.0s
139
+ time.sleep((2**i) / 2) # Exponential backoff: 0.5s, 1.0s, 2.0s
140
+
141
+
142
+ @contextmanager
143
+ def arange_patch(args):
144
+ """Workaround for ONNX torch.arange incompatibility with FP16.
145
+
146
+ https://github.com/pytorch/pytorch/issues/148041.
147
+ """
148
+ if args.dynamic and args.half and args.format == "onnx":
149
+ func = torch.arange
150
+
151
+ def arange(*args, dtype=None, **kwargs):
152
+ """Return a 1-D tensor of size with values from the interval and common difference."""
153
+ return func(*args, **kwargs).to(dtype) # cast to dtype instead of passing dtype
154
+
155
+ torch.arange = arange # patch
156
+ yield
157
+ torch.arange = func # unpatch
158
+ else:
159
+ yield
160
+
161
+
162
+ @contextmanager
163
+ def override_configs(args, overrides: dict[str, Any] | None = None):
164
+ """Context manager to temporarily override configurations in args.
165
+
166
+ Args:
167
+ args (IterableSimpleNamespace): Original configuration arguments.
168
+ overrides (dict[str, Any]): Dictionary of overrides to apply.
169
+
170
+ Yields:
171
+ (IterableSimpleNamespace): Configuration arguments with overrides applied.
172
+ """
173
+ if overrides:
174
+ original_args = copy(args)
175
+ for key, value in overrides.items():
176
+ setattr(args, key, value)
177
+ try:
178
+ yield args
179
+ finally:
180
+ args.__dict__.update(original_args.__dict__)
181
+ else:
182
+ yield args