dgenerate-ultralytics-headless 8.3.214__py3-none-any.whl → 8.4.7__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 (249) hide show
  1. {dgenerate_ultralytics_headless-8.3.214.dist-info → dgenerate_ultralytics_headless-8.4.7.dist-info}/METADATA +64 -74
  2. dgenerate_ultralytics_headless-8.4.7.dist-info/RECORD +311 -0
  3. {dgenerate_ultralytics_headless-8.3.214.dist-info → dgenerate_ultralytics_headless-8.4.7.dist-info}/WHEEL +1 -1
  4. tests/__init__.py +7 -9
  5. tests/conftest.py +8 -15
  6. tests/test_cli.py +1 -1
  7. tests/test_cuda.py +13 -10
  8. tests/test_engine.py +9 -9
  9. tests/test_exports.py +65 -13
  10. tests/test_integrations.py +13 -13
  11. tests/test_python.py +125 -69
  12. tests/test_solutions.py +161 -152
  13. ultralytics/__init__.py +1 -1
  14. ultralytics/cfg/__init__.py +86 -92
  15. ultralytics/cfg/datasets/Argoverse.yaml +7 -6
  16. ultralytics/cfg/datasets/DOTAv1.5.yaml +1 -1
  17. ultralytics/cfg/datasets/DOTAv1.yaml +1 -1
  18. ultralytics/cfg/datasets/ImageNet.yaml +1 -1
  19. ultralytics/cfg/datasets/TT100K.yaml +346 -0
  20. ultralytics/cfg/datasets/VOC.yaml +15 -16
  21. ultralytics/cfg/datasets/african-wildlife.yaml +1 -1
  22. ultralytics/cfg/datasets/coco-pose.yaml +21 -0
  23. ultralytics/cfg/datasets/coco12-formats.yaml +101 -0
  24. ultralytics/cfg/datasets/coco128-seg.yaml +1 -1
  25. ultralytics/cfg/datasets/coco8-pose.yaml +21 -0
  26. ultralytics/cfg/datasets/dog-pose.yaml +28 -0
  27. ultralytics/cfg/datasets/dota8-multispectral.yaml +1 -1
  28. ultralytics/cfg/datasets/dota8.yaml +2 -2
  29. ultralytics/cfg/datasets/hand-keypoints.yaml +26 -2
  30. ultralytics/cfg/datasets/kitti.yaml +27 -0
  31. ultralytics/cfg/datasets/lvis.yaml +5 -5
  32. ultralytics/cfg/datasets/open-images-v7.yaml +1 -1
  33. ultralytics/cfg/datasets/tiger-pose.yaml +16 -0
  34. ultralytics/cfg/datasets/xView.yaml +16 -16
  35. ultralytics/cfg/default.yaml +4 -2
  36. ultralytics/cfg/models/11/yolo11-pose.yaml +1 -1
  37. ultralytics/cfg/models/11/yoloe-11-seg.yaml +2 -2
  38. ultralytics/cfg/models/11/yoloe-11.yaml +2 -2
  39. ultralytics/cfg/models/26/yolo26-cls.yaml +33 -0
  40. ultralytics/cfg/models/26/yolo26-obb.yaml +52 -0
  41. ultralytics/cfg/models/26/yolo26-p2.yaml +60 -0
  42. ultralytics/cfg/models/26/yolo26-p6.yaml +62 -0
  43. ultralytics/cfg/models/26/yolo26-pose.yaml +53 -0
  44. ultralytics/cfg/models/26/yolo26-seg.yaml +52 -0
  45. ultralytics/cfg/models/26/yolo26.yaml +52 -0
  46. ultralytics/cfg/models/26/yoloe-26-seg.yaml +53 -0
  47. ultralytics/cfg/models/26/yoloe-26.yaml +53 -0
  48. ultralytics/cfg/models/rt-detr/rtdetr-l.yaml +1 -1
  49. ultralytics/cfg/models/rt-detr/rtdetr-resnet101.yaml +1 -1
  50. ultralytics/cfg/models/rt-detr/rtdetr-resnet50.yaml +1 -1
  51. ultralytics/cfg/models/rt-detr/rtdetr-x.yaml +1 -1
  52. ultralytics/cfg/models/v10/yolov10b.yaml +2 -2
  53. ultralytics/cfg/models/v10/yolov10l.yaml +2 -2
  54. ultralytics/cfg/models/v10/yolov10m.yaml +2 -2
  55. ultralytics/cfg/models/v10/yolov10n.yaml +2 -2
  56. ultralytics/cfg/models/v10/yolov10s.yaml +2 -2
  57. ultralytics/cfg/models/v10/yolov10x.yaml +2 -2
  58. ultralytics/cfg/models/v3/yolov3-tiny.yaml +1 -1
  59. ultralytics/cfg/models/v6/yolov6.yaml +1 -1
  60. ultralytics/cfg/models/v8/yoloe-v8-seg.yaml +9 -6
  61. ultralytics/cfg/models/v8/yoloe-v8.yaml +9 -6
  62. ultralytics/cfg/models/v8/yolov8-cls-resnet101.yaml +1 -1
  63. ultralytics/cfg/models/v8/yolov8-cls-resnet50.yaml +1 -1
  64. ultralytics/cfg/models/v8/yolov8-ghost-p2.yaml +2 -2
  65. ultralytics/cfg/models/v8/yolov8-ghost-p6.yaml +2 -2
  66. ultralytics/cfg/models/v8/yolov8-ghost.yaml +2 -2
  67. ultralytics/cfg/models/v8/yolov8-obb.yaml +1 -1
  68. ultralytics/cfg/models/v8/yolov8-p2.yaml +1 -1
  69. ultralytics/cfg/models/v8/yolov8-pose-p6.yaml +1 -1
  70. ultralytics/cfg/models/v8/yolov8-rtdetr.yaml +1 -1
  71. ultralytics/cfg/models/v8/yolov8-seg-p6.yaml +1 -1
  72. ultralytics/cfg/models/v8/yolov8-world.yaml +1 -1
  73. ultralytics/cfg/models/v8/yolov8-worldv2.yaml +6 -6
  74. ultralytics/cfg/models/v9/yolov9s.yaml +1 -1
  75. ultralytics/data/__init__.py +4 -4
  76. ultralytics/data/annotator.py +5 -6
  77. ultralytics/data/augment.py +300 -475
  78. ultralytics/data/base.py +18 -26
  79. ultralytics/data/build.py +147 -25
  80. ultralytics/data/converter.py +108 -87
  81. ultralytics/data/dataset.py +47 -75
  82. ultralytics/data/loaders.py +42 -49
  83. ultralytics/data/split.py +5 -6
  84. ultralytics/data/split_dota.py +8 -15
  85. ultralytics/data/utils.py +36 -45
  86. ultralytics/engine/exporter.py +351 -263
  87. ultralytics/engine/model.py +186 -225
  88. ultralytics/engine/predictor.py +45 -54
  89. ultralytics/engine/results.py +198 -325
  90. ultralytics/engine/trainer.py +165 -106
  91. ultralytics/engine/tuner.py +41 -43
  92. ultralytics/engine/validator.py +55 -38
  93. ultralytics/hub/__init__.py +16 -19
  94. ultralytics/hub/auth.py +6 -12
  95. ultralytics/hub/google/__init__.py +7 -10
  96. ultralytics/hub/session.py +15 -25
  97. ultralytics/hub/utils.py +5 -8
  98. ultralytics/models/__init__.py +1 -1
  99. ultralytics/models/fastsam/__init__.py +1 -1
  100. ultralytics/models/fastsam/model.py +8 -10
  101. ultralytics/models/fastsam/predict.py +18 -30
  102. ultralytics/models/fastsam/utils.py +1 -2
  103. ultralytics/models/fastsam/val.py +5 -7
  104. ultralytics/models/nas/__init__.py +1 -1
  105. ultralytics/models/nas/model.py +5 -8
  106. ultralytics/models/nas/predict.py +7 -9
  107. ultralytics/models/nas/val.py +1 -2
  108. ultralytics/models/rtdetr/__init__.py +1 -1
  109. ultralytics/models/rtdetr/model.py +5 -8
  110. ultralytics/models/rtdetr/predict.py +15 -19
  111. ultralytics/models/rtdetr/train.py +10 -13
  112. ultralytics/models/rtdetr/val.py +21 -23
  113. ultralytics/models/sam/__init__.py +15 -2
  114. ultralytics/models/sam/amg.py +14 -20
  115. ultralytics/models/sam/build.py +26 -19
  116. ultralytics/models/sam/build_sam3.py +377 -0
  117. ultralytics/models/sam/model.py +29 -32
  118. ultralytics/models/sam/modules/blocks.py +83 -144
  119. ultralytics/models/sam/modules/decoders.py +19 -37
  120. ultralytics/models/sam/modules/encoders.py +44 -101
  121. ultralytics/models/sam/modules/memory_attention.py +16 -30
  122. ultralytics/models/sam/modules/sam.py +200 -73
  123. ultralytics/models/sam/modules/tiny_encoder.py +64 -83
  124. ultralytics/models/sam/modules/transformer.py +18 -28
  125. ultralytics/models/sam/modules/utils.py +174 -50
  126. ultralytics/models/sam/predict.py +2248 -350
  127. ultralytics/models/sam/sam3/__init__.py +3 -0
  128. ultralytics/models/sam/sam3/decoder.py +546 -0
  129. ultralytics/models/sam/sam3/encoder.py +529 -0
  130. ultralytics/models/sam/sam3/geometry_encoders.py +415 -0
  131. ultralytics/models/sam/sam3/maskformer_segmentation.py +286 -0
  132. ultralytics/models/sam/sam3/model_misc.py +199 -0
  133. ultralytics/models/sam/sam3/necks.py +129 -0
  134. ultralytics/models/sam/sam3/sam3_image.py +339 -0
  135. ultralytics/models/sam/sam3/text_encoder_ve.py +307 -0
  136. ultralytics/models/sam/sam3/vitdet.py +547 -0
  137. ultralytics/models/sam/sam3/vl_combiner.py +160 -0
  138. ultralytics/models/utils/loss.py +14 -26
  139. ultralytics/models/utils/ops.py +13 -17
  140. ultralytics/models/yolo/__init__.py +1 -1
  141. ultralytics/models/yolo/classify/predict.py +10 -13
  142. ultralytics/models/yolo/classify/train.py +12 -33
  143. ultralytics/models/yolo/classify/val.py +30 -29
  144. ultralytics/models/yolo/detect/predict.py +9 -12
  145. ultralytics/models/yolo/detect/train.py +17 -23
  146. ultralytics/models/yolo/detect/val.py +77 -59
  147. ultralytics/models/yolo/model.py +43 -60
  148. ultralytics/models/yolo/obb/predict.py +7 -16
  149. ultralytics/models/yolo/obb/train.py +14 -17
  150. ultralytics/models/yolo/obb/val.py +40 -37
  151. ultralytics/models/yolo/pose/__init__.py +1 -1
  152. ultralytics/models/yolo/pose/predict.py +7 -22
  153. ultralytics/models/yolo/pose/train.py +13 -16
  154. ultralytics/models/yolo/pose/val.py +39 -58
  155. ultralytics/models/yolo/segment/predict.py +17 -21
  156. ultralytics/models/yolo/segment/train.py +7 -10
  157. ultralytics/models/yolo/segment/val.py +95 -47
  158. ultralytics/models/yolo/world/train.py +8 -14
  159. ultralytics/models/yolo/world/train_world.py +11 -34
  160. ultralytics/models/yolo/yoloe/__init__.py +7 -7
  161. ultralytics/models/yolo/yoloe/predict.py +16 -23
  162. ultralytics/models/yolo/yoloe/train.py +36 -44
  163. ultralytics/models/yolo/yoloe/train_seg.py +11 -11
  164. ultralytics/models/yolo/yoloe/val.py +15 -20
  165. ultralytics/nn/__init__.py +7 -7
  166. ultralytics/nn/autobackend.py +159 -85
  167. ultralytics/nn/modules/__init__.py +68 -60
  168. ultralytics/nn/modules/activation.py +4 -6
  169. ultralytics/nn/modules/block.py +260 -224
  170. ultralytics/nn/modules/conv.py +52 -97
  171. ultralytics/nn/modules/head.py +831 -299
  172. ultralytics/nn/modules/transformer.py +76 -88
  173. ultralytics/nn/modules/utils.py +16 -21
  174. ultralytics/nn/tasks.py +180 -195
  175. ultralytics/nn/text_model.py +45 -69
  176. ultralytics/optim/__init__.py +5 -0
  177. ultralytics/optim/muon.py +338 -0
  178. ultralytics/solutions/__init__.py +12 -12
  179. ultralytics/solutions/ai_gym.py +13 -19
  180. ultralytics/solutions/analytics.py +15 -16
  181. ultralytics/solutions/config.py +6 -7
  182. ultralytics/solutions/distance_calculation.py +10 -13
  183. ultralytics/solutions/heatmap.py +8 -14
  184. ultralytics/solutions/instance_segmentation.py +6 -9
  185. ultralytics/solutions/object_blurrer.py +7 -10
  186. ultralytics/solutions/object_counter.py +12 -19
  187. ultralytics/solutions/object_cropper.py +8 -14
  188. ultralytics/solutions/parking_management.py +34 -32
  189. ultralytics/solutions/queue_management.py +10 -12
  190. ultralytics/solutions/region_counter.py +9 -12
  191. ultralytics/solutions/security_alarm.py +15 -20
  192. ultralytics/solutions/similarity_search.py +10 -15
  193. ultralytics/solutions/solutions.py +77 -76
  194. ultralytics/solutions/speed_estimation.py +7 -10
  195. ultralytics/solutions/streamlit_inference.py +2 -4
  196. ultralytics/solutions/templates/similarity-search.html +7 -18
  197. ultralytics/solutions/trackzone.py +7 -10
  198. ultralytics/solutions/vision_eye.py +5 -8
  199. ultralytics/trackers/__init__.py +1 -1
  200. ultralytics/trackers/basetrack.py +3 -5
  201. ultralytics/trackers/bot_sort.py +10 -27
  202. ultralytics/trackers/byte_tracker.py +21 -37
  203. ultralytics/trackers/track.py +4 -7
  204. ultralytics/trackers/utils/gmc.py +11 -22
  205. ultralytics/trackers/utils/kalman_filter.py +37 -48
  206. ultralytics/trackers/utils/matching.py +12 -15
  207. ultralytics/utils/__init__.py +124 -124
  208. ultralytics/utils/autobatch.py +2 -4
  209. ultralytics/utils/autodevice.py +17 -18
  210. ultralytics/utils/benchmarks.py +57 -71
  211. ultralytics/utils/callbacks/base.py +8 -10
  212. ultralytics/utils/callbacks/clearml.py +5 -13
  213. ultralytics/utils/callbacks/comet.py +32 -46
  214. ultralytics/utils/callbacks/dvc.py +13 -18
  215. ultralytics/utils/callbacks/mlflow.py +4 -5
  216. ultralytics/utils/callbacks/neptune.py +7 -15
  217. ultralytics/utils/callbacks/platform.py +423 -38
  218. ultralytics/utils/callbacks/raytune.py +3 -4
  219. ultralytics/utils/callbacks/tensorboard.py +25 -31
  220. ultralytics/utils/callbacks/wb.py +16 -14
  221. ultralytics/utils/checks.py +127 -85
  222. ultralytics/utils/cpu.py +3 -8
  223. ultralytics/utils/dist.py +9 -12
  224. ultralytics/utils/downloads.py +25 -33
  225. ultralytics/utils/errors.py +6 -14
  226. ultralytics/utils/events.py +2 -4
  227. ultralytics/utils/export/__init__.py +4 -236
  228. ultralytics/utils/export/engine.py +246 -0
  229. ultralytics/utils/export/imx.py +117 -63
  230. ultralytics/utils/export/tensorflow.py +231 -0
  231. ultralytics/utils/files.py +26 -30
  232. ultralytics/utils/git.py +9 -11
  233. ultralytics/utils/instance.py +30 -51
  234. ultralytics/utils/logger.py +212 -114
  235. ultralytics/utils/loss.py +601 -215
  236. ultralytics/utils/metrics.py +128 -156
  237. ultralytics/utils/nms.py +13 -16
  238. ultralytics/utils/ops.py +117 -166
  239. ultralytics/utils/patches.py +75 -21
  240. ultralytics/utils/plotting.py +75 -80
  241. ultralytics/utils/tal.py +125 -59
  242. ultralytics/utils/torch_utils.py +53 -79
  243. ultralytics/utils/tqdm.py +24 -21
  244. ultralytics/utils/triton.py +13 -19
  245. ultralytics/utils/tuner.py +19 -10
  246. dgenerate_ultralytics_headless-8.3.214.dist-info/RECORD +0 -283
  247. {dgenerate_ultralytics_headless-8.3.214.dist-info → dgenerate_ultralytics_headless-8.4.7.dist-info}/entry_points.txt +0 -0
  248. {dgenerate_ultralytics_headless-8.3.214.dist-info → dgenerate_ultralytics_headless-8.4.7.dist-info}/licenses/LICENSE +0 -0
  249. {dgenerate_ultralytics_headless-8.3.214.dist-info → dgenerate_ultralytics_headless-8.4.7.dist-info}/top_level.txt +0 -0
@@ -14,6 +14,7 @@ import socket
14
14
  import sys
15
15
  import threading
16
16
  import time
17
+ import warnings
17
18
  from functools import lru_cache
18
19
  from pathlib import Path
19
20
  from threading import Lock
@@ -64,6 +65,7 @@ RKNN_CHIPS = frozenset(
64
65
  "rv1103b",
65
66
  "rv1106b",
66
67
  "rk2118",
68
+ "rv1126b",
67
69
  }
68
70
  ) # Rockchip processors available for export
69
71
  HELP_MSG = """
@@ -78,8 +80,8 @@ HELP_MSG = """
78
80
  from ultralytics import YOLO
79
81
 
80
82
  # Load a model
81
- model = YOLO("yolo11n.yaml") # build a new model from scratch
82
- model = YOLO("yolo11n.pt") # load a pretrained model (recommended for training)
83
+ model = YOLO("yolo26n.yaml") # build a new model from scratch
84
+ model = YOLO("yolo26n.pt") # load a pretrained model (recommended for training)
83
85
 
84
86
  # Use the model
85
87
  results = model.train(data="coco8.yaml", epochs=3) # train the model
@@ -99,16 +101,16 @@ HELP_MSG = """
99
101
  See all ARGS at https://docs.ultralytics.com/usage/cfg or with "yolo cfg"
100
102
 
101
103
  - Train a detection model for 10 epochs with an initial learning_rate of 0.01
102
- yolo detect train data=coco8.yaml model=yolo11n.pt epochs=10 lr0=0.01
104
+ yolo detect train data=coco8.yaml model=yolo26n.pt epochs=10 lr0=0.01
103
105
 
104
106
  - Predict a YouTube video using a pretrained segmentation model at image size 320:
105
- yolo segment predict model=yolo11n-seg.pt source='https://youtu.be/LNwODJXcvt4' imgsz=320
107
+ yolo segment predict model=yolo26n-seg.pt source='https://youtu.be/LNwODJXcvt4' imgsz=320
106
108
 
107
109
  - Val a pretrained detection model at batch-size 1 and image size 640:
108
- yolo detect val model=yolo11n.pt data=coco8.yaml batch=1 imgsz=640
110
+ yolo detect val model=yolo26n.pt data=coco8.yaml batch=1 imgsz=640
109
111
 
110
- - Export a YOLO11n classification model to ONNX format at image size 224 by 128 (no TASK required)
111
- yolo export model=yolo11n-cls.pt format=onnx imgsz=224,128
112
+ - Export a YOLO26n classification model to ONNX format at image size 224 by 128 (no TASK required)
113
+ yolo export model=yolo26n-cls.pt format=onnx imgsz=224,128
112
114
 
113
115
  - Run special commands:
114
116
  yolo help
@@ -132,18 +134,25 @@ os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3" # suppress verbose TF compiler warning
132
134
  os.environ["TORCH_CPP_LOG_LEVEL"] = "ERROR" # suppress "NNPACK.cpp could not initialize NNPACK" warnings
133
135
  os.environ["KINETO_LOG_LEVEL"] = "5" # suppress verbose PyTorch profiler output when computing FLOPs
134
136
 
137
+ # Centralized warning suppression
138
+ warnings.filterwarnings("ignore", message="torch.distributed.reduce_op is deprecated") # PyTorch deprecation
139
+ warnings.filterwarnings("ignore", message="The figure layout has changed to tight") # matplotlib>=3.7.2
140
+ warnings.filterwarnings("ignore", category=FutureWarning, module="timm") # mobileclip timm.layers deprecation
141
+ warnings.filterwarnings("ignore", category=torch.jit.TracerWarning) # ONNX/TorchScript export tracer warnings
142
+ warnings.filterwarnings("ignore", category=UserWarning, message=".*prim::Constant.*") # ONNX shape warning
143
+ warnings.filterwarnings("ignore", category=DeprecationWarning, module="coremltools") # CoreML np.bool deprecation
144
+
135
145
  # Precompiled type tuples for faster isinstance() checks
136
146
  FLOAT_OR_INT = (float, int)
137
147
  STR_OR_PATH = (str, Path)
138
148
 
139
149
 
140
150
  class DataExportMixin:
141
- """
142
- Mixin class for exporting validation metrics or prediction results in various formats.
151
+ """Mixin class for exporting validation metrics or prediction results in various formats.
143
152
 
144
153
  This class provides utilities to export performance metrics (e.g., mAP, precision, recall) or prediction results
145
154
  from classification, object detection, segmentation, or pose estimation tasks into various formats: Polars
146
- DataFrame, CSV and JSON.
155
+ DataFrame, CSV, and JSON.
147
156
 
148
157
  Methods:
149
158
  to_df: Convert summary to a Polars DataFrame.
@@ -152,7 +161,7 @@ class DataExportMixin:
152
161
  tojson: Deprecated alias for `to_json()`.
153
162
 
154
163
  Examples:
155
- >>> model = YOLO("yolo11n.pt")
164
+ >>> model = YOLO("yolo26n.pt")
156
165
  >>> results = model("image.jpg")
157
166
  >>> df = results.to_df()
158
167
  >>> print(df)
@@ -160,30 +169,28 @@ class DataExportMixin:
160
169
  """
161
170
 
162
171
  def to_df(self, normalize=False, decimals=5):
163
- """
164
- Create a polars DataFrame from the prediction results summary or validation metrics.
172
+ """Create a Polars DataFrame from the prediction results summary or validation metrics.
165
173
 
166
174
  Args:
167
175
  normalize (bool, optional): Normalize numerical values for easier comparison.
168
176
  decimals (int, optional): Decimal places to round floats.
169
177
 
170
178
  Returns:
171
- (DataFrame): DataFrame containing the summary data.
179
+ (polars.DataFrame): Polars DataFrame containing the summary data.
172
180
  """
173
181
  import polars as pl # scope for faster 'import ultralytics'
174
182
 
175
183
  return pl.DataFrame(self.summary(normalize=normalize, decimals=decimals))
176
184
 
177
185
  def to_csv(self, normalize=False, decimals=5):
178
- """
179
- Export results or metrics to CSV string format.
186
+ """Export results or metrics to CSV string format.
180
187
 
181
188
  Args:
182
- normalize (bool, optional): Normalize numeric values.
183
- decimals (int, optional): Decimal precision.
189
+ normalize (bool, optional): Normalize numeric values.
190
+ decimals (int, optional): Decimal precision.
184
191
 
185
192
  Returns:
186
- (str): CSV content as string.
193
+ (str): CSV content as string.
187
194
  """
188
195
  import polars as pl
189
196
 
@@ -207,8 +214,7 @@ class DataExportMixin:
207
214
  return df_str.write_csv()
208
215
 
209
216
  def to_json(self, normalize=False, decimals=5):
210
- """
211
- Export results to JSON format.
217
+ """Export results to JSON format.
212
218
 
213
219
  Args:
214
220
  normalize (bool, optional): Normalize numeric values.
@@ -221,11 +227,10 @@ class DataExportMixin:
221
227
 
222
228
 
223
229
  class SimpleClass:
224
- """
225
- A simple base class for creating objects with string representations of their attributes.
230
+ """A simple base class for creating objects with string representations of their attributes.
226
231
 
227
- This class provides a foundation for creating objects that can be easily printed or represented as strings,
228
- showing all their non-callable attributes. It's useful for debugging and introspection of object states.
232
+ This class provides a foundation for creating objects that can be easily printed or represented as strings, showing
233
+ all their non-callable attributes. It's useful for debugging and introspection of object states.
229
234
 
230
235
  Methods:
231
236
  __str__: Return a human-readable string representation of the object.
@@ -260,7 +265,7 @@ class SimpleClass:
260
265
  # Display only the module and class name for subclasses
261
266
  s = f"{a}: {v.__module__}.{v.__class__.__name__} object"
262
267
  else:
263
- s = f"{a}: {repr(v)}"
268
+ s = f"{a}: {v!r}"
264
269
  attr.append(s)
265
270
  return f"{self.__module__}.{self.__class__.__name__} object with attributes:\n\n" + "\n".join(attr)
266
271
 
@@ -275,12 +280,11 @@ class SimpleClass:
275
280
 
276
281
 
277
282
  class IterableSimpleNamespace(SimpleNamespace):
278
- """
279
- An iterable SimpleNamespace class that provides enhanced functionality for attribute access and iteration.
283
+ """An iterable SimpleNamespace class that provides enhanced functionality for attribute access and iteration.
280
284
 
281
- This class extends the SimpleNamespace class with additional methods for iteration, string representation,
282
- and attribute access. It is designed to be used as a convenient container for storing and accessing
283
- configuration parameters.
285
+ This class extends the SimpleNamespace class with additional methods for iteration, string representation, and
286
+ attribute access. It is designed to be used as a convenient container for storing and accessing configuration
287
+ parameters.
284
288
 
285
289
  Methods:
286
290
  __iter__: Return an iterator of key-value pairs from the namespace's attributes.
@@ -335,8 +339,7 @@ class IterableSimpleNamespace(SimpleNamespace):
335
339
 
336
340
 
337
341
  def plt_settings(rcparams=None, backend="Agg"):
338
- """
339
- Decorator to temporarily set rc parameters and the backend for a plotting function.
342
+ """Decorator to temporarily set rc parameters and the backend for a plotting function.
340
343
 
341
344
  Args:
342
345
  rcparams (dict, optional): Dictionary of rc parameters to set.
@@ -389,12 +392,11 @@ def plt_settings(rcparams=None, backend="Agg"):
389
392
 
390
393
 
391
394
  def set_logging(name="LOGGING_NAME", verbose=True):
392
- """
393
- Set up logging with UTF-8 encoding and configurable verbosity.
395
+ """Set up logging with UTF-8 encoding and configurable verbosity.
394
396
 
395
- This function configures logging for the Ultralytics library, setting the appropriate logging level and
396
- formatter based on the verbosity flag and the current process rank. It handles special cases for Windows
397
- environments where UTF-8 encoding might not be the default.
397
+ This function configures logging for the Ultralytics library, setting the appropriate logging level and formatter
398
+ based on the verbosity flag and the current process rank. It handles special cases for Windows environments where
399
+ UTF-8 encoding might not be the default.
398
400
 
399
401
  Args:
400
402
  name (str): Name of the logger.
@@ -469,8 +471,7 @@ def emojis(string=""):
469
471
 
470
472
 
471
473
  class ThreadingLocked:
472
- """
473
- A decorator class for ensuring thread-safe execution of a function or method.
474
+ """A decorator class for ensuring thread-safe execution of a function or method.
474
475
 
475
476
  This class can be used as a decorator to make sure that if the decorated function is called from multiple threads,
476
477
  only one thread at a time will be able to execute the function.
@@ -503,8 +504,7 @@ class ThreadingLocked:
503
504
 
504
505
 
505
506
  class YAML:
506
- """
507
- YAML utility class for efficient file operations with automatic C-implementation detection.
507
+ """YAML utility class for efficient file operations with automatic C-implementation detection.
508
508
 
509
509
  This class provides optimized YAML loading and saving operations using PyYAML's fastest available implementation
510
510
  (C-based when possible). It implements a singleton pattern with lazy initialization, allowing direct class method
@@ -554,8 +554,7 @@ class YAML:
554
554
 
555
555
  @classmethod
556
556
  def save(cls, file="data.yaml", data=None, header=""):
557
- """
558
- Save Python object as YAML file.
557
+ """Save Python object as YAML file.
559
558
 
560
559
  Args:
561
560
  file (str | Path): Path to save YAML file.
@@ -584,8 +583,7 @@ class YAML:
584
583
 
585
584
  @classmethod
586
585
  def load(cls, file="data.yaml", append_filename=False):
587
- """
588
- Load YAML file to Python object with robust error handling.
586
+ """Load YAML file to Python object with robust error handling.
589
587
 
590
588
  Args:
591
589
  file (str | Path): Path to YAML file.
@@ -619,8 +617,7 @@ class YAML:
619
617
 
620
618
  @classmethod
621
619
  def print(cls, yaml_file):
622
- """
623
- Pretty print YAML file or object to console.
620
+ """Pretty print YAML file or object to console.
624
621
 
625
622
  Args:
626
623
  yaml_file (str | Path | dict): Path to YAML file or dict to print.
@@ -643,8 +640,7 @@ DEFAULT_CFG = IterableSimpleNamespace(**DEFAULT_CFG_DICT)
643
640
 
644
641
 
645
642
  def read_device_model() -> str:
646
- """
647
- Read the device model information from the system and cache it for quick access.
643
+ """Read the device model information from the system and cache it for quick access.
648
644
 
649
645
  Returns:
650
646
  (str): Kernel release information.
@@ -653,8 +649,7 @@ def read_device_model() -> str:
653
649
 
654
650
 
655
651
  def is_ubuntu() -> bool:
656
- """
657
- Check if the OS is Ubuntu.
652
+ """Check if the OS is Ubuntu.
658
653
 
659
654
  Returns:
660
655
  (bool): True if OS is Ubuntu, False otherwise.
@@ -666,9 +661,34 @@ def is_ubuntu() -> bool:
666
661
  return False
667
662
 
668
663
 
669
- def is_colab():
664
+ def is_debian(codenames: list[str] | None | str = None) -> list[bool] | bool:
665
+ """Check if the OS is Debian.
666
+
667
+ Args:
668
+ codenames (list[str] | None | str): Specific Debian codename to check for (e.g., 'buster', 'bullseye'). If None,
669
+ only checks for Debian.
670
+
671
+ Returns:
672
+ (list[bool] | bool): List of booleans indicating if OS matches each Debian codename, or a single boolean if no
673
+ codenames provided.
670
674
  """
671
- Check if the current script is running inside a Google Colab notebook.
675
+ try:
676
+ with open("/etc/os-release") as f:
677
+ content = f.read()
678
+ if codenames is None:
679
+ return "ID=debian" in content
680
+ if isinstance(codenames, str):
681
+ codenames = [codenames]
682
+ return [
683
+ f"VERSION_CODENAME={codename}" in content if codename else "ID=debian" in content
684
+ for codename in codenames
685
+ ]
686
+ except FileNotFoundError:
687
+ return [False] * len(codenames) if codenames else False
688
+
689
+
690
+ def is_colab():
691
+ """Check if the current script is running inside a Google Colab notebook.
672
692
 
673
693
  Returns:
674
694
  (bool): True if running inside a Colab notebook, False otherwise.
@@ -677,8 +697,7 @@ def is_colab():
677
697
 
678
698
 
679
699
  def is_kaggle():
680
- """
681
- Check if the current script is running inside a Kaggle kernel.
700
+ """Check if the current script is running inside a Kaggle kernel.
682
701
 
683
702
  Returns:
684
703
  (bool): True if running inside a Kaggle kernel, False otherwise.
@@ -687,8 +706,7 @@ def is_kaggle():
687
706
 
688
707
 
689
708
  def is_jupyter():
690
- """
691
- Check if the current script is running inside a Jupyter Notebook.
709
+ """Check if the current script is running inside a Jupyter Notebook.
692
710
 
693
711
  Returns:
694
712
  (bool): True if running inside a Jupyter Notebook, False otherwise.
@@ -701,8 +719,7 @@ def is_jupyter():
701
719
 
702
720
 
703
721
  def is_runpod():
704
- """
705
- Check if the current script is running inside a RunPod container.
722
+ """Check if the current script is running inside a RunPod container.
706
723
 
707
724
  Returns:
708
725
  (bool): True if running in RunPod, False otherwise.
@@ -711,8 +728,7 @@ def is_runpod():
711
728
 
712
729
 
713
730
  def is_docker() -> bool:
714
- """
715
- Determine if the script is running inside a Docker container.
731
+ """Determine if the script is running inside a Docker container.
716
732
 
717
733
  Returns:
718
734
  (bool): True if the script is running inside a Docker container, False otherwise.
@@ -724,8 +740,7 @@ def is_docker() -> bool:
724
740
 
725
741
 
726
742
  def is_raspberrypi() -> bool:
727
- """
728
- Determine if the Python environment is running on a Raspberry Pi.
743
+ """Determine if the Python environment is running on a Raspberry Pi.
729
744
 
730
745
  Returns:
731
746
  (bool): True if running on a Raspberry Pi, False otherwise.
@@ -735,8 +750,7 @@ def is_raspberrypi() -> bool:
735
750
 
736
751
  @lru_cache(maxsize=3)
737
752
  def is_jetson(jetpack=None) -> bool:
738
- """
739
- Determine if the Python environment is running on an NVIDIA Jetson device.
753
+ """Determine if the Python environment is running on an NVIDIA Jetson device.
740
754
 
741
755
  Args:
742
756
  jetpack (int | None): If specified, check for specific JetPack version (4, 5, 6).
@@ -744,20 +758,19 @@ def is_jetson(jetpack=None) -> bool:
744
758
  Returns:
745
759
  (bool): True if running on an NVIDIA Jetson device, False otherwise.
746
760
  """
747
- if jetson := ("tegra" in DEVICE_MODEL):
748
- if jetpack:
749
- try:
750
- content = open("/etc/nv_tegra_release").read()
751
- version_map = {4: "R32", 5: "R35", 6: "R36"} # JetPack to L4T major version mapping
752
- return jetpack in version_map and version_map[jetpack] in content
753
- except Exception:
754
- return False
761
+ jetson = "tegra" in DEVICE_MODEL
762
+ if jetson and jetpack:
763
+ try:
764
+ content = open("/etc/nv_tegra_release").read()
765
+ version_map = {4: "R32", 5: "R35", 6: "R36"} # JetPack to L4T major version mapping
766
+ return jetpack in version_map and version_map[jetpack] in content
767
+ except Exception:
768
+ return False
755
769
  return jetson
756
770
 
757
771
 
758
772
  def is_online() -> bool:
759
- """
760
- Fast online check using DNS (v4/v6) resolution (Cloudflare + Google).
773
+ """Fast online check using DNS (v4/v6) resolution (Cloudflare + Google).
761
774
 
762
775
  Returns:
763
776
  (bool): True if connection is successful, False otherwise.
@@ -775,8 +788,7 @@ def is_online() -> bool:
775
788
 
776
789
 
777
790
  def is_pip_package(filepath: str = __name__) -> bool:
778
- """
779
- Determine if the file at the given filepath is part of a pip package.
791
+ """Determine if the file at the given filepath is part of a pip package.
780
792
 
781
793
  Args:
782
794
  filepath (str): The filepath to check.
@@ -794,21 +806,19 @@ def is_pip_package(filepath: str = __name__) -> bool:
794
806
 
795
807
 
796
808
  def is_dir_writeable(dir_path: str | Path) -> bool:
797
- """
798
- Check if a directory is writeable.
809
+ """Check if a directory is writable.
799
810
 
800
811
  Args:
801
812
  dir_path (str | Path): The path to the directory.
802
813
 
803
814
  Returns:
804
- (bool): True if the directory is writeable, False otherwise.
815
+ (bool): True if the directory is writable, False otherwise.
805
816
  """
806
817
  return os.access(str(dir_path), os.W_OK)
807
818
 
808
819
 
809
820
  def is_pytest_running():
810
- """
811
- Determine whether pytest is currently running or not.
821
+ """Determine whether pytest is currently running or not.
812
822
 
813
823
  Returns:
814
824
  (bool): True if pytest is running, False otherwise.
@@ -817,8 +827,7 @@ def is_pytest_running():
817
827
 
818
828
 
819
829
  def is_github_action_running() -> bool:
820
- """
821
- Determine if the current environment is a GitHub Actions runner.
830
+ """Determine if the current environment is a GitHub Actions runner.
822
831
 
823
832
  Returns:
824
833
  (bool): True if the current environment is a GitHub Actions runner, False otherwise.
@@ -827,8 +836,7 @@ def is_github_action_running() -> bool:
827
836
 
828
837
 
829
838
  def get_default_args(func):
830
- """
831
- Return a dictionary of default arguments for a function.
839
+ """Return a dictionary of default arguments for a function.
832
840
 
833
841
  Args:
834
842
  func (callable): The function to inspect.
@@ -841,8 +849,7 @@ def get_default_args(func):
841
849
 
842
850
 
843
851
  def get_ubuntu_version():
844
- """
845
- Retrieve the Ubuntu version if the OS is Ubuntu.
852
+ """Retrieve the Ubuntu version if the OS is Ubuntu.
846
853
 
847
854
  Returns:
848
855
  (str): Ubuntu version or None if not an Ubuntu OS.
@@ -856,8 +863,7 @@ def get_ubuntu_version():
856
863
 
857
864
 
858
865
  def get_user_config_dir(sub_dir="Ultralytics"):
859
- """
860
- Return a writable config dir, preferring YOLO_CONFIG_DIR and being OS-aware.
866
+ """Return a writable config dir, preferring YOLO_CONFIG_DIR and being OS-aware.
861
867
 
862
868
  Args:
863
869
  sub_dir (str): The name of the subdirectory to create.
@@ -882,14 +888,14 @@ def get_user_config_dir(sub_dir="Ultralytics"):
882
888
  p.mkdir(parents=True, exist_ok=True)
883
889
  return p
884
890
 
885
- # Fallbacks for Docker, GCP/AWS functions where only /tmp is writeable
891
+ # Fallbacks for Docker, GCP/AWS functions where only /tmp is writable
886
892
  for alt in [Path("/tmp") / sub_dir, Path.cwd() / sub_dir]:
887
893
  if alt.exists():
888
894
  return alt
889
895
  if is_dir_writeable(alt.parent):
890
896
  alt.mkdir(parents=True, exist_ok=True)
891
897
  LOGGER.warning(
892
- f"user config directory '{p}' is not writeable, using '{alt}'. Set YOLO_CONFIG_DIR to override."
898
+ f"user config directory '{p}' is not writable, using '{alt}'. Set YOLO_CONFIG_DIR to override."
893
899
  )
894
900
  return alt
895
901
 
@@ -909,14 +915,15 @@ IS_JETSON = is_jetson()
909
915
  IS_JUPYTER = is_jupyter()
910
916
  IS_PIP_PACKAGE = is_pip_package()
911
917
  IS_RASPBERRYPI = is_raspberrypi()
918
+ IS_DEBIAN, IS_DEBIAN_BOOKWORM, IS_DEBIAN_TRIXIE = is_debian([None, "bookworm", "trixie"])
919
+ IS_UBUNTU = is_ubuntu()
912
920
  GIT = GitRepo()
913
921
  USER_CONFIG_DIR = get_user_config_dir() # Ultralytics settings dir
914
922
  SETTINGS_FILE = USER_CONFIG_DIR / "settings.json"
915
923
 
916
924
 
917
925
  def colorstr(*input):
918
- r"""
919
- Color a string based on the provided color and style arguments using ANSI escape codes.
926
+ r"""Color a string based on the provided color and style arguments using ANSI escape codes.
920
927
 
921
928
  This function can be called in two ways:
922
929
  - colorstr('color', 'style', 'your string')
@@ -925,12 +932,16 @@ def colorstr(*input):
925
932
  In the second form, 'blue' and 'bold' will be applied by default.
926
933
 
927
934
  Args:
928
- *input (str | Path): A sequence of strings where the first n-1 strings are color and style arguments,
929
- and the last string is the one to be colored.
935
+ *input (str | Path): A sequence of strings where the first n-1 strings are color and style arguments, and the
936
+ last string is the one to be colored.
930
937
 
931
938
  Returns:
932
939
  (str): The input string wrapped with ANSI escape codes for the specified color and style.
933
940
 
941
+ Examples:
942
+ >>> colorstr("blue", "bold", "hello world")
943
+ >>> "\033[34m\033[1mhello world\033[0m"
944
+
934
945
  Notes:
935
946
  Supported Colors and Styles:
936
947
  - Basic Colors: 'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'
@@ -938,10 +949,6 @@ def colorstr(*input):
938
949
  'bright_blue', 'bright_magenta', 'bright_cyan', 'bright_white'
939
950
  - Misc: 'end', 'bold', 'underline'
940
951
 
941
- Examples:
942
- >>> colorstr("blue", "bold", "hello world")
943
- >>> "\033[34m\033[1mhello world\033[0m"
944
-
945
952
  References:
946
953
  https://en.wikipedia.org/wiki/ANSI_escape_code
947
954
  """
@@ -971,8 +978,7 @@ def colorstr(*input):
971
978
 
972
979
 
973
980
  def remove_colorstr(input_string):
974
- """
975
- Remove ANSI escape codes from a string, effectively un-coloring it.
981
+ """Remove ANSI escape codes from a string, effectively un-coloring it.
976
982
 
977
983
  Args:
978
984
  input_string (str): The string to remove color and style from.
@@ -989,8 +995,7 @@ def remove_colorstr(input_string):
989
995
 
990
996
 
991
997
  class TryExcept(contextlib.ContextDecorator):
992
- """
993
- Ultralytics TryExcept class for handling exceptions gracefully.
998
+ """Ultralytics TryExcept class for handling exceptions gracefully.
994
999
 
995
1000
  This class can be used as a decorator or context manager to catch exceptions and optionally print warning messages.
996
1001
  It allows code to continue execution even when exceptions occur, which is useful for non-critical operations.
@@ -1029,12 +1034,11 @@ class TryExcept(contextlib.ContextDecorator):
1029
1034
 
1030
1035
 
1031
1036
  class Retry(contextlib.ContextDecorator):
1032
- """
1033
- Retry class for function execution with exponential backoff.
1037
+ """Retry class for function execution with exponential backoff.
1034
1038
 
1035
1039
  This decorator can be used to retry a function on exceptions, up to a specified number of times with an
1036
- exponentially increasing delay between retries. It's useful for handling transient failures in network
1037
- operations or other unreliable processes.
1040
+ exponentially increasing delay between retries. It's useful for handling transient failures in network operations or
1041
+ other unreliable processes.
1038
1042
 
1039
1043
  Attributes:
1040
1044
  times (int): Maximum number of retry attempts.
@@ -1074,12 +1078,11 @@ class Retry(contextlib.ContextDecorator):
1074
1078
 
1075
1079
 
1076
1080
  def threaded(func):
1077
- """
1078
- Multi-thread a target function by default and return the thread or function result.
1081
+ """Multi-thread a target function by default and return the thread or function result.
1079
1082
 
1080
- This decorator provides flexible execution of the target function, either in a separate thread or synchronously.
1081
- By default, the function runs in a thread, but this can be controlled via the 'threaded=False' keyword argument
1082
- which is removed from kwargs before calling the function.
1083
+ This decorator provides flexible execution of the target function, either in a separate thread or synchronously. By
1084
+ default, the function runs in a thread, but this can be controlled via the 'threaded=False' keyword argument which
1085
+ is removed from kwargs before calling the function.
1083
1086
 
1084
1087
  Args:
1085
1088
  func (callable): The function to be potentially executed in a separate thread.
@@ -1109,8 +1112,7 @@ def threaded(func):
1109
1112
 
1110
1113
 
1111
1114
  def set_sentry():
1112
- """
1113
- Initialize the Sentry SDK for error tracking and reporting.
1115
+ """Initialize the Sentry SDK for error tracking and reporting.
1114
1116
 
1115
1117
  Only used if sentry_sdk package is installed and sync=True in settings. Run 'yolo settings' to see and update
1116
1118
  settings.
@@ -1137,13 +1139,12 @@ def set_sentry():
1137
1139
  return
1138
1140
  # If sentry_sdk package is not installed then return and do not use Sentry
1139
1141
  try:
1140
- import sentry_sdk # noqa
1142
+ import sentry_sdk
1141
1143
  except ImportError:
1142
1144
  return
1143
1145
 
1144
1146
  def before_send(event, hint):
1145
- """
1146
- Modify the event before sending it to Sentry based on specific exception types and messages.
1147
+ """Modify the event before sending it to Sentry based on specific exception types and messages.
1147
1148
 
1148
1149
  Args:
1149
1150
  event (dict): The event dictionary containing information about the error.
@@ -1179,8 +1180,7 @@ def set_sentry():
1179
1180
 
1180
1181
 
1181
1182
  class JSONDict(dict):
1182
- """
1183
- A dictionary-like class that provides JSON persistence for its contents.
1183
+ """A dictionary-like class that provides JSON persistence for its contents.
1184
1184
 
1185
1185
  This class extends the built-in dictionary to automatically save its contents to a JSON file whenever they are
1186
1186
  modified. It ensures thread-safe operations using a lock and handles JSON serialization of Path objects.
@@ -1219,7 +1219,8 @@ class JSONDict(dict):
1219
1219
  try:
1220
1220
  if self.file_path.exists():
1221
1221
  with open(self.file_path) as f:
1222
- self.update(json.load(f))
1222
+ # Use the base dict update to avoid persisting during reads
1223
+ super().update(json.load(f))
1223
1224
  except json.JSONDecodeError:
1224
1225
  LOGGER.warning(f"Error decoding JSON from {self.file_path}. Starting with an empty dictionary.")
1225
1226
  except Exception as e:
@@ -1272,8 +1273,7 @@ class JSONDict(dict):
1272
1273
 
1273
1274
 
1274
1275
  class SettingsManager(JSONDict):
1275
- """
1276
- SettingsManager class for managing and persisting Ultralytics settings.
1276
+ """SettingsManager class for managing and persisting Ultralytics settings.
1277
1277
 
1278
1278
  This class extends JSONDict to provide JSON persistence for settings, ensuring thread-safe operations and default
1279
1279
  values. It validates settings on initialization and provides methods to update or reset settings. The settings
@@ -20,8 +20,7 @@ def check_train_batch_size(
20
20
  batch: int | float = -1,
21
21
  max_num_obj: int = 1,
22
22
  ) -> int:
23
- """
24
- Compute optimal YOLO training batch size using the autobatch() function.
23
+ """Compute optimal YOLO training batch size using the autobatch() function.
25
24
 
26
25
  Args:
27
26
  model (torch.nn.Module): YOLO model to check batch size for.
@@ -50,8 +49,7 @@ def autobatch(
50
49
  batch_size: int = DEFAULT_CFG.batch,
51
50
  max_num_obj: int = 1,
52
51
  ) -> int:
53
- """
54
- Automatically estimate the best YOLO batch size to use a fraction of the available CUDA memory.
52
+ """Automatically estimate the best YOLO batch size to use a fraction of the available CUDA memory.
55
53
 
56
54
  Args:
57
55
  model (torch.nn.Module): YOLO model to compute batch size for.