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
@@ -18,12 +18,14 @@ GITHUB_ASSETS_NAMES = frozenset(
18
18
  [f"yolov8{k}{suffix}.pt" for k in "nsmlx" for suffix in ("", "-cls", "-seg", "-pose", "-obb", "-oiv7")]
19
19
  + [f"yolo11{k}{suffix}.pt" for k in "nsmlx" for suffix in ("", "-cls", "-seg", "-pose", "-obb")]
20
20
  + [f"yolo12{k}{suffix}.pt" for k in "nsmlx" for suffix in ("",)] # detect models only currently
21
+ + [f"yolo26{k}{suffix}.pt" for k in "nsmlx" for suffix in ("", "-cls", "-seg", "-pose", "-obb")]
21
22
  + [f"yolov5{k}{resolution}u.pt" for k in "nsmlx" for resolution in ("", "6")]
22
23
  + [f"yolov3{k}u.pt" for k in ("", "-spp", "-tiny")]
23
24
  + [f"yolov8{k}-world.pt" for k in "smlx"]
24
25
  + [f"yolov8{k}-worldv2.pt" for k in "smlx"]
25
26
  + [f"yoloe-v8{k}{suffix}.pt" for k in "sml" for suffix in ("-seg", "-seg-pf")]
26
27
  + [f"yoloe-11{k}{suffix}.pt" for k in "sml" for suffix in ("-seg", "-seg-pf")]
28
+ + [f"yoloe-26{k}{suffix}.pt" for k in "nsmlx" for suffix in ("-seg", "-seg-pf")]
27
29
  + [f"yolov9{k}.pt" for k in "tsmce"]
28
30
  + [f"yolov10{k}.pt" for k in "nsmblx"]
29
31
  + [f"yolo_nas_{k}.pt" for k in "sml"]
@@ -43,8 +45,7 @@ GITHUB_ASSETS_STEMS = frozenset(k.rpartition(".")[0] for k in GITHUB_ASSETS_NAME
43
45
 
44
46
 
45
47
  def is_url(url: str | Path, check: bool = False) -> bool:
46
- """
47
- Validate if the given string is a URL and optionally check if the URL exists online.
48
+ """Validate if the given string is a URL and optionally check if the URL exists online.
48
49
 
49
50
  Args:
50
51
  url (str): The string to be validated as a URL.
@@ -71,8 +72,7 @@ def is_url(url: str | Path, check: bool = False) -> bool:
71
72
 
72
73
 
73
74
  def delete_dsstore(path: str | Path, files_to_delete: tuple[str, ...] = (".DS_Store", "__MACOSX")) -> None:
74
- """
75
- Delete all specified system files in a directory.
75
+ """Delete all specified system files in a directory.
76
76
 
77
77
  Args:
78
78
  path (str | Path): The directory path where the files should be deleted.
@@ -83,7 +83,7 @@ def delete_dsstore(path: str | Path, files_to_delete: tuple[str, ...] = (".DS_St
83
83
  >>> delete_dsstore("path/to/dir")
84
84
 
85
85
  Notes:
86
- ".DS_store" files are created by the Apple operating system and contain metadata about folders and files. They
86
+ ".DS_Store" files are created by the Apple operating system and contain metadata about folders and files. They
87
87
  are hidden system files and can cause issues when transferring files between different operating systems.
88
88
  """
89
89
  for file in files_to_delete:
@@ -99,8 +99,7 @@ def zip_directory(
99
99
  exclude: tuple[str, ...] = (".DS_Store", "__MACOSX"),
100
100
  progress: bool = True,
101
101
  ) -> Path:
102
- """
103
- Zip the contents of a directory, excluding specified files.
102
+ """Zip the contents of a directory, excluding specified files.
104
103
 
105
104
  The resulting zip file is named after the directory and placed alongside it.
106
105
 
@@ -142,12 +141,11 @@ def unzip_file(
142
141
  exist_ok: bool = False,
143
142
  progress: bool = True,
144
143
  ) -> Path:
145
- """
146
- Unzip a *.zip file to the specified path, excluding specified files.
144
+ """Unzip a *.zip file to the specified path, excluding specified files.
147
145
 
148
- If the zipfile does not contain a single top-level directory, the function will create a new
149
- directory with the same name as the zipfile (without the extension) to extract its contents.
150
- If a path is not provided, the function will use the parent directory of the zipfile as the default path.
146
+ If the zipfile does not contain a single top-level directory, the function will create a new directory with the same
147
+ name as the zipfile (without the extension) to extract its contents. If a path is not provided, the function will
148
+ use the parent directory of the zipfile as the default path.
151
149
 
152
150
  Args:
153
151
  file (str | Path): The path to the zipfile to be extracted.
@@ -183,7 +181,7 @@ def unzip_file(
183
181
  if unzip_as_dir:
184
182
  # Zip has 1 top-level directory
185
183
  extract_path = path # i.e. ../datasets
186
- path = Path(path) / list(top_level_dirs)[0] # i.e. extract coco8/ dir to ../datasets/
184
+ path = Path(path) / next(iter(top_level_dirs)) # i.e. extract coco8/ dir to ../datasets/
187
185
  else:
188
186
  # Zip has multiple files at top level
189
187
  path = extract_path = Path(path) / Path(file).stem # i.e. extract multiple files to ../datasets/coco8/
@@ -210,8 +208,7 @@ def check_disk_space(
210
208
  sf: float = 1.5,
211
209
  hard: bool = True,
212
210
  ) -> bool:
213
- """
214
- Check if there is sufficient disk space to download and store a file.
211
+ """Check if there is sufficient disk space to download and store a file.
215
212
 
216
213
  Args:
217
214
  file_bytes (int): The file size in bytes.
@@ -222,7 +219,7 @@ def check_disk_space(
222
219
  Returns:
223
220
  (bool): True if there is sufficient disk space, False otherwise.
224
221
  """
225
- total, used, free = shutil.disk_usage(path) # bytes
222
+ _total, _used, free = shutil.disk_usage(path) # bytes
226
223
  if file_bytes * sf < free:
227
224
  return True # sufficient space
228
225
 
@@ -238,8 +235,7 @@ def check_disk_space(
238
235
 
239
236
 
240
237
  def get_google_drive_file_info(link: str) -> tuple[str, str | None]:
241
- """
242
- Retrieve the direct download link and filename for a shareable Google Drive file link.
238
+ """Retrieve the direct download link and filename for a shareable Google Drive file link.
243
239
 
244
240
  Args:
245
241
  link (str): The shareable link of the Google Drive file.
@@ -289,16 +285,15 @@ def safe_download(
289
285
  exist_ok: bool = False,
290
286
  progress: bool = True,
291
287
  ) -> Path | str:
292
- """
293
- Download files from a URL with options for retrying, unzipping, and deleting the downloaded file. Enhanced with
288
+ """Download files from a URL with options for retrying, unzipping, and deleting the downloaded file. Enhanced with
294
289
  robust partial download detection using Content-Length validation.
295
290
 
296
291
  Args:
297
292
  url (str): The URL of the file to be downloaded.
298
- file (str, optional): The filename of the downloaded file.
299
- If not provided, the file will be saved with the same name as the URL.
300
- dir (str | Path, optional): The directory to save the downloaded file.
301
- If not provided, the file will be saved in the current working directory.
293
+ file (str, optional): The filename of the downloaded file. If not provided, the file will be saved with the same
294
+ name as the URL.
295
+ dir (str | Path, optional): The directory to save the downloaded file. If not provided, the file will be saved
296
+ in the current working directory.
302
297
  unzip (bool, optional): Whether to unzip the downloaded file.
303
298
  delete (bool, optional): Whether to delete the downloaded file after unzipping.
304
299
  curl (bool, optional): Whether to use curl command line tool for downloading.
@@ -397,8 +392,7 @@ def get_github_assets(
397
392
  version: str = "latest",
398
393
  retry: bool = False,
399
394
  ) -> tuple[str, list[str]]:
400
- """
401
- Retrieve the specified version's tag and assets from a GitHub repository.
395
+ """Retrieve the specified version's tag and assets from a GitHub repository.
402
396
 
403
397
  If the version is not specified, the function fetches the latest release assets.
404
398
 
@@ -426,17 +420,16 @@ def get_github_assets(
426
420
  LOGGER.warning(f"GitHub assets check failure for {url}: {r.status_code} {r.reason}")
427
421
  return "", []
428
422
  data = r.json()
429
- return data["tag_name"], [x["name"] for x in data["assets"]] # tag, assets i.e. ['yolo11n.pt', 'yolov8s.pt', ...]
423
+ return data["tag_name"], [x["name"] for x in data["assets"]] # tag, assets i.e. ['yolo26n.pt', 'yolo11s.pt', ...]
430
424
 
431
425
 
432
426
  def attempt_download_asset(
433
427
  file: str | Path,
434
428
  repo: str = "ultralytics/assets",
435
- release: str = "v8.3.0",
429
+ release: str = "v8.4.0",
436
430
  **kwargs,
437
431
  ) -> str:
438
- """
439
- Attempt to download a file from GitHub release assets if it is not found locally.
432
+ """Attempt to download a file from GitHub release assets if it is not found locally.
440
433
 
441
434
  Args:
442
435
  file (str | Path): The filename or file path to be downloaded.
@@ -448,7 +441,7 @@ def attempt_download_asset(
448
441
  (str): The path to the downloaded file.
449
442
 
450
443
  Examples:
451
- >>> file_path = attempt_download_asset("yolo11n.pt", repo="ultralytics/assets", release="latest")
444
+ >>> file_path = attempt_download_asset("yolo26n.pt", repo="ultralytics/assets", release="latest")
452
445
  """
453
446
  from ultralytics.utils import SETTINGS # scoped for circular import
454
447
 
@@ -495,8 +488,7 @@ def download(
495
488
  retry: int = 3,
496
489
  exist_ok: bool = False,
497
490
  ) -> None:
498
- """
499
- Download files from specified URLs to a given directory.
491
+ """Download files from specified URLs to a given directory.
500
492
 
501
493
  Supports concurrent downloads if multiple threads are specified.
502
494
 
@@ -4,11 +4,10 @@ from ultralytics.utils import emojis
4
4
 
5
5
 
6
6
  class HUBModelError(Exception):
7
- """
8
- Exception raised when a model cannot be found or retrieved from Ultralytics HUB.
7
+ """Exception raised when a model cannot be found or retrieved from Ultralytics HUB.
9
8
 
10
- This custom exception is used specifically for handling errors related to model fetching in Ultralytics YOLO.
11
- The error message is processed to include emojis for better user experience.
9
+ This custom exception is used specifically for handling errors related to model fetching in Ultralytics YOLO. The
10
+ error message is processed to include emojis for better user experience.
12
11
 
13
12
  Attributes:
14
13
  message (str): The error message displayed when the exception is raised.
@@ -25,19 +24,12 @@ class HUBModelError(Exception):
25
24
  """
26
25
 
27
26
  def __init__(self, message: str = "Model not found. Please check model URL and try again."):
28
- """
29
- Initialize a HUBModelError exception.
27
+ """Initialize a HUBModelError exception.
30
28
 
31
- This exception is raised when a requested model is not found or cannot be retrieved from Ultralytics HUB.
32
- The message is processed to include emojis for better user experience.
29
+ This exception is raised when a requested model is not found or cannot be retrieved from Ultralytics HUB. The
30
+ message is processed to include emojis for better user experience.
33
31
 
34
32
  Args:
35
33
  message (str, optional): The error message to display when the exception is raised.
36
-
37
- Examples:
38
- >>> try:
39
- ... raise HUBModelError("Custom model error message")
40
- ... except HUBModelError as e:
41
- ... print(e)
42
34
  """
43
35
  super().__init__(emojis(message))
@@ -24,8 +24,7 @@ def _post(url: str, data: dict, timeout: float = 5.0) -> None:
24
24
 
25
25
 
26
26
  class Events:
27
- """
28
- Collect and send anonymous usage analytics with rate-limiting.
27
+ """Collect and send anonymous usage analytics with rate-limiting.
29
28
 
30
29
  Event collection and transmission are enabled when sync is enabled in settings, the current process is rank -1 or 0,
31
30
  tests are not running, the environment is online, and the installation source is either pip or the official
@@ -71,8 +70,7 @@ class Events:
71
70
  )
72
71
 
73
72
  def __call__(self, cfg, device=None) -> None:
74
- """
75
- Queue an event and flush the queue asynchronously when the rate limit elapses.
73
+ """Queue an event and flush the queue asynchronously when the rate limit elapses.
76
74
 
77
75
  Args:
78
76
  cfg (IterableSimpleNamespace): The configuration object containing mode and task information.
@@ -1,239 +1,7 @@
1
1
  # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2
2
 
3
- from __future__ import annotations
3
+ from .engine import onnx2engine, torch2onnx
4
+ from .imx import torch2imx
5
+ from .tensorflow import keras2pb, onnx2saved_model, pb2tfjs, tflite2edgetpu
4
6
 
5
- import json
6
- from pathlib import Path
7
-
8
- import torch
9
-
10
- from ultralytics.utils import IS_JETSON, LOGGER
11
-
12
- from .imx import torch2imx # noqa
13
-
14
-
15
- def torch2onnx(
16
- torch_model: torch.nn.Module,
17
- im: torch.Tensor,
18
- onnx_file: str,
19
- opset: int = 14,
20
- input_names: list[str] = ["images"],
21
- output_names: list[str] = ["output0"],
22
- dynamic: bool | dict = False,
23
- ) -> None:
24
- """
25
- Export a PyTorch model to ONNX format.
26
-
27
- Args:
28
- torch_model (torch.nn.Module): The PyTorch model to export.
29
- im (torch.Tensor): Example input tensor for the model.
30
- onnx_file (str): Path to save the exported ONNX file.
31
- opset (int): ONNX opset version to use for export.
32
- input_names (list[str]): List of input tensor names.
33
- output_names (list[str]): List of output tensor names.
34
- dynamic (bool | dict, optional): Whether to enable dynamic axes.
35
-
36
- Notes:
37
- Setting `do_constant_folding=True` may cause issues with DNN inference for torch>=1.12.
38
- """
39
- torch.onnx.export(
40
- torch_model,
41
- im,
42
- onnx_file,
43
- verbose=False,
44
- opset_version=opset,
45
- do_constant_folding=True, # WARNING: DNN inference with torch>=1.12 may require do_constant_folding=False
46
- input_names=input_names,
47
- output_names=output_names,
48
- dynamic_axes=dynamic or None,
49
- )
50
-
51
-
52
- def onnx2engine(
53
- onnx_file: str,
54
- engine_file: str | None = None,
55
- workspace: int | None = None,
56
- half: bool = False,
57
- int8: bool = False,
58
- dynamic: bool = False,
59
- shape: tuple[int, int, int, int] = (1, 3, 640, 640),
60
- dla: int | None = None,
61
- dataset=None,
62
- metadata: dict | None = None,
63
- verbose: bool = False,
64
- prefix: str = "",
65
- ) -> None:
66
- """
67
- Export a YOLO model to TensorRT engine format.
68
-
69
- Args:
70
- onnx_file (str): Path to the ONNX file to be converted.
71
- engine_file (str, optional): Path to save the generated TensorRT engine file.
72
- workspace (int, optional): Workspace size in GB for TensorRT.
73
- half (bool, optional): Enable FP16 precision.
74
- int8 (bool, optional): Enable INT8 precision.
75
- dynamic (bool, optional): Enable dynamic input shapes.
76
- shape (tuple[int, int, int, int], optional): Input shape (batch, channels, height, width).
77
- dla (int, optional): DLA core to use (Jetson devices only).
78
- dataset (ultralytics.data.build.InfiniteDataLoader, optional): Dataset for INT8 calibration.
79
- metadata (dict, optional): Metadata to include in the engine file.
80
- verbose (bool, optional): Enable verbose logging.
81
- prefix (str, optional): Prefix for log messages.
82
-
83
- Raises:
84
- ValueError: If DLA is enabled on non-Jetson devices or required precision is not set.
85
- RuntimeError: If the ONNX file cannot be parsed.
86
-
87
- Notes:
88
- TensorRT version compatibility is handled for workspace size and engine building.
89
- INT8 calibration requires a dataset and generates a calibration cache.
90
- Metadata is serialized and written to the engine file if provided.
91
- """
92
- import tensorrt as trt # noqa
93
-
94
- engine_file = engine_file or Path(onnx_file).with_suffix(".engine")
95
-
96
- logger = trt.Logger(trt.Logger.INFO)
97
- if verbose:
98
- logger.min_severity = trt.Logger.Severity.VERBOSE
99
-
100
- # Engine builder
101
- builder = trt.Builder(logger)
102
- config = builder.create_builder_config()
103
- workspace_bytes = int((workspace or 0) * (1 << 30))
104
- is_trt10 = int(trt.__version__.split(".", 1)[0]) >= 10 # is TensorRT >= 10
105
- if is_trt10 and workspace_bytes > 0:
106
- config.set_memory_pool_limit(trt.MemoryPoolType.WORKSPACE, workspace_bytes)
107
- elif workspace_bytes > 0: # TensorRT versions 7, 8
108
- config.max_workspace_size = workspace_bytes
109
- flag = 1 << int(trt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH)
110
- network = builder.create_network(flag)
111
- half = builder.platform_has_fast_fp16 and half
112
- int8 = builder.platform_has_fast_int8 and int8
113
-
114
- # Optionally switch to DLA if enabled
115
- if dla is not None:
116
- if not IS_JETSON:
117
- raise ValueError("DLA is only available on NVIDIA Jetson devices")
118
- LOGGER.info(f"{prefix} enabling DLA on core {dla}...")
119
- if not half and not int8:
120
- raise ValueError(
121
- "DLA requires either 'half=True' (FP16) or 'int8=True' (INT8) to be enabled. Please enable one of them and try again."
122
- )
123
- config.default_device_type = trt.DeviceType.DLA
124
- config.DLA_core = int(dla)
125
- config.set_flag(trt.BuilderFlag.GPU_FALLBACK)
126
-
127
- # Read ONNX file
128
- parser = trt.OnnxParser(network, logger)
129
- if not parser.parse_from_file(onnx_file):
130
- raise RuntimeError(f"failed to load ONNX file: {onnx_file}")
131
-
132
- # Network inputs
133
- inputs = [network.get_input(i) for i in range(network.num_inputs)]
134
- outputs = [network.get_output(i) for i in range(network.num_outputs)]
135
- for inp in inputs:
136
- LOGGER.info(f'{prefix} input "{inp.name}" with shape{inp.shape} {inp.dtype}')
137
- for out in outputs:
138
- LOGGER.info(f'{prefix} output "{out.name}" with shape{out.shape} {out.dtype}')
139
-
140
- if dynamic:
141
- profile = builder.create_optimization_profile()
142
- min_shape = (1, shape[1], 32, 32) # minimum input shape
143
- max_shape = (*shape[:2], *(int(max(2, workspace or 2) * d) for d in shape[2:])) # max input shape
144
- for inp in inputs:
145
- profile.set_shape(inp.name, min=min_shape, opt=shape, max=max_shape)
146
- config.add_optimization_profile(profile)
147
- if int8:
148
- config.set_calibration_profile(profile)
149
-
150
- LOGGER.info(f"{prefix} building {'INT8' if int8 else 'FP' + ('16' if half else '32')} engine as {engine_file}")
151
- if int8:
152
- config.set_flag(trt.BuilderFlag.INT8)
153
- config.profiling_verbosity = trt.ProfilingVerbosity.DETAILED
154
-
155
- class EngineCalibrator(trt.IInt8Calibrator):
156
- """
157
- Custom INT8 calibrator for TensorRT engine optimization.
158
-
159
- This calibrator provides the necessary interface for TensorRT to perform INT8 quantization calibration
160
- using a dataset. It handles batch generation, caching, and calibration algorithm selection.
161
-
162
- Attributes:
163
- dataset: Dataset for calibration.
164
- data_iter: Iterator over the calibration dataset.
165
- algo (trt.CalibrationAlgoType): Calibration algorithm type.
166
- batch (int): Batch size for calibration.
167
- cache (Path): Path to save the calibration cache.
168
-
169
- Methods:
170
- get_algorithm: Get the calibration algorithm to use.
171
- get_batch_size: Get the batch size to use for calibration.
172
- get_batch: Get the next batch to use for calibration.
173
- read_calibration_cache: Use existing cache instead of calibrating again.
174
- write_calibration_cache: Write calibration cache to disk.
175
- """
176
-
177
- def __init__(
178
- self,
179
- dataset, # ultralytics.data.build.InfiniteDataLoader
180
- cache: str = "",
181
- ) -> None:
182
- """Initialize the INT8 calibrator with dataset and cache path."""
183
- trt.IInt8Calibrator.__init__(self)
184
- self.dataset = dataset
185
- self.data_iter = iter(dataset)
186
- self.algo = (
187
- trt.CalibrationAlgoType.ENTROPY_CALIBRATION_2 # DLA quantization needs ENTROPY_CALIBRATION_2
188
- if dla is not None
189
- else trt.CalibrationAlgoType.MINMAX_CALIBRATION
190
- )
191
- self.batch = dataset.batch_size
192
- self.cache = Path(cache)
193
-
194
- def get_algorithm(self) -> trt.CalibrationAlgoType:
195
- """Get the calibration algorithm to use."""
196
- return self.algo
197
-
198
- def get_batch_size(self) -> int:
199
- """Get the batch size to use for calibration."""
200
- return self.batch or 1
201
-
202
- def get_batch(self, names) -> list[int] | None:
203
- """Get the next batch to use for calibration, as a list of device memory pointers."""
204
- try:
205
- im0s = next(self.data_iter)["img"] / 255.0
206
- im0s = im0s.to("cuda") if im0s.device.type == "cpu" else im0s
207
- return [int(im0s.data_ptr())]
208
- except StopIteration:
209
- # Return None to signal to TensorRT there is no calibration data remaining
210
- return None
211
-
212
- def read_calibration_cache(self) -> bytes | None:
213
- """Use existing cache instead of calibrating again, otherwise, implicitly return None."""
214
- if self.cache.exists() and self.cache.suffix == ".cache":
215
- return self.cache.read_bytes()
216
-
217
- def write_calibration_cache(self, cache: bytes) -> None:
218
- """Write calibration cache to disk."""
219
- _ = self.cache.write_bytes(cache)
220
-
221
- # Load dataset w/ builder (for batching) and calibrate
222
- config.int8_calibrator = EngineCalibrator(
223
- dataset=dataset,
224
- cache=str(Path(onnx_file).with_suffix(".cache")),
225
- )
226
-
227
- elif half:
228
- config.set_flag(trt.BuilderFlag.FP16)
229
-
230
- # Write file
231
- build = builder.build_serialized_network if is_trt10 else builder.build_engine
232
- with build(network, config) as engine, open(engine_file, "wb") as t:
233
- # Metadata
234
- if metadata is not None:
235
- meta = json.dumps(metadata)
236
- t.write(len(meta).to_bytes(4, byteorder="little", signed=True))
237
- t.write(meta.encode())
238
- # Model
239
- t.write(engine if is_trt10 else engine.serialize())
7
+ __all__ = ["keras2pb", "onnx2engine", "onnx2saved_model", "pb2tfjs", "tflite2edgetpu", "torch2imx", "torch2onnx"]