dgenerate-ultralytics-headless 8.3.253__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 (299) hide show
  1. dgenerate_ultralytics_headless-8.3.253.dist-info/METADATA +405 -0
  2. dgenerate_ultralytics_headless-8.3.253.dist-info/RECORD +299 -0
  3. dgenerate_ultralytics_headless-8.3.253.dist-info/WHEEL +5 -0
  4. dgenerate_ultralytics_headless-8.3.253.dist-info/entry_points.txt +3 -0
  5. dgenerate_ultralytics_headless-8.3.253.dist-info/licenses/LICENSE +661 -0
  6. dgenerate_ultralytics_headless-8.3.253.dist-info/top_level.txt +1 -0
  7. tests/__init__.py +23 -0
  8. tests/conftest.py +59 -0
  9. tests/test_cli.py +131 -0
  10. tests/test_cuda.py +216 -0
  11. tests/test_engine.py +157 -0
  12. tests/test_exports.py +309 -0
  13. tests/test_integrations.py +151 -0
  14. tests/test_python.py +777 -0
  15. tests/test_solutions.py +371 -0
  16. ultralytics/__init__.py +48 -0
  17. ultralytics/assets/bus.jpg +0 -0
  18. ultralytics/assets/zidane.jpg +0 -0
  19. ultralytics/cfg/__init__.py +1028 -0
  20. ultralytics/cfg/datasets/Argoverse.yaml +78 -0
  21. ultralytics/cfg/datasets/DOTAv1.5.yaml +37 -0
  22. ultralytics/cfg/datasets/DOTAv1.yaml +36 -0
  23. ultralytics/cfg/datasets/GlobalWheat2020.yaml +68 -0
  24. ultralytics/cfg/datasets/HomeObjects-3K.yaml +32 -0
  25. ultralytics/cfg/datasets/ImageNet.yaml +2025 -0
  26. ultralytics/cfg/datasets/Objects365.yaml +447 -0
  27. ultralytics/cfg/datasets/SKU-110K.yaml +58 -0
  28. ultralytics/cfg/datasets/TT100K.yaml +346 -0
  29. ultralytics/cfg/datasets/VOC.yaml +102 -0
  30. ultralytics/cfg/datasets/VisDrone.yaml +87 -0
  31. ultralytics/cfg/datasets/african-wildlife.yaml +25 -0
  32. ultralytics/cfg/datasets/brain-tumor.yaml +22 -0
  33. ultralytics/cfg/datasets/carparts-seg.yaml +44 -0
  34. ultralytics/cfg/datasets/coco-pose.yaml +64 -0
  35. ultralytics/cfg/datasets/coco.yaml +118 -0
  36. ultralytics/cfg/datasets/coco128-seg.yaml +101 -0
  37. ultralytics/cfg/datasets/coco128.yaml +101 -0
  38. ultralytics/cfg/datasets/coco8-grayscale.yaml +103 -0
  39. ultralytics/cfg/datasets/coco8-multispectral.yaml +104 -0
  40. ultralytics/cfg/datasets/coco8-pose.yaml +47 -0
  41. ultralytics/cfg/datasets/coco8-seg.yaml +101 -0
  42. ultralytics/cfg/datasets/coco8.yaml +101 -0
  43. ultralytics/cfg/datasets/construction-ppe.yaml +32 -0
  44. ultralytics/cfg/datasets/crack-seg.yaml +22 -0
  45. ultralytics/cfg/datasets/dog-pose.yaml +52 -0
  46. ultralytics/cfg/datasets/dota8-multispectral.yaml +38 -0
  47. ultralytics/cfg/datasets/dota8.yaml +35 -0
  48. ultralytics/cfg/datasets/hand-keypoints.yaml +50 -0
  49. ultralytics/cfg/datasets/kitti.yaml +27 -0
  50. ultralytics/cfg/datasets/lvis.yaml +1240 -0
  51. ultralytics/cfg/datasets/medical-pills.yaml +21 -0
  52. ultralytics/cfg/datasets/open-images-v7.yaml +663 -0
  53. ultralytics/cfg/datasets/package-seg.yaml +22 -0
  54. ultralytics/cfg/datasets/signature.yaml +21 -0
  55. ultralytics/cfg/datasets/tiger-pose.yaml +41 -0
  56. ultralytics/cfg/datasets/xView.yaml +155 -0
  57. ultralytics/cfg/default.yaml +130 -0
  58. ultralytics/cfg/models/11/yolo11-cls-resnet18.yaml +17 -0
  59. ultralytics/cfg/models/11/yolo11-cls.yaml +33 -0
  60. ultralytics/cfg/models/11/yolo11-obb.yaml +50 -0
  61. ultralytics/cfg/models/11/yolo11-pose.yaml +51 -0
  62. ultralytics/cfg/models/11/yolo11-seg.yaml +50 -0
  63. ultralytics/cfg/models/11/yolo11.yaml +50 -0
  64. ultralytics/cfg/models/11/yoloe-11-seg.yaml +48 -0
  65. ultralytics/cfg/models/11/yoloe-11.yaml +48 -0
  66. ultralytics/cfg/models/12/yolo12-cls.yaml +32 -0
  67. ultralytics/cfg/models/12/yolo12-obb.yaml +48 -0
  68. ultralytics/cfg/models/12/yolo12-pose.yaml +49 -0
  69. ultralytics/cfg/models/12/yolo12-seg.yaml +48 -0
  70. ultralytics/cfg/models/12/yolo12.yaml +48 -0
  71. ultralytics/cfg/models/rt-detr/rtdetr-l.yaml +53 -0
  72. ultralytics/cfg/models/rt-detr/rtdetr-resnet101.yaml +45 -0
  73. ultralytics/cfg/models/rt-detr/rtdetr-resnet50.yaml +45 -0
  74. ultralytics/cfg/models/rt-detr/rtdetr-x.yaml +57 -0
  75. ultralytics/cfg/models/v10/yolov10b.yaml +45 -0
  76. ultralytics/cfg/models/v10/yolov10l.yaml +45 -0
  77. ultralytics/cfg/models/v10/yolov10m.yaml +45 -0
  78. ultralytics/cfg/models/v10/yolov10n.yaml +45 -0
  79. ultralytics/cfg/models/v10/yolov10s.yaml +45 -0
  80. ultralytics/cfg/models/v10/yolov10x.yaml +45 -0
  81. ultralytics/cfg/models/v3/yolov3-spp.yaml +49 -0
  82. ultralytics/cfg/models/v3/yolov3-tiny.yaml +40 -0
  83. ultralytics/cfg/models/v3/yolov3.yaml +49 -0
  84. ultralytics/cfg/models/v5/yolov5-p6.yaml +62 -0
  85. ultralytics/cfg/models/v5/yolov5.yaml +51 -0
  86. ultralytics/cfg/models/v6/yolov6.yaml +56 -0
  87. ultralytics/cfg/models/v8/yoloe-v8-seg.yaml +48 -0
  88. ultralytics/cfg/models/v8/yoloe-v8.yaml +48 -0
  89. ultralytics/cfg/models/v8/yolov8-cls-resnet101.yaml +28 -0
  90. ultralytics/cfg/models/v8/yolov8-cls-resnet50.yaml +28 -0
  91. ultralytics/cfg/models/v8/yolov8-cls.yaml +32 -0
  92. ultralytics/cfg/models/v8/yolov8-ghost-p2.yaml +58 -0
  93. ultralytics/cfg/models/v8/yolov8-ghost-p6.yaml +60 -0
  94. ultralytics/cfg/models/v8/yolov8-ghost.yaml +50 -0
  95. ultralytics/cfg/models/v8/yolov8-obb.yaml +49 -0
  96. ultralytics/cfg/models/v8/yolov8-p2.yaml +57 -0
  97. ultralytics/cfg/models/v8/yolov8-p6.yaml +59 -0
  98. ultralytics/cfg/models/v8/yolov8-pose-p6.yaml +60 -0
  99. ultralytics/cfg/models/v8/yolov8-pose.yaml +50 -0
  100. ultralytics/cfg/models/v8/yolov8-rtdetr.yaml +49 -0
  101. ultralytics/cfg/models/v8/yolov8-seg-p6.yaml +59 -0
  102. ultralytics/cfg/models/v8/yolov8-seg.yaml +49 -0
  103. ultralytics/cfg/models/v8/yolov8-world.yaml +51 -0
  104. ultralytics/cfg/models/v8/yolov8-worldv2.yaml +49 -0
  105. ultralytics/cfg/models/v8/yolov8.yaml +49 -0
  106. ultralytics/cfg/models/v9/yolov9c-seg.yaml +41 -0
  107. ultralytics/cfg/models/v9/yolov9c.yaml +41 -0
  108. ultralytics/cfg/models/v9/yolov9e-seg.yaml +64 -0
  109. ultralytics/cfg/models/v9/yolov9e.yaml +64 -0
  110. ultralytics/cfg/models/v9/yolov9m.yaml +41 -0
  111. ultralytics/cfg/models/v9/yolov9s.yaml +41 -0
  112. ultralytics/cfg/models/v9/yolov9t.yaml +41 -0
  113. ultralytics/cfg/trackers/botsort.yaml +21 -0
  114. ultralytics/cfg/trackers/bytetrack.yaml +12 -0
  115. ultralytics/data/__init__.py +26 -0
  116. ultralytics/data/annotator.py +66 -0
  117. ultralytics/data/augment.py +2801 -0
  118. ultralytics/data/base.py +435 -0
  119. ultralytics/data/build.py +437 -0
  120. ultralytics/data/converter.py +855 -0
  121. ultralytics/data/dataset.py +834 -0
  122. ultralytics/data/loaders.py +704 -0
  123. ultralytics/data/scripts/download_weights.sh +18 -0
  124. ultralytics/data/scripts/get_coco.sh +61 -0
  125. ultralytics/data/scripts/get_coco128.sh +18 -0
  126. ultralytics/data/scripts/get_imagenet.sh +52 -0
  127. ultralytics/data/split.py +138 -0
  128. ultralytics/data/split_dota.py +344 -0
  129. ultralytics/data/utils.py +798 -0
  130. ultralytics/engine/__init__.py +1 -0
  131. ultralytics/engine/exporter.py +1580 -0
  132. ultralytics/engine/model.py +1125 -0
  133. ultralytics/engine/predictor.py +508 -0
  134. ultralytics/engine/results.py +1522 -0
  135. ultralytics/engine/trainer.py +977 -0
  136. ultralytics/engine/tuner.py +449 -0
  137. ultralytics/engine/validator.py +387 -0
  138. ultralytics/hub/__init__.py +166 -0
  139. ultralytics/hub/auth.py +151 -0
  140. ultralytics/hub/google/__init__.py +174 -0
  141. ultralytics/hub/session.py +422 -0
  142. ultralytics/hub/utils.py +162 -0
  143. ultralytics/models/__init__.py +9 -0
  144. ultralytics/models/fastsam/__init__.py +7 -0
  145. ultralytics/models/fastsam/model.py +79 -0
  146. ultralytics/models/fastsam/predict.py +169 -0
  147. ultralytics/models/fastsam/utils.py +23 -0
  148. ultralytics/models/fastsam/val.py +38 -0
  149. ultralytics/models/nas/__init__.py +7 -0
  150. ultralytics/models/nas/model.py +98 -0
  151. ultralytics/models/nas/predict.py +56 -0
  152. ultralytics/models/nas/val.py +38 -0
  153. ultralytics/models/rtdetr/__init__.py +7 -0
  154. ultralytics/models/rtdetr/model.py +63 -0
  155. ultralytics/models/rtdetr/predict.py +88 -0
  156. ultralytics/models/rtdetr/train.py +89 -0
  157. ultralytics/models/rtdetr/val.py +216 -0
  158. ultralytics/models/sam/__init__.py +25 -0
  159. ultralytics/models/sam/amg.py +275 -0
  160. ultralytics/models/sam/build.py +365 -0
  161. ultralytics/models/sam/build_sam3.py +377 -0
  162. ultralytics/models/sam/model.py +169 -0
  163. ultralytics/models/sam/modules/__init__.py +1 -0
  164. ultralytics/models/sam/modules/blocks.py +1067 -0
  165. ultralytics/models/sam/modules/decoders.py +495 -0
  166. ultralytics/models/sam/modules/encoders.py +794 -0
  167. ultralytics/models/sam/modules/memory_attention.py +298 -0
  168. ultralytics/models/sam/modules/sam.py +1160 -0
  169. ultralytics/models/sam/modules/tiny_encoder.py +979 -0
  170. ultralytics/models/sam/modules/transformer.py +344 -0
  171. ultralytics/models/sam/modules/utils.py +512 -0
  172. ultralytics/models/sam/predict.py +3940 -0
  173. ultralytics/models/sam/sam3/__init__.py +3 -0
  174. ultralytics/models/sam/sam3/decoder.py +546 -0
  175. ultralytics/models/sam/sam3/encoder.py +529 -0
  176. ultralytics/models/sam/sam3/geometry_encoders.py +415 -0
  177. ultralytics/models/sam/sam3/maskformer_segmentation.py +286 -0
  178. ultralytics/models/sam/sam3/model_misc.py +199 -0
  179. ultralytics/models/sam/sam3/necks.py +129 -0
  180. ultralytics/models/sam/sam3/sam3_image.py +339 -0
  181. ultralytics/models/sam/sam3/text_encoder_ve.py +307 -0
  182. ultralytics/models/sam/sam3/vitdet.py +547 -0
  183. ultralytics/models/sam/sam3/vl_combiner.py +160 -0
  184. ultralytics/models/utils/__init__.py +1 -0
  185. ultralytics/models/utils/loss.py +466 -0
  186. ultralytics/models/utils/ops.py +315 -0
  187. ultralytics/models/yolo/__init__.py +7 -0
  188. ultralytics/models/yolo/classify/__init__.py +7 -0
  189. ultralytics/models/yolo/classify/predict.py +90 -0
  190. ultralytics/models/yolo/classify/train.py +202 -0
  191. ultralytics/models/yolo/classify/val.py +216 -0
  192. ultralytics/models/yolo/detect/__init__.py +7 -0
  193. ultralytics/models/yolo/detect/predict.py +122 -0
  194. ultralytics/models/yolo/detect/train.py +227 -0
  195. ultralytics/models/yolo/detect/val.py +507 -0
  196. ultralytics/models/yolo/model.py +430 -0
  197. ultralytics/models/yolo/obb/__init__.py +7 -0
  198. ultralytics/models/yolo/obb/predict.py +56 -0
  199. ultralytics/models/yolo/obb/train.py +79 -0
  200. ultralytics/models/yolo/obb/val.py +302 -0
  201. ultralytics/models/yolo/pose/__init__.py +7 -0
  202. ultralytics/models/yolo/pose/predict.py +65 -0
  203. ultralytics/models/yolo/pose/train.py +110 -0
  204. ultralytics/models/yolo/pose/val.py +248 -0
  205. ultralytics/models/yolo/segment/__init__.py +7 -0
  206. ultralytics/models/yolo/segment/predict.py +109 -0
  207. ultralytics/models/yolo/segment/train.py +69 -0
  208. ultralytics/models/yolo/segment/val.py +307 -0
  209. ultralytics/models/yolo/world/__init__.py +5 -0
  210. ultralytics/models/yolo/world/train.py +173 -0
  211. ultralytics/models/yolo/world/train_world.py +178 -0
  212. ultralytics/models/yolo/yoloe/__init__.py +22 -0
  213. ultralytics/models/yolo/yoloe/predict.py +162 -0
  214. ultralytics/models/yolo/yoloe/train.py +287 -0
  215. ultralytics/models/yolo/yoloe/train_seg.py +122 -0
  216. ultralytics/models/yolo/yoloe/val.py +206 -0
  217. ultralytics/nn/__init__.py +27 -0
  218. ultralytics/nn/autobackend.py +964 -0
  219. ultralytics/nn/modules/__init__.py +182 -0
  220. ultralytics/nn/modules/activation.py +54 -0
  221. ultralytics/nn/modules/block.py +1947 -0
  222. ultralytics/nn/modules/conv.py +669 -0
  223. ultralytics/nn/modules/head.py +1183 -0
  224. ultralytics/nn/modules/transformer.py +793 -0
  225. ultralytics/nn/modules/utils.py +159 -0
  226. ultralytics/nn/tasks.py +1768 -0
  227. ultralytics/nn/text_model.py +356 -0
  228. ultralytics/py.typed +1 -0
  229. ultralytics/solutions/__init__.py +41 -0
  230. ultralytics/solutions/ai_gym.py +108 -0
  231. ultralytics/solutions/analytics.py +264 -0
  232. ultralytics/solutions/config.py +107 -0
  233. ultralytics/solutions/distance_calculation.py +123 -0
  234. ultralytics/solutions/heatmap.py +125 -0
  235. ultralytics/solutions/instance_segmentation.py +86 -0
  236. ultralytics/solutions/object_blurrer.py +89 -0
  237. ultralytics/solutions/object_counter.py +190 -0
  238. ultralytics/solutions/object_cropper.py +87 -0
  239. ultralytics/solutions/parking_management.py +280 -0
  240. ultralytics/solutions/queue_management.py +93 -0
  241. ultralytics/solutions/region_counter.py +133 -0
  242. ultralytics/solutions/security_alarm.py +151 -0
  243. ultralytics/solutions/similarity_search.py +219 -0
  244. ultralytics/solutions/solutions.py +828 -0
  245. ultralytics/solutions/speed_estimation.py +114 -0
  246. ultralytics/solutions/streamlit_inference.py +260 -0
  247. ultralytics/solutions/templates/similarity-search.html +156 -0
  248. ultralytics/solutions/trackzone.py +88 -0
  249. ultralytics/solutions/vision_eye.py +67 -0
  250. ultralytics/trackers/__init__.py +7 -0
  251. ultralytics/trackers/basetrack.py +115 -0
  252. ultralytics/trackers/bot_sort.py +257 -0
  253. ultralytics/trackers/byte_tracker.py +469 -0
  254. ultralytics/trackers/track.py +116 -0
  255. ultralytics/trackers/utils/__init__.py +1 -0
  256. ultralytics/trackers/utils/gmc.py +339 -0
  257. ultralytics/trackers/utils/kalman_filter.py +482 -0
  258. ultralytics/trackers/utils/matching.py +154 -0
  259. ultralytics/utils/__init__.py +1450 -0
  260. ultralytics/utils/autobatch.py +118 -0
  261. ultralytics/utils/autodevice.py +205 -0
  262. ultralytics/utils/benchmarks.py +728 -0
  263. ultralytics/utils/callbacks/__init__.py +5 -0
  264. ultralytics/utils/callbacks/base.py +233 -0
  265. ultralytics/utils/callbacks/clearml.py +146 -0
  266. ultralytics/utils/callbacks/comet.py +625 -0
  267. ultralytics/utils/callbacks/dvc.py +197 -0
  268. ultralytics/utils/callbacks/hub.py +110 -0
  269. ultralytics/utils/callbacks/mlflow.py +134 -0
  270. ultralytics/utils/callbacks/neptune.py +126 -0
  271. ultralytics/utils/callbacks/platform.py +453 -0
  272. ultralytics/utils/callbacks/raytune.py +42 -0
  273. ultralytics/utils/callbacks/tensorboard.py +123 -0
  274. ultralytics/utils/callbacks/wb.py +188 -0
  275. ultralytics/utils/checks.py +1020 -0
  276. ultralytics/utils/cpu.py +85 -0
  277. ultralytics/utils/dist.py +123 -0
  278. ultralytics/utils/downloads.py +529 -0
  279. ultralytics/utils/errors.py +35 -0
  280. ultralytics/utils/events.py +113 -0
  281. ultralytics/utils/export/__init__.py +7 -0
  282. ultralytics/utils/export/engine.py +237 -0
  283. ultralytics/utils/export/imx.py +325 -0
  284. ultralytics/utils/export/tensorflow.py +231 -0
  285. ultralytics/utils/files.py +219 -0
  286. ultralytics/utils/git.py +137 -0
  287. ultralytics/utils/instance.py +484 -0
  288. ultralytics/utils/logger.py +506 -0
  289. ultralytics/utils/loss.py +849 -0
  290. ultralytics/utils/metrics.py +1563 -0
  291. ultralytics/utils/nms.py +337 -0
  292. ultralytics/utils/ops.py +664 -0
  293. ultralytics/utils/patches.py +201 -0
  294. ultralytics/utils/plotting.py +1047 -0
  295. ultralytics/utils/tal.py +404 -0
  296. ultralytics/utils/torch_utils.py +984 -0
  297. ultralytics/utils/tqdm.py +443 -0
  298. ultralytics/utils/triton.py +112 -0
  299. ultralytics/utils/tuner.py +168 -0
tests/test_exports.py ADDED
@@ -0,0 +1,309 @@
1
+ # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2
+
3
+ import io
4
+ import shutil
5
+ import uuid
6
+ from contextlib import redirect_stderr, redirect_stdout
7
+ from itertools import product
8
+ from pathlib import Path
9
+
10
+ import pytest
11
+
12
+ from tests import MODEL, SOURCE
13
+ from ultralytics import YOLO
14
+ from ultralytics.cfg import TASK2DATA, TASK2MODEL, TASKS
15
+ from ultralytics.utils import ARM64, IS_RASPBERRYPI, LINUX, MACOS, WINDOWS, checks
16
+ from ultralytics.utils.torch_utils import TORCH_1_10, TORCH_1_11, TORCH_1_13, TORCH_2_1, TORCH_2_8, TORCH_2_9
17
+
18
+
19
+ def test_export_torchscript():
20
+ """Test YOLO model export to TorchScript format for compatibility and correctness."""
21
+ file = YOLO(MODEL).export(format="torchscript", optimize=False, imgsz=32)
22
+ YOLO(file)(SOURCE, imgsz=32) # exported model inference
23
+
24
+
25
+ def test_export_onnx():
26
+ """Test YOLO model export to ONNX format with dynamic axes."""
27
+ file = YOLO(MODEL).export(format="onnx", dynamic=True, imgsz=32)
28
+ YOLO(file)(SOURCE, imgsz=32) # exported model inference
29
+
30
+
31
+ @pytest.mark.skipif(not TORCH_2_1, reason="OpenVINO requires torch>=2.1")
32
+ def test_export_openvino():
33
+ """Test YOLO export to OpenVINO format for model inference compatibility."""
34
+ file = YOLO(MODEL).export(format="openvino", imgsz=32)
35
+ YOLO(file)(SOURCE, imgsz=32) # exported model inference
36
+
37
+
38
+ @pytest.mark.slow
39
+ @pytest.mark.skipif(not TORCH_2_1, reason="OpenVINO requires torch>=2.1")
40
+ @pytest.mark.parametrize(
41
+ "task, dynamic, int8, half, batch, nms",
42
+ [ # generate all combinations except for exclusion cases
43
+ (task, dynamic, int8, half, batch, nms)
44
+ for task, dynamic, int8, half, batch, nms in product(
45
+ TASKS, [True, False], [True, False], [True, False], [1, 2], [True, False]
46
+ )
47
+ if not ((int8 and half) or (task == "classify" and nms))
48
+ ],
49
+ )
50
+ def test_export_openvino_matrix(task, dynamic, int8, half, batch, nms):
51
+ """Test YOLO model export to OpenVINO under various configuration matrix conditions."""
52
+ file = YOLO(TASK2MODEL[task]).export(
53
+ format="openvino",
54
+ imgsz=32,
55
+ dynamic=dynamic,
56
+ int8=int8,
57
+ half=half,
58
+ batch=batch,
59
+ data=TASK2DATA[task],
60
+ nms=nms,
61
+ )
62
+ if WINDOWS:
63
+ # Use unique filenames due to Windows file permissions bug possibly due to latent threaded use
64
+ # See https://github.com/ultralytics/ultralytics/actions/runs/8957949304/job/24601616830?pr=10423
65
+ file = Path(file)
66
+ file = file.rename(file.with_stem(f"{file.stem}-{uuid.uuid4()}"))
67
+ YOLO(file)([SOURCE] * batch, imgsz=64 if dynamic else 32, batch=batch) # exported model inference
68
+ shutil.rmtree(file, ignore_errors=True) # retry in case of potential lingering multi-threaded file usage errors
69
+
70
+
71
+ @pytest.mark.slow
72
+ @pytest.mark.parametrize(
73
+ "task, dynamic, int8, half, batch, simplify, nms",
74
+ [ # generate all combinations except for exclusion cases
75
+ (task, dynamic, int8, half, batch, simplify, nms)
76
+ for task, dynamic, int8, half, batch, simplify, nms in product(
77
+ TASKS, [True, False], [False], [False], [1, 2], [True, False], [True, False]
78
+ )
79
+ if not ((int8 and half) or (task == "classify" and nms) or (nms and not TORCH_1_13))
80
+ ],
81
+ )
82
+ def test_export_onnx_matrix(task, dynamic, int8, half, batch, simplify, nms):
83
+ """Test YOLO export to ONNX format with various configurations and parameters."""
84
+ file = YOLO(TASK2MODEL[task]).export(
85
+ format="onnx", imgsz=32, dynamic=dynamic, int8=int8, half=half, batch=batch, simplify=simplify, nms=nms
86
+ )
87
+ YOLO(file)([SOURCE] * batch, imgsz=64 if dynamic else 32) # exported model inference
88
+ Path(file).unlink() # cleanup
89
+
90
+
91
+ @pytest.mark.slow
92
+ @pytest.mark.parametrize(
93
+ "task, dynamic, int8, half, batch, nms",
94
+ [ # generate all combinations except for exclusion cases
95
+ (task, dynamic, int8, half, batch, nms)
96
+ for task, dynamic, int8, half, batch, nms in product(
97
+ TASKS, [False, True], [False], [False, True], [1, 2], [True, False]
98
+ )
99
+ if not (task == "classify" and nms)
100
+ ],
101
+ )
102
+ def test_export_torchscript_matrix(task, dynamic, int8, half, batch, nms):
103
+ """Test YOLO model export to TorchScript format under varied configurations."""
104
+ file = YOLO(TASK2MODEL[task]).export(
105
+ format="torchscript", imgsz=32, dynamic=dynamic, int8=int8, half=half, batch=batch, nms=nms
106
+ )
107
+ YOLO(file)([SOURCE] * batch, imgsz=64 if dynamic else 32) # exported model inference
108
+ Path(file).unlink() # cleanup
109
+
110
+
111
+ @pytest.mark.slow
112
+ @pytest.mark.skipif(not MACOS, reason="CoreML inference only supported on macOS")
113
+ @pytest.mark.skipif(not TORCH_1_11, reason="CoreML export requires torch>=1.11")
114
+ @pytest.mark.skipif(checks.IS_PYTHON_3_13, reason="CoreML not supported in Python 3.13")
115
+ @pytest.mark.parametrize(
116
+ "task, dynamic, int8, half, nms, batch",
117
+ [ # generate all combinations except for exclusion cases
118
+ (task, dynamic, int8, half, nms, batch)
119
+ for task, dynamic, int8, half, nms, batch in product(
120
+ TASKS, [True, False], [True, False], [True, False], [True, False], [1]
121
+ )
122
+ if not (int8 and half)
123
+ and not (task != "detect" and nms)
124
+ and not (dynamic and nms)
125
+ and not (task == "classify" and dynamic)
126
+ ],
127
+ )
128
+ def test_export_coreml_matrix(task, dynamic, int8, half, nms, batch):
129
+ """Test YOLO export to CoreML format with various parameter configurations."""
130
+ file = YOLO(TASK2MODEL[task]).export(
131
+ format="coreml",
132
+ imgsz=32,
133
+ dynamic=dynamic,
134
+ int8=int8,
135
+ half=half,
136
+ batch=batch,
137
+ nms=nms,
138
+ )
139
+ YOLO(file)([SOURCE] * batch, imgsz=32) # exported model inference
140
+ shutil.rmtree(file) # cleanup
141
+
142
+
143
+ @pytest.mark.slow
144
+ @pytest.mark.skipif(not checks.IS_PYTHON_MINIMUM_3_10, reason="TFLite export requires Python>=3.10")
145
+ @pytest.mark.skipif(
146
+ not LINUX or IS_RASPBERRYPI,
147
+ reason="Test disabled as TF suffers from install conflicts on Windows, macOS and Raspberry Pi",
148
+ )
149
+ @pytest.mark.parametrize(
150
+ "task, dynamic, int8, half, batch, nms",
151
+ [ # generate all combinations except for exclusion cases
152
+ (task, dynamic, int8, half, batch, nms)
153
+ for task, dynamic, int8, half, batch, nms in product(
154
+ TASKS, [False], [True, False], [True, False], [1], [True, False]
155
+ )
156
+ if not ((int8 and half) or (task == "classify" and nms) or (ARM64 and nms) or (nms and not TORCH_1_13))
157
+ ],
158
+ )
159
+ def test_export_tflite_matrix(task, dynamic, int8, half, batch, nms):
160
+ """Test YOLO export to TFLite format considering various export configurations."""
161
+ file = YOLO(TASK2MODEL[task]).export(
162
+ format="tflite", imgsz=32, dynamic=dynamic, int8=int8, half=half, batch=batch, nms=nms
163
+ )
164
+ YOLO(file)([SOURCE] * batch, imgsz=32) # exported model inference
165
+ Path(file).unlink() # cleanup
166
+
167
+
168
+ @pytest.mark.skipif(not TORCH_1_11, reason="CoreML export requires torch>=1.11")
169
+ @pytest.mark.skipif(WINDOWS, reason="CoreML not supported on Windows") # RuntimeError: BlobWriter not loaded
170
+ @pytest.mark.skipif(LINUX and ARM64, reason="CoreML not supported on aarch64 Linux")
171
+ @pytest.mark.skipif(checks.IS_PYTHON_3_13, reason="CoreML not supported in Python 3.13")
172
+ def test_export_coreml():
173
+ """Test YOLO export to CoreML format and check for errors."""
174
+ # Capture stdout and stderr
175
+ stdout, stderr = io.StringIO(), io.StringIO()
176
+ with redirect_stdout(stdout), redirect_stderr(stderr):
177
+ YOLO(MODEL).export(format="coreml", nms=True, imgsz=32)
178
+ if MACOS:
179
+ file = YOLO(MODEL).export(format="coreml", imgsz=32)
180
+ YOLO(file)(SOURCE, imgsz=32) # model prediction only supported on macOS for nms=False models
181
+
182
+ # Check captured output for errors
183
+ output = stdout.getvalue() + stderr.getvalue()
184
+ assert "Error" not in output, f"CoreML export produced errors: {output}"
185
+ assert "You will not be able to run predict()" not in output, "CoreML export has predict() error"
186
+
187
+
188
+ @pytest.mark.skipif(not checks.IS_PYTHON_MINIMUM_3_10, reason="TFLite export requires Python>=3.10")
189
+ @pytest.mark.skipif(not LINUX, reason="Test disabled as TF suffers from install conflicts on Windows and macOS")
190
+ def test_export_tflite():
191
+ """Test YOLO export to TFLite format under specific OS and Python version conditions."""
192
+ model = YOLO(MODEL)
193
+ file = model.export(format="tflite", imgsz=32)
194
+ YOLO(file)(SOURCE, imgsz=32)
195
+
196
+
197
+ @pytest.mark.skipif(True, reason="Test disabled")
198
+ @pytest.mark.skipif(not LINUX, reason="TF suffers from install conflicts on Windows and macOS")
199
+ def test_export_pb():
200
+ """Test YOLO export to TensorFlow's Protobuf (*.pb) format."""
201
+ model = YOLO(MODEL)
202
+ file = model.export(format="pb", imgsz=32)
203
+ YOLO(file)(SOURCE, imgsz=32)
204
+
205
+
206
+ @pytest.mark.skipif(True, reason="Test disabled as Paddle protobuf and ONNX protobuf requirements conflict.")
207
+ def test_export_paddle():
208
+ """Test YOLO export to Paddle format, noting protobuf conflicts with ONNX."""
209
+ YOLO(MODEL).export(format="paddle", imgsz=32)
210
+
211
+
212
+ @pytest.mark.slow
213
+ @pytest.mark.skipif(not TORCH_1_10, reason="MNN export requires torch>=1.10")
214
+ def test_export_mnn():
215
+ """Test YOLO export to MNN format (WARNING: MNN test must precede NCNN test or CI error on Windows)."""
216
+ file = YOLO(MODEL).export(format="mnn", imgsz=32)
217
+ YOLO(file)(SOURCE, imgsz=32) # exported model inference
218
+
219
+
220
+ @pytest.mark.slow
221
+ @pytest.mark.skipif(not TORCH_1_10, reason="MNN export requires torch>=1.10")
222
+ @pytest.mark.parametrize(
223
+ "task, int8, half, batch",
224
+ [ # generate all combinations except for exclusion cases
225
+ (task, int8, half, batch)
226
+ for task, int8, half, batch in product(TASKS, [True, False], [True, False], [1, 2])
227
+ if not (int8 and half)
228
+ ],
229
+ )
230
+ def test_export_mnn_matrix(task, int8, half, batch):
231
+ """Test YOLO export to MNN format considering various export configurations."""
232
+ file = YOLO(TASK2MODEL[task]).export(format="mnn", imgsz=32, int8=int8, half=half, batch=batch)
233
+ YOLO(file)([SOURCE] * batch, imgsz=32) # exported model inference
234
+ Path(file).unlink() # cleanup
235
+
236
+
237
+ @pytest.mark.slow
238
+ def test_export_ncnn():
239
+ """Test YOLO export to NCNN format."""
240
+ file = YOLO(MODEL).export(format="ncnn", imgsz=32)
241
+ YOLO(file)(SOURCE, imgsz=32) # exported model inference
242
+
243
+
244
+ @pytest.mark.slow
245
+ @pytest.mark.parametrize("task, half, batch", list(product(TASKS, [True, False], [1])))
246
+ def test_export_ncnn_matrix(task, half, batch):
247
+ """Test YOLO export to NCNN format considering various export configurations."""
248
+ file = YOLO(TASK2MODEL[task]).export(format="ncnn", imgsz=32, half=half, batch=batch)
249
+ YOLO(file)([SOURCE] * batch, imgsz=32) # exported model inference
250
+ shutil.rmtree(file, ignore_errors=True) # retry in case of potential lingering multi-threaded file usage errors
251
+
252
+
253
+ @pytest.mark.skipif(not TORCH_2_9, reason="IMX export requires torch>=2.9.0")
254
+ @pytest.mark.skipif(not checks.IS_PYTHON_MINIMUM_3_9, reason="Requires Python>=3.9")
255
+ @pytest.mark.skipif(WINDOWS or MACOS, reason="Skipping test on Windows and Macos")
256
+ @pytest.mark.skipif(ARM64, reason="IMX export is not supported on ARM64 architectures.")
257
+ def test_export_imx():
258
+ """Test YOLO export to IMX format."""
259
+ model = YOLO(MODEL)
260
+ file = model.export(format="imx", imgsz=32)
261
+ YOLO(file)(SOURCE, imgsz=32)
262
+
263
+
264
+ @pytest.mark.slow
265
+ @pytest.mark.skipif(not TORCH_2_8, reason="Axelera export requires torch>=2.8.0")
266
+ @pytest.mark.skipif(not LINUX, reason="Axelera export only supported on Linux")
267
+ @pytest.mark.skipif(not checks.IS_PYTHON_3_10, reason="Axelera export requires Python 3.10")
268
+ def test_export_axelera():
269
+ """Test YOLO export to Axelera format."""
270
+ # For faster testing, use a smaller calibration dataset (32 image size crashes axelera export, so 64 is used)
271
+ file = YOLO(MODEL).export(format="axelera", imgsz=64, data="coco8.yaml")
272
+ assert Path(file).exists(), f"Axelera export failed, directory not found: {file}"
273
+ shutil.rmtree(file, ignore_errors=True) # cleanup
274
+
275
+
276
+ # @pytest.mark.skipif(True, reason="Disabled for debugging ruamel.yaml installation required by executorch")
277
+ @pytest.mark.skipif(not checks.IS_PYTHON_MINIMUM_3_10 or not TORCH_2_9, reason="Requires Python>=3.10 and Torch>=2.9.0")
278
+ @pytest.mark.skipif(WINDOWS, reason="Skipping test on Windows")
279
+ def test_export_executorch():
280
+ """Test YOLO model export to ExecuTorch format."""
281
+ file = YOLO(MODEL).export(format="executorch", imgsz=32)
282
+ assert Path(file).exists(), f"ExecuTorch export failed, directory not found: {file}"
283
+ # Check that .pte file exists in the exported directory
284
+ pte_file = Path(file) / Path(MODEL).with_suffix(".pte").name
285
+ assert pte_file.exists(), f"ExecuTorch .pte file not found: {pte_file}"
286
+ # Check that metadata.yaml exists
287
+ metadata_file = Path(file) / "metadata.yaml"
288
+ assert metadata_file.exists(), f"ExecuTorch metadata.yaml not found: {metadata_file}"
289
+ # Note: Inference testing skipped as ExecuTorch requires special runtime setup
290
+ shutil.rmtree(file, ignore_errors=True) # cleanup
291
+
292
+
293
+ @pytest.mark.slow
294
+ @pytest.mark.skipif(not checks.IS_PYTHON_MINIMUM_3_10 or not TORCH_2_9, reason="Requires Python>=3.10 and Torch>=2.9.0")
295
+ @pytest.mark.skipif(WINDOWS, reason="Skipping test on Windows")
296
+ @pytest.mark.parametrize("task", TASKS)
297
+ def test_export_executorch_matrix(task):
298
+ """Test YOLO export to ExecuTorch format for various task types."""
299
+ file = YOLO(TASK2MODEL[task]).export(format="executorch", imgsz=32)
300
+ assert Path(file).exists(), f"ExecuTorch export failed for task '{task}', directory not found: {file}"
301
+ # Check that .pte file exists in the exported directory
302
+ model_name = Path(TASK2MODEL[task]).with_suffix(".pte").name
303
+ pte_file = Path(file) / model_name
304
+ assert pte_file.exists(), f"ExecuTorch .pte file not found for task '{task}': {pte_file}"
305
+ # Check that metadata.yaml exists
306
+ metadata_file = Path(file) / "metadata.yaml"
307
+ assert metadata_file.exists(), f"ExecuTorch metadata.yaml not found for task '{task}': {metadata_file}"
308
+ # Note: Inference testing skipped as ExecuTorch requires special runtime setup
309
+ shutil.rmtree(file, ignore_errors=True) # cleanup
@@ -0,0 +1,151 @@
1
+ # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2
+
3
+ import contextlib
4
+ import os
5
+ import subprocess
6
+ import time
7
+ from pathlib import Path
8
+
9
+ import pytest
10
+
11
+ from tests import MODEL, SOURCE
12
+ from ultralytics import YOLO, download
13
+ from ultralytics.utils import ASSETS_URL, DATASETS_DIR, SETTINGS
14
+ from ultralytics.utils.checks import check_requirements
15
+
16
+
17
+ @pytest.mark.slow
18
+ def test_tensorboard():
19
+ """Test training with TensorBoard logging enabled."""
20
+ SETTINGS["tensorboard"] = True
21
+ YOLO("yolo11n-cls.yaml").train(data="imagenet10", imgsz=32, epochs=3, plots=False, device="cpu")
22
+ SETTINGS["tensorboard"] = False
23
+
24
+
25
+ @pytest.mark.skipif(not check_requirements("ray", install=False), reason="ray[tune] not installed")
26
+ def test_model_ray_tune():
27
+ """Tune YOLO model using Ray for hyperparameter optimization."""
28
+ YOLO("yolo11n-cls.yaml").tune(
29
+ use_ray=True, data="imagenet10", grace_period=1, iterations=1, imgsz=32, epochs=1, plots=False, device="cpu"
30
+ )
31
+
32
+
33
+ @pytest.mark.skipif(not check_requirements("mlflow", install=False), reason="mlflow not installed")
34
+ def test_mlflow():
35
+ """Test training with MLflow tracking enabled."""
36
+ SETTINGS["mlflow"] = True
37
+ YOLO("yolo11n-cls.yaml").train(data="imagenet10", imgsz=32, epochs=3, plots=False, device="cpu")
38
+ SETTINGS["mlflow"] = False
39
+
40
+
41
+ @pytest.mark.skipif(True, reason="Test failing in scheduled CI https://github.com/ultralytics/ultralytics/pull/8868")
42
+ @pytest.mark.skipif(not check_requirements("mlflow", install=False), reason="mlflow not installed")
43
+ def test_mlflow_keep_run_active():
44
+ """Ensure MLflow run status matches MLFLOW_KEEP_RUN_ACTIVE environment variable settings."""
45
+ import mlflow
46
+
47
+ SETTINGS["mlflow"] = True
48
+ run_name = "Test Run"
49
+ os.environ["MLFLOW_RUN"] = run_name
50
+
51
+ # Test with MLFLOW_KEEP_RUN_ACTIVE=True
52
+ os.environ["MLFLOW_KEEP_RUN_ACTIVE"] = "True"
53
+ YOLO("yolo11n-cls.yaml").train(data="imagenet10", imgsz=32, epochs=1, plots=False, device="cpu")
54
+ status = mlflow.active_run().info.status
55
+ assert status == "RUNNING", "MLflow run should be active when MLFLOW_KEEP_RUN_ACTIVE=True"
56
+
57
+ run_id = mlflow.active_run().info.run_id
58
+
59
+ # Test with MLFLOW_KEEP_RUN_ACTIVE=False
60
+ os.environ["MLFLOW_KEEP_RUN_ACTIVE"] = "False"
61
+ YOLO("yolo11n-cls.yaml").train(data="imagenet10", imgsz=32, epochs=1, plots=False, device="cpu")
62
+ status = mlflow.get_run(run_id=run_id).info.status
63
+ assert status == "FINISHED", "MLflow run should be ended when MLFLOW_KEEP_RUN_ACTIVE=False"
64
+
65
+ # Test with MLFLOW_KEEP_RUN_ACTIVE not set
66
+ os.environ.pop("MLFLOW_KEEP_RUN_ACTIVE", None)
67
+ YOLO("yolo11n-cls.yaml").train(data="imagenet10", imgsz=32, epochs=1, plots=False, device="cpu")
68
+ status = mlflow.get_run(run_id=run_id).info.status
69
+ assert status == "FINISHED", "MLflow run should be ended by default when MLFLOW_KEEP_RUN_ACTIVE is not set"
70
+ SETTINGS["mlflow"] = False
71
+
72
+
73
+ @pytest.mark.skipif(not check_requirements("tritonclient", install=False), reason="tritonclient[all] not installed")
74
+ def test_triton(tmp_path):
75
+ """Test NVIDIA Triton Server functionalities with YOLO model."""
76
+ check_requirements("tritonclient[all]")
77
+ from tritonclient.http import InferenceServerClient
78
+
79
+ # Create variables
80
+ model_name = "yolo"
81
+ triton_repo = tmp_path / "triton_repo" # Triton repo path
82
+ triton_model = triton_repo / model_name # Triton model path
83
+
84
+ # Export model to ONNX
85
+ f = YOLO(MODEL).export(format="onnx", dynamic=True)
86
+
87
+ # Prepare Triton repo
88
+ (triton_model / "1").mkdir(parents=True, exist_ok=True)
89
+ Path(f).rename(triton_model / "1" / "model.onnx")
90
+ (triton_model / "config.pbtxt").touch()
91
+
92
+ # Define image https://catalog.ngc.nvidia.com/orgs/nvidia/containers/tritonserver
93
+ tag = "nvcr.io/nvidia/tritonserver:23.09-py3" # 6.4 GB
94
+
95
+ # Pull the image
96
+ subprocess.call(f"docker pull {tag}", shell=True)
97
+
98
+ # Run the Triton server and capture the container ID
99
+ container_id = (
100
+ subprocess.check_output(
101
+ f"docker run -d --rm -v {triton_repo}:/models -p 8000:8000 {tag} tritonserver --model-repository=/models",
102
+ shell=True,
103
+ )
104
+ .decode("utf-8")
105
+ .strip()
106
+ )
107
+
108
+ # Wait for the Triton server to start
109
+ triton_client = InferenceServerClient(url="localhost:8000", verbose=False, ssl=False)
110
+
111
+ # Wait until model is ready
112
+ for _ in range(10):
113
+ with contextlib.suppress(Exception):
114
+ assert triton_client.is_model_ready(model_name)
115
+ break
116
+ time.sleep(1)
117
+
118
+ # Check Triton inference
119
+ YOLO(f"http://localhost:8000/{model_name}", "detect")(SOURCE) # exported model inference
120
+
121
+ # Kill and remove the container at the end of the test
122
+ subprocess.call(f"docker kill {container_id}", shell=True)
123
+
124
+
125
+ @pytest.mark.skipif(not check_requirements("faster-coco-eval", install=False), reason="faster-coco-eval not installed")
126
+ def test_faster_coco_eval():
127
+ """Validate YOLO model predictions on COCO dataset using faster-coco-eval."""
128
+ from ultralytics.models.yolo.detect import DetectionValidator
129
+ from ultralytics.models.yolo.pose import PoseValidator
130
+ from ultralytics.models.yolo.segment import SegmentationValidator
131
+
132
+ args = {"model": "yolo11n.pt", "data": "coco8.yaml", "save_json": True, "imgsz": 64}
133
+ validator = DetectionValidator(args=args)
134
+ validator()
135
+ validator.is_coco = True
136
+ download(f"{ASSETS_URL}/instances_val2017.json", dir=DATASETS_DIR / "coco8/annotations")
137
+ _ = validator.eval_json(validator.stats)
138
+
139
+ args = {"model": "yolo11n-seg.pt", "data": "coco8-seg.yaml", "save_json": True, "imgsz": 64}
140
+ validator = SegmentationValidator(args=args)
141
+ validator()
142
+ validator.is_coco = True
143
+ download(f"{ASSETS_URL}/instances_val2017.json", dir=DATASETS_DIR / "coco8-seg/annotations")
144
+ _ = validator.eval_json(validator.stats)
145
+
146
+ args = {"model": "yolo11n-pose.pt", "data": "coco8-pose.yaml", "save_json": True, "imgsz": 64}
147
+ validator = PoseValidator(args=args)
148
+ validator()
149
+ validator.is_coco = True
150
+ download(f"{ASSETS_URL}/person_keypoints_val2017.json", dir=DATASETS_DIR / "coco8-pose/annotations")
151
+ _ = validator.eval_json(validator.stats)