ultralytics 8.1.28__py3-none-any.whl → 8.3.62__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 (247) hide show
  1. tests/__init__.py +22 -0
  2. tests/conftest.py +83 -0
  3. tests/test_cli.py +122 -0
  4. tests/test_cuda.py +155 -0
  5. tests/test_engine.py +131 -0
  6. tests/test_exports.py +216 -0
  7. tests/test_integrations.py +150 -0
  8. tests/test_python.py +615 -0
  9. tests/test_solutions.py +94 -0
  10. ultralytics/__init__.py +11 -8
  11. ultralytics/cfg/__init__.py +569 -131
  12. ultralytics/cfg/datasets/Argoverse.yaml +2 -1
  13. ultralytics/cfg/datasets/DOTAv1.5.yaml +3 -2
  14. ultralytics/cfg/datasets/DOTAv1.yaml +3 -2
  15. ultralytics/cfg/datasets/GlobalWheat2020.yaml +3 -2
  16. ultralytics/cfg/datasets/ImageNet.yaml +2 -1
  17. ultralytics/cfg/datasets/Objects365.yaml +5 -4
  18. ultralytics/cfg/datasets/SKU-110K.yaml +2 -1
  19. ultralytics/cfg/datasets/VOC.yaml +3 -2
  20. ultralytics/cfg/datasets/VisDrone.yaml +6 -5
  21. ultralytics/cfg/datasets/african-wildlife.yaml +25 -0
  22. ultralytics/cfg/datasets/brain-tumor.yaml +23 -0
  23. ultralytics/cfg/datasets/carparts-seg.yaml +3 -2
  24. ultralytics/cfg/datasets/coco-pose.yaml +7 -6
  25. ultralytics/cfg/datasets/coco.yaml +3 -2
  26. ultralytics/cfg/datasets/coco128-seg.yaml +4 -3
  27. ultralytics/cfg/datasets/coco128.yaml +4 -3
  28. ultralytics/cfg/datasets/coco8-pose.yaml +3 -2
  29. ultralytics/cfg/datasets/coco8-seg.yaml +3 -2
  30. ultralytics/cfg/datasets/coco8.yaml +3 -2
  31. ultralytics/cfg/datasets/crack-seg.yaml +3 -2
  32. ultralytics/cfg/datasets/dog-pose.yaml +24 -0
  33. ultralytics/cfg/datasets/dota8.yaml +3 -2
  34. ultralytics/cfg/datasets/hand-keypoints.yaml +26 -0
  35. ultralytics/cfg/datasets/lvis.yaml +1236 -0
  36. ultralytics/cfg/datasets/medical-pills.yaml +22 -0
  37. ultralytics/cfg/datasets/open-images-v7.yaml +2 -1
  38. ultralytics/cfg/datasets/package-seg.yaml +5 -4
  39. ultralytics/cfg/datasets/signature.yaml +21 -0
  40. ultralytics/cfg/datasets/tiger-pose.yaml +3 -2
  41. ultralytics/cfg/datasets/xView.yaml +2 -1
  42. ultralytics/cfg/default.yaml +14 -11
  43. ultralytics/cfg/models/11/yolo11-cls-resnet18.yaml +24 -0
  44. ultralytics/cfg/models/11/yolo11-cls.yaml +33 -0
  45. ultralytics/cfg/models/11/yolo11-obb.yaml +50 -0
  46. ultralytics/cfg/models/11/yolo11-pose.yaml +51 -0
  47. ultralytics/cfg/models/11/yolo11-seg.yaml +50 -0
  48. ultralytics/cfg/models/11/yolo11.yaml +50 -0
  49. ultralytics/cfg/models/rt-detr/rtdetr-l.yaml +5 -2
  50. ultralytics/cfg/models/rt-detr/rtdetr-resnet101.yaml +5 -2
  51. ultralytics/cfg/models/rt-detr/rtdetr-resnet50.yaml +5 -2
  52. ultralytics/cfg/models/rt-detr/rtdetr-x.yaml +5 -2
  53. ultralytics/cfg/models/v10/yolov10b.yaml +45 -0
  54. ultralytics/cfg/models/v10/yolov10l.yaml +45 -0
  55. ultralytics/cfg/models/v10/yolov10m.yaml +45 -0
  56. ultralytics/cfg/models/v10/yolov10n.yaml +45 -0
  57. ultralytics/cfg/models/v10/yolov10s.yaml +45 -0
  58. ultralytics/cfg/models/v10/yolov10x.yaml +45 -0
  59. ultralytics/cfg/models/v3/yolov3-spp.yaml +5 -2
  60. ultralytics/cfg/models/v3/yolov3-tiny.yaml +5 -2
  61. ultralytics/cfg/models/v3/yolov3.yaml +5 -2
  62. ultralytics/cfg/models/v5/yolov5-p6.yaml +5 -2
  63. ultralytics/cfg/models/v5/yolov5.yaml +5 -2
  64. ultralytics/cfg/models/v6/yolov6.yaml +5 -2
  65. ultralytics/cfg/models/v8/yolov8-cls-resnet101.yaml +5 -2
  66. ultralytics/cfg/models/v8/yolov8-cls-resnet50.yaml +5 -2
  67. ultralytics/cfg/models/v8/yolov8-cls.yaml +5 -2
  68. ultralytics/cfg/models/v8/yolov8-ghost-p2.yaml +6 -2
  69. ultralytics/cfg/models/v8/yolov8-ghost-p6.yaml +6 -2
  70. ultralytics/cfg/models/v8/yolov8-ghost.yaml +5 -2
  71. ultralytics/cfg/models/v8/yolov8-obb.yaml +5 -2
  72. ultralytics/cfg/models/v8/yolov8-p2.yaml +5 -2
  73. ultralytics/cfg/models/v8/yolov8-p6.yaml +10 -7
  74. ultralytics/cfg/models/v8/yolov8-pose-p6.yaml +5 -2
  75. ultralytics/cfg/models/v8/yolov8-pose.yaml +5 -2
  76. ultralytics/cfg/models/v8/yolov8-rtdetr.yaml +5 -2
  77. ultralytics/cfg/models/v8/yolov8-seg-p6.yaml +5 -2
  78. ultralytics/cfg/models/v8/yolov8-seg.yaml +5 -2
  79. ultralytics/cfg/models/v8/yolov8-world.yaml +5 -2
  80. ultralytics/cfg/models/v8/yolov8-worldv2.yaml +5 -2
  81. ultralytics/cfg/models/v8/yolov8.yaml +5 -2
  82. ultralytics/cfg/models/v9/yolov9c-seg.yaml +41 -0
  83. ultralytics/cfg/models/v9/yolov9c.yaml +30 -25
  84. ultralytics/cfg/models/v9/yolov9e-seg.yaml +64 -0
  85. ultralytics/cfg/models/v9/yolov9e.yaml +46 -42
  86. ultralytics/cfg/models/v9/yolov9m.yaml +41 -0
  87. ultralytics/cfg/models/v9/yolov9s.yaml +41 -0
  88. ultralytics/cfg/models/v9/yolov9t.yaml +41 -0
  89. ultralytics/cfg/solutions/default.yaml +24 -0
  90. ultralytics/cfg/trackers/botsort.yaml +8 -5
  91. ultralytics/cfg/trackers/bytetrack.yaml +8 -5
  92. ultralytics/data/__init__.py +14 -3
  93. ultralytics/data/annotator.py +37 -15
  94. ultralytics/data/augment.py +1783 -289
  95. ultralytics/data/base.py +62 -27
  96. ultralytics/data/build.py +36 -8
  97. ultralytics/data/converter.py +196 -36
  98. ultralytics/data/dataset.py +233 -94
  99. ultralytics/data/loaders.py +199 -96
  100. ultralytics/data/split_dota.py +39 -29
  101. ultralytics/data/utils.py +110 -40
  102. ultralytics/engine/__init__.py +1 -1
  103. ultralytics/engine/exporter.py +569 -242
  104. ultralytics/engine/model.py +604 -252
  105. ultralytics/engine/predictor.py +22 -11
  106. ultralytics/engine/results.py +1228 -218
  107. ultralytics/engine/trainer.py +190 -129
  108. ultralytics/engine/tuner.py +18 -18
  109. ultralytics/engine/validator.py +18 -15
  110. ultralytics/hub/__init__.py +31 -13
  111. ultralytics/hub/auth.py +11 -7
  112. ultralytics/hub/google/__init__.py +159 -0
  113. ultralytics/hub/session.py +128 -94
  114. ultralytics/hub/utils.py +20 -21
  115. ultralytics/models/__init__.py +4 -2
  116. ultralytics/models/fastsam/__init__.py +2 -3
  117. ultralytics/models/fastsam/model.py +26 -4
  118. ultralytics/models/fastsam/predict.py +127 -63
  119. ultralytics/models/fastsam/utils.py +1 -44
  120. ultralytics/models/fastsam/val.py +1 -1
  121. ultralytics/models/nas/__init__.py +1 -1
  122. ultralytics/models/nas/model.py +21 -10
  123. ultralytics/models/nas/predict.py +3 -6
  124. ultralytics/models/nas/val.py +4 -4
  125. ultralytics/models/rtdetr/__init__.py +1 -1
  126. ultralytics/models/rtdetr/model.py +1 -1
  127. ultralytics/models/rtdetr/predict.py +6 -8
  128. ultralytics/models/rtdetr/train.py +6 -2
  129. ultralytics/models/rtdetr/val.py +3 -3
  130. ultralytics/models/sam/__init__.py +3 -3
  131. ultralytics/models/sam/amg.py +29 -23
  132. ultralytics/models/sam/build.py +211 -13
  133. ultralytics/models/sam/model.py +91 -30
  134. ultralytics/models/sam/modules/__init__.py +1 -1
  135. ultralytics/models/sam/modules/blocks.py +1129 -0
  136. ultralytics/models/sam/modules/decoders.py +381 -53
  137. ultralytics/models/sam/modules/encoders.py +515 -324
  138. ultralytics/models/sam/modules/memory_attention.py +237 -0
  139. ultralytics/models/sam/modules/sam.py +969 -21
  140. ultralytics/models/sam/modules/tiny_encoder.py +425 -154
  141. ultralytics/models/sam/modules/transformer.py +159 -60
  142. ultralytics/models/sam/modules/utils.py +293 -0
  143. ultralytics/models/sam/predict.py +1263 -132
  144. ultralytics/models/utils/__init__.py +1 -1
  145. ultralytics/models/utils/loss.py +36 -24
  146. ultralytics/models/utils/ops.py +3 -7
  147. ultralytics/models/yolo/__init__.py +3 -3
  148. ultralytics/models/yolo/classify/__init__.py +1 -1
  149. ultralytics/models/yolo/classify/predict.py +7 -8
  150. ultralytics/models/yolo/classify/train.py +17 -22
  151. ultralytics/models/yolo/classify/val.py +8 -4
  152. ultralytics/models/yolo/detect/__init__.py +1 -1
  153. ultralytics/models/yolo/detect/predict.py +3 -5
  154. ultralytics/models/yolo/detect/train.py +11 -4
  155. ultralytics/models/yolo/detect/val.py +90 -52
  156. ultralytics/models/yolo/model.py +14 -9
  157. ultralytics/models/yolo/obb/__init__.py +1 -1
  158. ultralytics/models/yolo/obb/predict.py +2 -2
  159. ultralytics/models/yolo/obb/train.py +5 -3
  160. ultralytics/models/yolo/obb/val.py +41 -23
  161. ultralytics/models/yolo/pose/__init__.py +1 -1
  162. ultralytics/models/yolo/pose/predict.py +3 -5
  163. ultralytics/models/yolo/pose/train.py +2 -2
  164. ultralytics/models/yolo/pose/val.py +51 -17
  165. ultralytics/models/yolo/segment/__init__.py +1 -1
  166. ultralytics/models/yolo/segment/predict.py +3 -5
  167. ultralytics/models/yolo/segment/train.py +2 -2
  168. ultralytics/models/yolo/segment/val.py +60 -19
  169. ultralytics/models/yolo/world/__init__.py +5 -0
  170. ultralytics/models/yolo/world/train.py +92 -0
  171. ultralytics/models/yolo/world/train_world.py +109 -0
  172. ultralytics/nn/__init__.py +1 -1
  173. ultralytics/nn/autobackend.py +228 -93
  174. ultralytics/nn/modules/__init__.py +39 -14
  175. ultralytics/nn/modules/activation.py +21 -0
  176. ultralytics/nn/modules/block.py +527 -67
  177. ultralytics/nn/modules/conv.py +24 -7
  178. ultralytics/nn/modules/head.py +177 -34
  179. ultralytics/nn/modules/transformer.py +6 -5
  180. ultralytics/nn/modules/utils.py +1 -2
  181. ultralytics/nn/tasks.py +225 -77
  182. ultralytics/solutions/__init__.py +30 -1
  183. ultralytics/solutions/ai_gym.py +96 -143
  184. ultralytics/solutions/analytics.py +247 -0
  185. ultralytics/solutions/distance_calculation.py +78 -135
  186. ultralytics/solutions/heatmap.py +93 -247
  187. ultralytics/solutions/object_counter.py +184 -259
  188. ultralytics/solutions/parking_management.py +246 -0
  189. ultralytics/solutions/queue_management.py +112 -0
  190. ultralytics/solutions/region_counter.py +116 -0
  191. ultralytics/solutions/security_alarm.py +144 -0
  192. ultralytics/solutions/solutions.py +178 -0
  193. ultralytics/solutions/speed_estimation.py +86 -174
  194. ultralytics/solutions/streamlit_inference.py +190 -0
  195. ultralytics/solutions/trackzone.py +68 -0
  196. ultralytics/trackers/__init__.py +1 -1
  197. ultralytics/trackers/basetrack.py +32 -13
  198. ultralytics/trackers/bot_sort.py +61 -28
  199. ultralytics/trackers/byte_tracker.py +83 -51
  200. ultralytics/trackers/track.py +21 -6
  201. ultralytics/trackers/utils/__init__.py +1 -1
  202. ultralytics/trackers/utils/gmc.py +62 -48
  203. ultralytics/trackers/utils/kalman_filter.py +166 -35
  204. ultralytics/trackers/utils/matching.py +40 -21
  205. ultralytics/utils/__init__.py +511 -239
  206. ultralytics/utils/autobatch.py +40 -22
  207. ultralytics/utils/benchmarks.py +266 -85
  208. ultralytics/utils/callbacks/__init__.py +1 -1
  209. ultralytics/utils/callbacks/base.py +1 -3
  210. ultralytics/utils/callbacks/clearml.py +7 -6
  211. ultralytics/utils/callbacks/comet.py +39 -17
  212. ultralytics/utils/callbacks/dvc.py +1 -1
  213. ultralytics/utils/callbacks/hub.py +16 -16
  214. ultralytics/utils/callbacks/mlflow.py +28 -24
  215. ultralytics/utils/callbacks/neptune.py +6 -2
  216. ultralytics/utils/callbacks/raytune.py +3 -4
  217. ultralytics/utils/callbacks/tensorboard.py +18 -18
  218. ultralytics/utils/callbacks/wb.py +27 -20
  219. ultralytics/utils/checks.py +160 -100
  220. ultralytics/utils/dist.py +2 -1
  221. ultralytics/utils/downloads.py +44 -37
  222. ultralytics/utils/errors.py +1 -1
  223. ultralytics/utils/files.py +72 -38
  224. ultralytics/utils/instance.py +41 -19
  225. ultralytics/utils/loss.py +84 -56
  226. ultralytics/utils/metrics.py +61 -56
  227. ultralytics/utils/ops.py +94 -89
  228. ultralytics/utils/patches.py +30 -14
  229. ultralytics/utils/plotting.py +600 -269
  230. ultralytics/utils/tal.py +67 -26
  231. ultralytics/utils/torch_utils.py +302 -102
  232. ultralytics/utils/triton.py +2 -1
  233. ultralytics/utils/tuner.py +21 -12
  234. ultralytics-8.3.62.dist-info/METADATA +370 -0
  235. ultralytics-8.3.62.dist-info/RECORD +241 -0
  236. {ultralytics-8.1.28.dist-info → ultralytics-8.3.62.dist-info}/WHEEL +1 -1
  237. ultralytics/data/explorer/__init__.py +0 -5
  238. ultralytics/data/explorer/explorer.py +0 -472
  239. ultralytics/data/explorer/gui/__init__.py +0 -1
  240. ultralytics/data/explorer/gui/dash.py +0 -268
  241. ultralytics/data/explorer/utils.py +0 -166
  242. ultralytics/models/fastsam/prompt.py +0 -357
  243. ultralytics-8.1.28.dist-info/METADATA +0 -373
  244. ultralytics-8.1.28.dist-info/RECORD +0 -197
  245. {ultralytics-8.1.28.dist-info → ultralytics-8.3.62.dist-info}/LICENSE +0 -0
  246. {ultralytics-8.1.28.dist-info → ultralytics-8.3.62.dist-info}/entry_points.txt +0 -0
  247. {ultralytics-8.1.28.dist-info → ultralytics-8.3.62.dist-info}/top_level.txt +0 -0
tests/test_exports.py ADDED
@@ -0,0 +1,216 @@
1
+ # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2
+
3
+ import shutil
4
+ import uuid
5
+ from itertools import product
6
+ from pathlib import Path
7
+
8
+ import pytest
9
+
10
+ from tests import MODEL, SOURCE
11
+ from ultralytics import YOLO
12
+ from ultralytics.cfg import TASK2DATA, TASK2MODEL, TASKS
13
+ from ultralytics.utils import (
14
+ IS_RASPBERRYPI,
15
+ LINUX,
16
+ MACOS,
17
+ WINDOWS,
18
+ checks,
19
+ )
20
+ from ultralytics.utils.torch_utils import TORCH_1_9, TORCH_1_13
21
+
22
+
23
+ def test_export_torchscript():
24
+ """Test YOLO model exporting to TorchScript format for compatibility and correctness."""
25
+ file = YOLO(MODEL).export(format="torchscript", optimize=False, imgsz=32)
26
+ YOLO(file)(SOURCE, imgsz=32) # exported model inference
27
+
28
+
29
+ def test_export_onnx():
30
+ """Test YOLO model export to ONNX format with dynamic axes."""
31
+ file = YOLO(MODEL).export(format="onnx", dynamic=True, imgsz=32)
32
+ YOLO(file)(SOURCE, imgsz=32) # exported model inference
33
+
34
+
35
+ @pytest.mark.skipif(not TORCH_1_13, reason="OpenVINO requires torch>=1.13")
36
+ def test_export_openvino():
37
+ """Test YOLO exports to OpenVINO format for model inference compatibility."""
38
+ file = YOLO(MODEL).export(format="openvino", imgsz=32)
39
+ YOLO(file)(SOURCE, imgsz=32) # exported model inference
40
+
41
+
42
+ @pytest.mark.slow
43
+ @pytest.mark.skipif(not TORCH_1_13, reason="OpenVINO requires torch>=1.13")
44
+ @pytest.mark.parametrize(
45
+ "task, dynamic, int8, half, batch",
46
+ [ # generate all combinations but exclude those where both int8 and half are True
47
+ (task, dynamic, int8, half, batch)
48
+ for task, dynamic, int8, half, batch in product(TASKS, [True, False], [True, False], [True, False], [1, 2])
49
+ if not (int8 and half) # exclude cases where both int8 and half are True
50
+ ],
51
+ )
52
+ def test_export_openvino_matrix(task, dynamic, int8, half, batch):
53
+ """Test YOLO model exports to OpenVINO under various configuration matrix conditions."""
54
+ file = YOLO(TASK2MODEL[task]).export(
55
+ format="openvino",
56
+ imgsz=32,
57
+ dynamic=dynamic,
58
+ int8=int8,
59
+ half=half,
60
+ batch=batch,
61
+ data=TASK2DATA[task],
62
+ )
63
+ if WINDOWS:
64
+ # Use unique filenames due to Windows file permissions bug possibly due to latent threaded use
65
+ # See https://github.com/ultralytics/ultralytics/actions/runs/8957949304/job/24601616830?pr=10423
66
+ file = Path(file)
67
+ file = file.rename(file.with_stem(f"{file.stem}-{uuid.uuid4()}"))
68
+ YOLO(file)([SOURCE] * batch, imgsz=64 if dynamic else 32) # exported model inference
69
+ shutil.rmtree(file, ignore_errors=True) # retry in case of potential lingering multi-threaded file usage errors
70
+
71
+
72
+ @pytest.mark.slow
73
+ @pytest.mark.parametrize(
74
+ "task, dynamic, int8, half, batch, simplify", product(TASKS, [True, False], [False], [False], [1, 2], [True, False])
75
+ )
76
+ def test_export_onnx_matrix(task, dynamic, int8, half, batch, simplify):
77
+ """Test YOLO exports to ONNX format with various configurations and parameters."""
78
+ file = YOLO(TASK2MODEL[task]).export(
79
+ format="onnx",
80
+ imgsz=32,
81
+ dynamic=dynamic,
82
+ int8=int8,
83
+ half=half,
84
+ batch=batch,
85
+ simplify=simplify,
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("task, dynamic, int8, half, batch", product(TASKS, [False], [False], [False], [1, 2]))
93
+ def test_export_torchscript_matrix(task, dynamic, int8, half, batch):
94
+ """Tests YOLO model exports to TorchScript format under varied configurations."""
95
+ file = YOLO(TASK2MODEL[task]).export(
96
+ format="torchscript",
97
+ imgsz=32,
98
+ dynamic=dynamic,
99
+ int8=int8,
100
+ half=half,
101
+ batch=batch,
102
+ )
103
+ YOLO(file)([SOURCE] * 3, imgsz=64 if dynamic else 32) # exported model inference at batch=3
104
+ Path(file).unlink() # cleanup
105
+
106
+
107
+ @pytest.mark.slow
108
+ @pytest.mark.skipif(not MACOS, reason="CoreML inference only supported on macOS")
109
+ @pytest.mark.skipif(not TORCH_1_9, reason="CoreML>=7.2 not supported with PyTorch<=1.8")
110
+ @pytest.mark.skipif(checks.IS_PYTHON_3_12, reason="CoreML not supported in Python 3.12")
111
+ @pytest.mark.parametrize(
112
+ "task, dynamic, int8, half, batch",
113
+ [ # generate all combinations but exclude those where both int8 and half are True
114
+ (task, dynamic, int8, half, batch)
115
+ for task, dynamic, int8, half, batch in product(TASKS, [False], [True, False], [True, False], [1])
116
+ if not (int8 and half) # exclude cases where both int8 and half are True
117
+ ],
118
+ )
119
+ def test_export_coreml_matrix(task, dynamic, int8, half, batch):
120
+ """Test YOLO exports to CoreML format with various parameter configurations."""
121
+ file = YOLO(TASK2MODEL[task]).export(
122
+ format="coreml",
123
+ imgsz=32,
124
+ dynamic=dynamic,
125
+ int8=int8,
126
+ half=half,
127
+ batch=batch,
128
+ )
129
+ YOLO(file)([SOURCE] * batch, imgsz=32) # exported model inference at batch=3
130
+ shutil.rmtree(file) # cleanup
131
+
132
+
133
+ @pytest.mark.slow
134
+ @pytest.mark.skipif(not checks.IS_PYTHON_MINIMUM_3_10, reason="TFLite export requires Python>=3.10")
135
+ @pytest.mark.skipif(not LINUX, reason="Test disabled as TF suffers from install conflicts on Windows and macOS")
136
+ @pytest.mark.parametrize(
137
+ "task, dynamic, int8, half, batch",
138
+ [ # generate all combinations but exclude those where both int8 and half are True
139
+ (task, dynamic, int8, half, batch)
140
+ for task, dynamic, int8, half, batch in product(TASKS, [False], [True, False], [True, False], [1])
141
+ if not (int8 and half) # exclude cases where both int8 and half are True
142
+ ],
143
+ )
144
+ def test_export_tflite_matrix(task, dynamic, int8, half, batch):
145
+ """Test YOLO exports to TFLite format considering various export configurations."""
146
+ file = YOLO(TASK2MODEL[task]).export(
147
+ format="tflite",
148
+ imgsz=32,
149
+ dynamic=dynamic,
150
+ int8=int8,
151
+ half=half,
152
+ batch=batch,
153
+ )
154
+ YOLO(file)([SOURCE] * batch, imgsz=32) # exported model inference at batch=3
155
+ Path(file).unlink() # cleanup
156
+
157
+
158
+ @pytest.mark.skipif(not TORCH_1_9, reason="CoreML>=7.2 not supported with PyTorch<=1.8")
159
+ @pytest.mark.skipif(WINDOWS, reason="CoreML not supported on Windows") # RuntimeError: BlobWriter not loaded
160
+ @pytest.mark.skipif(IS_RASPBERRYPI, reason="CoreML not supported on Raspberry Pi")
161
+ @pytest.mark.skipif(checks.IS_PYTHON_3_12, reason="CoreML not supported in Python 3.12")
162
+ def test_export_coreml():
163
+ """Test YOLO exports to CoreML format, optimized for macOS only."""
164
+ if MACOS:
165
+ file = YOLO(MODEL).export(format="coreml", imgsz=32)
166
+ YOLO(file)(SOURCE, imgsz=32) # model prediction only supported on macOS for nms=False models
167
+ else:
168
+ YOLO(MODEL).export(format="coreml", nms=True, imgsz=32)
169
+
170
+
171
+ @pytest.mark.skipif(not checks.IS_PYTHON_MINIMUM_3_10, reason="TFLite export requires Python>=3.10")
172
+ @pytest.mark.skipif(not LINUX, reason="Test disabled as TF suffers from install conflicts on Windows and macOS")
173
+ def test_export_tflite():
174
+ """Test YOLO exports to TFLite format under specific OS and Python version conditions."""
175
+ model = YOLO(MODEL)
176
+ file = model.export(format="tflite", imgsz=32)
177
+ YOLO(file)(SOURCE, imgsz=32)
178
+
179
+
180
+ @pytest.mark.skipif(True, reason="Test disabled")
181
+ @pytest.mark.skipif(not LINUX, reason="TF suffers from install conflicts on Windows and macOS")
182
+ def test_export_pb():
183
+ """Test YOLO exports to TensorFlow's Protobuf (*.pb) format."""
184
+ model = YOLO(MODEL)
185
+ file = model.export(format="pb", imgsz=32)
186
+ YOLO(file)(SOURCE, imgsz=32)
187
+
188
+
189
+ @pytest.mark.skipif(True, reason="Test disabled as Paddle protobuf and ONNX protobuf requirements conflict.")
190
+ def test_export_paddle():
191
+ """Test YOLO exports to Paddle format, noting protobuf conflicts with ONNX."""
192
+ YOLO(MODEL).export(format="paddle", imgsz=32)
193
+
194
+
195
+ @pytest.mark.slow
196
+ @pytest.mark.skipif(IS_RASPBERRYPI, reason="MNN not supported on Raspberry Pi")
197
+ def test_export_mnn():
198
+ """Test YOLO exports to MNN format (WARNING: MNN test must precede NCNN test or CI error on Windows)."""
199
+ file = YOLO(MODEL).export(format="mnn", imgsz=32)
200
+ YOLO(file)(SOURCE, imgsz=32) # exported model inference
201
+
202
+
203
+ @pytest.mark.slow
204
+ def test_export_ncnn():
205
+ """Test YOLO exports to NCNN format."""
206
+ file = YOLO(MODEL).export(format="ncnn", imgsz=32)
207
+ YOLO(file)(SOURCE, imgsz=32) # exported model inference
208
+
209
+
210
+ @pytest.mark.skipif(True, reason="Test disabled as keras and tensorflow version conflicts with tflite export.")
211
+ @pytest.mark.skipif(not LINUX or MACOS, reason="Skipping test on Windows and Macos")
212
+ def test_export_imx():
213
+ """Test YOLOv8n exports to IMX format."""
214
+ model = YOLO("yolov8n.pt")
215
+ file = model.export(format="imx", imgsz=32)
216
+ YOLO(file)(SOURCE, imgsz=32)
@@ -0,0 +1,150 @@
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, TMP
12
+ from ultralytics import YOLO, download
13
+ from ultralytics.utils import DATASETS_DIR, SETTINGS
14
+ from ultralytics.utils.checks import check_requirements
15
+
16
+
17
+ @pytest.mark.skipif(not check_requirements("ray", install=False), reason="ray[tune] not installed")
18
+ def test_model_ray_tune():
19
+ """Tune YOLO model using Ray for hyperparameter optimization."""
20
+ YOLO("yolo11n-cls.yaml").tune(
21
+ use_ray=True, data="imagenet10", grace_period=1, iterations=1, imgsz=32, epochs=1, plots=False, device="cpu"
22
+ )
23
+
24
+
25
+ @pytest.mark.skipif(not check_requirements("mlflow", install=False), reason="mlflow not installed")
26
+ def test_mlflow():
27
+ """Test training with MLflow tracking enabled (see https://mlflow.org/ for details)."""
28
+ SETTINGS["mlflow"] = True
29
+ YOLO("yolo11n-cls.yaml").train(data="imagenet10", imgsz=32, epochs=3, plots=False, device="cpu")
30
+ SETTINGS["mlflow"] = False
31
+
32
+
33
+ @pytest.mark.skipif(True, reason="Test failing in scheduled CI https://github.com/ultralytics/ultralytics/pull/8868")
34
+ @pytest.mark.skipif(not check_requirements("mlflow", install=False), reason="mlflow not installed")
35
+ def test_mlflow_keep_run_active():
36
+ """Ensure MLflow run status matches MLFLOW_KEEP_RUN_ACTIVE environment variable settings."""
37
+ import mlflow
38
+
39
+ SETTINGS["mlflow"] = True
40
+ run_name = "Test Run"
41
+ os.environ["MLFLOW_RUN"] = run_name
42
+
43
+ # Test with MLFLOW_KEEP_RUN_ACTIVE=True
44
+ os.environ["MLFLOW_KEEP_RUN_ACTIVE"] = "True"
45
+ YOLO("yolo11n-cls.yaml").train(data="imagenet10", imgsz=32, epochs=1, plots=False, device="cpu")
46
+ status = mlflow.active_run().info.status
47
+ assert status == "RUNNING", "MLflow run should be active when MLFLOW_KEEP_RUN_ACTIVE=True"
48
+
49
+ run_id = mlflow.active_run().info.run_id
50
+
51
+ # Test with MLFLOW_KEEP_RUN_ACTIVE=False
52
+ os.environ["MLFLOW_KEEP_RUN_ACTIVE"] = "False"
53
+ YOLO("yolo11n-cls.yaml").train(data="imagenet10", imgsz=32, epochs=1, plots=False, device="cpu")
54
+ status = mlflow.get_run(run_id=run_id).info.status
55
+ assert status == "FINISHED", "MLflow run should be ended when MLFLOW_KEEP_RUN_ACTIVE=False"
56
+
57
+ # Test with MLFLOW_KEEP_RUN_ACTIVE not set
58
+ os.environ.pop("MLFLOW_KEEP_RUN_ACTIVE", None)
59
+ YOLO("yolo11n-cls.yaml").train(data="imagenet10", imgsz=32, epochs=1, plots=False, device="cpu")
60
+ status = mlflow.get_run(run_id=run_id).info.status
61
+ assert status == "FINISHED", "MLflow run should be ended by default when MLFLOW_KEEP_RUN_ACTIVE is not set"
62
+ SETTINGS["mlflow"] = False
63
+
64
+
65
+ @pytest.mark.skipif(not check_requirements("tritonclient", install=False), reason="tritonclient[all] not installed")
66
+ def test_triton():
67
+ """
68
+ Test NVIDIA Triton Server functionalities with YOLO model.
69
+
70
+ See https://catalog.ngc.nvidia.com/orgs/nvidia/containers/tritonserver.
71
+ """
72
+ check_requirements("tritonclient[all]")
73
+ from tritonclient.http import InferenceServerClient # noqa
74
+
75
+ # Create variables
76
+ model_name = "yolo"
77
+ triton_repo = TMP / "triton_repo" # Triton repo path
78
+ triton_model = triton_repo / model_name # Triton model path
79
+
80
+ # Export model to ONNX
81
+ f = YOLO(MODEL).export(format="onnx", dynamic=True)
82
+
83
+ # Prepare Triton repo
84
+ (triton_model / "1").mkdir(parents=True, exist_ok=True)
85
+ Path(f).rename(triton_model / "1" / "model.onnx")
86
+ (triton_model / "config.pbtxt").touch()
87
+
88
+ # Define image https://catalog.ngc.nvidia.com/orgs/nvidia/containers/tritonserver
89
+ tag = "nvcr.io/nvidia/tritonserver:23.09-py3" # 6.4 GB
90
+
91
+ # Pull the image
92
+ subprocess.call(f"docker pull {tag}", shell=True)
93
+
94
+ # Run the Triton server and capture the container ID
95
+ container_id = (
96
+ subprocess.check_output(
97
+ f"docker run -d --rm -v {triton_repo}:/models -p 8000:8000 {tag} tritonserver --model-repository=/models",
98
+ shell=True,
99
+ )
100
+ .decode("utf-8")
101
+ .strip()
102
+ )
103
+
104
+ # Wait for the Triton server to start
105
+ triton_client = InferenceServerClient(url="localhost:8000", verbose=False, ssl=False)
106
+
107
+ # Wait until model is ready
108
+ for _ in range(10):
109
+ with contextlib.suppress(Exception):
110
+ assert triton_client.is_model_ready(model_name)
111
+ break
112
+ time.sleep(1)
113
+
114
+ # Check Triton inference
115
+ YOLO(f"http://localhost:8000/{model_name}", "detect")(SOURCE) # exported model inference
116
+
117
+ # Kill and remove the container at the end of the test
118
+ subprocess.call(f"docker kill {container_id}", shell=True)
119
+
120
+
121
+ @pytest.mark.skipif(not check_requirements("pycocotools", install=False), reason="pycocotools not installed")
122
+ def test_pycocotools():
123
+ """Validate YOLO model predictions on COCO dataset using pycocotools."""
124
+ from ultralytics.models.yolo.detect import DetectionValidator
125
+ from ultralytics.models.yolo.pose import PoseValidator
126
+ from ultralytics.models.yolo.segment import SegmentationValidator
127
+
128
+ # Download annotations after each dataset downloads first
129
+ url = "https://github.com/ultralytics/assets/releases/download/v0.0.0/"
130
+
131
+ args = {"model": "yolo11n.pt", "data": "coco8.yaml", "save_json": True, "imgsz": 64}
132
+ validator = DetectionValidator(args=args)
133
+ validator()
134
+ validator.is_coco = True
135
+ download(f"{url}instances_val2017.json", dir=DATASETS_DIR / "coco8/annotations")
136
+ _ = validator.eval_json(validator.stats)
137
+
138
+ args = {"model": "yolo11n-seg.pt", "data": "coco8-seg.yaml", "save_json": True, "imgsz": 64}
139
+ validator = SegmentationValidator(args=args)
140
+ validator()
141
+ validator.is_coco = True
142
+ download(f"{url}instances_val2017.json", dir=DATASETS_DIR / "coco8-seg/annotations")
143
+ _ = validator.eval_json(validator.stats)
144
+
145
+ args = {"model": "yolo11n-pose.pt", "data": "coco8-pose.yaml", "save_json": True, "imgsz": 64}
146
+ validator = PoseValidator(args=args)
147
+ validator()
148
+ validator.is_coco = True
149
+ download(f"{url}person_keypoints_val2017.json", dir=DATASETS_DIR / "coco8-pose/annotations")
150
+ _ = validator.eval_json(validator.stats)