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
@@ -0,0 +1,371 @@
1
+ # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2
+
3
+ # Tests Ultralytics Solutions: https://docs.ultralytics.com/solutions/,
4
+ # Includes all solutions except DistanceCalculation and the Security Alarm System.
5
+
6
+ import os
7
+ from unittest.mock import patch
8
+
9
+ import cv2
10
+ import numpy as np
11
+ import pytest
12
+
13
+ from tests import MODEL
14
+ from ultralytics import solutions
15
+ from ultralytics.utils import ASSETS_URL, IS_RASPBERRYPI, TORCH_VERSION, checks
16
+ from ultralytics.utils.downloads import safe_download
17
+ from ultralytics.utils.torch_utils import TORCH_2_4
18
+
19
+ # Predefined argument values
20
+ SHOW = False
21
+ DEMO_VIDEO = "solutions_ci_demo.mp4" # for all the solutions, except workout, object cropping and parking management
22
+ CROP_VIDEO = "decelera_landscape_min.mov" # for object cropping solution
23
+ POSE_VIDEO = "solution_ci_pose_demo.mp4" # only for workouts monitoring solution
24
+ PARKING_VIDEO = "solution_ci_parking_demo.mp4" # only for parking management solution
25
+ PARKING_AREAS_JSON = "solution_ci_parking_areas.json" # only for parking management solution
26
+ PARKING_MODEL = "solutions_ci_parking_model.pt" # only for parking management solution
27
+ VERTICAL_VIDEO = "solution_vertical_demo.mp4" # only for vertical line counting
28
+ REGION = [(10, 200), (540, 200), (540, 180), (10, 180)] # for object counting, speed estimation and queue management
29
+ HORIZONTAL_LINE = [(10, 200), (540, 200)] # for object counting
30
+ VERTICAL_LINE = [(320, 0), (320, 400)] # for object counting
31
+
32
+
33
+ def process_video(solution, video_path: str, needs_frame_count: bool = False):
34
+ """Process video with solution, feeding frames and optional frame count to the solution instance."""
35
+ cap = cv2.VideoCapture(video_path)
36
+ assert cap.isOpened(), f"Error reading video file {video_path}"
37
+
38
+ frame_count = 0
39
+ while cap.isOpened():
40
+ success, im0 = cap.read()
41
+ if not success:
42
+ break
43
+ frame_count += 1
44
+ im_copy = im0.copy()
45
+ args = [im_copy, frame_count] if needs_frame_count else [im_copy]
46
+ _ = solution(*args)
47
+
48
+ cap.release()
49
+
50
+
51
+ @pytest.mark.skipif(IS_RASPBERRYPI, reason="Disabled for testing due to --slow test errors after YOLOE PR.")
52
+ @pytest.mark.parametrize(
53
+ "name, solution_class, needs_frame_count, video, kwargs",
54
+ [
55
+ (
56
+ "ObjectCounter",
57
+ solutions.ObjectCounter,
58
+ False,
59
+ DEMO_VIDEO,
60
+ {"region": REGION, "model": MODEL, "show": SHOW},
61
+ ),
62
+ (
63
+ "ObjectCounter",
64
+ solutions.ObjectCounter,
65
+ False,
66
+ DEMO_VIDEO,
67
+ {"region": HORIZONTAL_LINE, "model": MODEL, "show": SHOW},
68
+ ),
69
+ (
70
+ "ObjectCounterVertical",
71
+ solutions.ObjectCounter,
72
+ False,
73
+ DEMO_VIDEO,
74
+ {"region": VERTICAL_LINE, "model": MODEL, "show": SHOW},
75
+ ),
76
+ (
77
+ "ObjectCounterwithOBB",
78
+ solutions.ObjectCounter,
79
+ False,
80
+ DEMO_VIDEO,
81
+ {"region": REGION, "model": "yolo11n-obb.pt", "show": SHOW},
82
+ ),
83
+ (
84
+ "Heatmap",
85
+ solutions.Heatmap,
86
+ False,
87
+ DEMO_VIDEO,
88
+ {"colormap": cv2.COLORMAP_PARULA, "model": MODEL, "show": SHOW, "region": None},
89
+ ),
90
+ (
91
+ "HeatmapWithRegion",
92
+ solutions.Heatmap,
93
+ False,
94
+ DEMO_VIDEO,
95
+ {"colormap": cv2.COLORMAP_PARULA, "region": REGION, "model": MODEL, "show": SHOW},
96
+ ),
97
+ (
98
+ "SpeedEstimator",
99
+ solutions.SpeedEstimator,
100
+ False,
101
+ DEMO_VIDEO,
102
+ {"region": REGION, "model": MODEL, "show": SHOW},
103
+ ),
104
+ (
105
+ "QueueManager",
106
+ solutions.QueueManager,
107
+ False,
108
+ DEMO_VIDEO,
109
+ {"region": REGION, "model": MODEL, "show": SHOW},
110
+ ),
111
+ (
112
+ "LineAnalytics",
113
+ solutions.Analytics,
114
+ True,
115
+ DEMO_VIDEO,
116
+ {"analytics_type": "line", "model": MODEL, "show": SHOW, "figsize": (6.4, 3.2)},
117
+ ),
118
+ (
119
+ "PieAnalytics",
120
+ solutions.Analytics,
121
+ True,
122
+ DEMO_VIDEO,
123
+ {"analytics_type": "pie", "model": MODEL, "show": SHOW, "figsize": (6.4, 3.2)},
124
+ ),
125
+ (
126
+ "BarAnalytics",
127
+ solutions.Analytics,
128
+ True,
129
+ DEMO_VIDEO,
130
+ {"analytics_type": "bar", "model": MODEL, "show": SHOW, "figsize": (6.4, 3.2)},
131
+ ),
132
+ (
133
+ "AreaAnalytics",
134
+ solutions.Analytics,
135
+ True,
136
+ DEMO_VIDEO,
137
+ {"analytics_type": "area", "model": MODEL, "show": SHOW, "figsize": (6.4, 3.2)},
138
+ ),
139
+ ("TrackZone", solutions.TrackZone, False, DEMO_VIDEO, {"region": REGION, "model": MODEL, "show": SHOW}),
140
+ (
141
+ "ObjectCropper",
142
+ solutions.ObjectCropper,
143
+ False,
144
+ CROP_VIDEO,
145
+ {"temp_crop_dir": "cropped-detections", "model": MODEL, "show": SHOW},
146
+ ),
147
+ (
148
+ "ObjectBlurrer",
149
+ solutions.ObjectBlurrer,
150
+ False,
151
+ DEMO_VIDEO,
152
+ {"blur_ratio": 0.02, "model": MODEL, "show": SHOW},
153
+ ),
154
+ (
155
+ "InstanceSegmentation",
156
+ solutions.InstanceSegmentation,
157
+ False,
158
+ DEMO_VIDEO,
159
+ {"model": "yolo11n-seg.pt", "show": SHOW},
160
+ ),
161
+ ("VisionEye", solutions.VisionEye, False, DEMO_VIDEO, {"model": MODEL, "show": SHOW}),
162
+ (
163
+ "RegionCounter",
164
+ solutions.RegionCounter,
165
+ False,
166
+ DEMO_VIDEO,
167
+ {"region": REGION, "model": MODEL, "show": SHOW},
168
+ ),
169
+ ("AIGym", solutions.AIGym, False, POSE_VIDEO, {"kpts": [6, 8, 10], "show": SHOW}),
170
+ (
171
+ "ParkingManager",
172
+ solutions.ParkingManagement,
173
+ False,
174
+ PARKING_VIDEO,
175
+ {"temp_model": str(PARKING_MODEL), "show": SHOW, "temp_json_file": str(PARKING_AREAS_JSON)},
176
+ ),
177
+ (
178
+ "StreamlitInference",
179
+ solutions.Inference,
180
+ False,
181
+ None, # streamlit application doesn't require video file
182
+ {}, # streamlit application doesn't accept arguments
183
+ ),
184
+ ],
185
+ )
186
+ def test_solution(name, solution_class, needs_frame_count, video, kwargs, tmp_path):
187
+ """Test individual Ultralytics solution with video processing and parameter validation."""
188
+ if video:
189
+ if name != "ObjectCounterVertical":
190
+ safe_download(url=f"{ASSETS_URL}/{video}", dir=tmp_path)
191
+ else:
192
+ safe_download(url=f"{ASSETS_URL}/{VERTICAL_VIDEO}", dir=tmp_path)
193
+ if name == "ParkingManager":
194
+ safe_download(url=f"{ASSETS_URL}/{PARKING_AREAS_JSON}", dir=tmp_path)
195
+ safe_download(url=f"{ASSETS_URL}/{PARKING_MODEL}", dir=tmp_path)
196
+
197
+ elif name == "StreamlitInference":
198
+ if checks.check_imshow(): # do not merge with elif above
199
+ solution_class(**kwargs).inference() # requires interactive GUI environment
200
+ return
201
+
202
+ # Update kwargs to use tmp_path
203
+ kwargs_updated = {}
204
+ for key in kwargs:
205
+ if key.startswith("temp_"):
206
+ kwargs_updated[key.replace("temp_", "")] = str(tmp_path / kwargs[key])
207
+ else:
208
+ kwargs_updated[key] = kwargs[key]
209
+
210
+ video = VERTICAL_VIDEO if name == "ObjectCounterVertical" else video
211
+ process_video(
212
+ solution=solution_class(**kwargs_updated),
213
+ video_path=str(tmp_path / video),
214
+ needs_frame_count=needs_frame_count,
215
+ )
216
+
217
+
218
+ def test_left_click_selection():
219
+ """Test distance calculation left click selection functionality."""
220
+ dc = solutions.DistanceCalculation()
221
+ dc.boxes, dc.track_ids = [[10, 10, 50, 50]], [1]
222
+ dc.mouse_event_for_distance(cv2.EVENT_LBUTTONDOWN, 30, 30, None, None)
223
+ assert 1 in dc.selected_boxes
224
+
225
+
226
+ def test_right_click_reset():
227
+ """Test distance calculation right click reset functionality."""
228
+ dc = solutions.DistanceCalculation()
229
+ dc.selected_boxes, dc.left_mouse_count = {1: [10, 10, 50, 50]}, 1
230
+ dc.mouse_event_for_distance(cv2.EVENT_RBUTTONDOWN, 0, 0, None, None)
231
+ assert not dc.selected_boxes
232
+ assert dc.left_mouse_count == 0
233
+
234
+
235
+ def test_parking_json_none():
236
+ """Test that ParkingManagement handles missing JSON gracefully."""
237
+ im0 = np.zeros((640, 480, 3), dtype=np.uint8)
238
+ try:
239
+ parkingmanager = solutions.ParkingManagement(json_path=None)
240
+ parkingmanager(im0)
241
+ except ValueError:
242
+ pytest.skip("Skipping test due to missing JSON.")
243
+
244
+
245
+ def test_analytics_graph_not_supported():
246
+ """Test that unsupported analytics type raises ValueError."""
247
+ try:
248
+ analytics = solutions.Analytics(analytics_type="test") # 'test' is unsupported
249
+ analytics.process(im0=np.zeros((640, 480, 3), dtype=np.uint8), frame_number=0)
250
+ assert False, "Expected ValueError for unsupported chart type"
251
+ except ValueError as e:
252
+ assert "Unsupported analytics_type" in str(e)
253
+
254
+
255
+ def test_area_chart_padding():
256
+ """Test area chart graph update with dynamic class padding logic."""
257
+ analytics = solutions.Analytics(analytics_type="area")
258
+ analytics.update_graph(frame_number=1, count_dict={"car": 2}, plot="area")
259
+ plot_im = analytics.update_graph(frame_number=2, count_dict={"car": 3, "person": 1}, plot="area")
260
+ assert plot_im is not None
261
+
262
+
263
+ def test_config_update_method_with_invalid_argument():
264
+ """Test that update() raises ValueError for invalid config keys."""
265
+ obj = solutions.config.SolutionConfig()
266
+ try:
267
+ obj.update(invalid_key=123)
268
+ assert False, "Expected ValueError for invalid update argument"
269
+ except ValueError as e:
270
+ assert "is not a valid solution argument" in str(e)
271
+
272
+
273
+ def test_plot_with_no_masks():
274
+ """Test that instance segmentation handles cases with no masks."""
275
+ im0 = np.zeros((640, 480, 3), dtype=np.uint8)
276
+ isegment = solutions.InstanceSegmentation(model="yolo11n-seg.pt")
277
+ results = isegment(im0)
278
+ assert results.plot_im is not None
279
+
280
+
281
+ def test_streamlit_handle_video_upload_creates_file():
282
+ """Test Streamlit video upload logic saves file correctly."""
283
+ import io
284
+
285
+ fake_file = io.BytesIO(b"fake video content")
286
+ fake_file.read = fake_file.getvalue
287
+ if fake_file is not None:
288
+ g = io.BytesIO(fake_file.read())
289
+ with open("ultralytics.mp4", "wb") as out:
290
+ out.write(g.read())
291
+ output_path = "ultralytics.mp4"
292
+ else:
293
+ output_path = None
294
+ assert output_path == "ultralytics.mp4"
295
+ assert os.path.exists("ultralytics.mp4")
296
+ with open("ultralytics.mp4", "rb") as f:
297
+ assert f.read() == b"fake video content"
298
+ os.remove("ultralytics.mp4")
299
+
300
+
301
+ @pytest.mark.skipif(not TORCH_2_4, reason=f"VisualAISearch requires torch>=2.4 (found torch=={TORCH_VERSION})")
302
+ @pytest.mark.skipif(IS_RASPBERRYPI, reason="Disabled due to slow performance on Raspberry Pi.")
303
+ def test_similarity_search(tmp_path):
304
+ """Test similarity search solution with sample images and text query."""
305
+ safe_download(f"{ASSETS_URL}/4-imgs-similaritysearch.zip", dir=tmp_path) # 4 dog images for testing in a zip file
306
+ searcher = solutions.VisualAISearch(data=str(tmp_path / "4-imgs-similaritysearch"))
307
+ _ = searcher("a dog sitting on a bench") # Returns the results in format "- img name | similarity score"
308
+
309
+
310
+ @pytest.mark.skipif(not TORCH_2_4, reason=f"VisualAISearch requires torch>=2.4 (found torch=={TORCH_VERSION})")
311
+ @pytest.mark.skipif(IS_RASPBERRYPI, reason="Disabled due to slow performance on Raspberry Pi.")
312
+ def test_similarity_search_app_init():
313
+ """Test SearchApp initializes with required attributes."""
314
+ app = solutions.SearchApp(device="cpu")
315
+ assert hasattr(app, "searcher")
316
+ assert hasattr(app, "run")
317
+
318
+
319
+ @pytest.mark.skipif(not TORCH_2_4, reason=f"VisualAISearch requires torch>=2.4 (found torch=={TORCH_VERSION})")
320
+ @pytest.mark.skipif(IS_RASPBERRYPI, reason="Disabled due to slow performance on Raspberry Pi.")
321
+ def test_similarity_search_complete(tmp_path):
322
+ """Test VisualAISearch end-to-end with sample image and query."""
323
+ from PIL import Image
324
+
325
+ image_dir = tmp_path / "images"
326
+ os.makedirs(image_dir, exist_ok=True)
327
+ for i in range(2):
328
+ img = Image.fromarray(np.uint8(np.random.rand(224, 224, 3) * 255))
329
+ img.save(image_dir / f"test_image_{i}.jpg")
330
+ searcher = solutions.VisualAISearch(data=str(image_dir))
331
+ results = searcher("a red and white object")
332
+ assert results
333
+
334
+
335
+ def test_distance_calculation_process_method():
336
+ """Test DistanceCalculation.process() computes distance between selected boxes."""
337
+ from ultralytics.solutions.solutions import SolutionResults
338
+
339
+ dc = solutions.DistanceCalculation()
340
+ dc.boxes, dc.track_ids, dc.clss, dc.confs = (
341
+ [[100, 100, 200, 200], [300, 300, 400, 400]],
342
+ [1, 2],
343
+ [0, 0],
344
+ [0.9, 0.95],
345
+ )
346
+ dc.selected_boxes = {1: dc.boxes[0], 2: dc.boxes[1]}
347
+ frame = np.zeros((480, 640, 3), dtype=np.uint8)
348
+ with patch.object(dc, "extract_tracks"), patch.object(dc, "display_output"), patch("cv2.setMouseCallback"):
349
+ result = dc.process(frame)
350
+ assert isinstance(result, SolutionResults)
351
+ assert result.total_tracks == 2
352
+ assert result.pixels_distance > 0
353
+
354
+
355
+ def test_object_crop_with_show_True():
356
+ """Test ObjectCropper init with show=True to cover display warning."""
357
+ solutions.ObjectCropper(show=True)
358
+
359
+
360
+ def test_display_output_method():
361
+ """Test that display_output triggers imshow, waitKey, and destroyAllWindows when enabled."""
362
+ counter = solutions.ObjectCounter(show=True)
363
+ counter.env_check = True
364
+ frame = np.zeros((100, 100, 3), dtype=np.uint8)
365
+ with patch("cv2.imshow") as mock_imshow, patch("cv2.waitKey", return_value=ord("q")) as mock_wait, patch(
366
+ "cv2.destroyAllWindows"
367
+ ) as mock_destroy:
368
+ counter.display_output(frame)
369
+ mock_imshow.assert_called_once()
370
+ mock_wait.assert_called_once()
371
+ mock_destroy.assert_called_once()
@@ -0,0 +1,48 @@
1
+ # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2
+
3
+ __version__ = "8.3.253"
4
+
5
+ import importlib
6
+ import os
7
+ from typing import TYPE_CHECKING
8
+
9
+ # Set ENV variables (place before imports)
10
+ if not os.environ.get("OMP_NUM_THREADS"):
11
+ os.environ["OMP_NUM_THREADS"] = "1" # default for reduced CPU utilization during training
12
+
13
+ from ultralytics.utils import ASSETS, SETTINGS
14
+ from ultralytics.utils.checks import check_yolo as checks
15
+ from ultralytics.utils.downloads import download
16
+
17
+ settings = SETTINGS
18
+
19
+ MODELS = ("YOLO", "YOLOWorld", "YOLOE", "NAS", "SAM", "FastSAM", "RTDETR")
20
+
21
+ __all__ = (
22
+ "__version__",
23
+ "ASSETS",
24
+ *MODELS,
25
+ "checks",
26
+ "download",
27
+ "settings",
28
+ )
29
+
30
+ if TYPE_CHECKING:
31
+ # Enable hints for type checkers
32
+ from ultralytics.models import YOLO, YOLOWorld, YOLOE, NAS, SAM, FastSAM, RTDETR # noqa
33
+
34
+
35
+ def __getattr__(name: str):
36
+ """Lazy-import model classes on first access."""
37
+ if name in MODELS:
38
+ return getattr(importlib.import_module("ultralytics.models"), name)
39
+ raise AttributeError(f"module {__name__} has no attribute {name}")
40
+
41
+
42
+ def __dir__():
43
+ """Extend dir() to include lazily available model names for IDE autocompletion."""
44
+ return sorted(set(globals()) | set(MODELS))
45
+
46
+
47
+ if __name__ == "__main__":
48
+ print(__version__)
Binary file
Binary file