ultralytics-opencv-headless 8.3.242__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 (298) hide show
  1. tests/__init__.py +23 -0
  2. tests/conftest.py +59 -0
  3. tests/test_cli.py +131 -0
  4. tests/test_cuda.py +216 -0
  5. tests/test_engine.py +157 -0
  6. tests/test_exports.py +309 -0
  7. tests/test_integrations.py +151 -0
  8. tests/test_python.py +777 -0
  9. tests/test_solutions.py +371 -0
  10. ultralytics/__init__.py +48 -0
  11. ultralytics/assets/bus.jpg +0 -0
  12. ultralytics/assets/zidane.jpg +0 -0
  13. ultralytics/cfg/__init__.py +1026 -0
  14. ultralytics/cfg/datasets/Argoverse.yaml +78 -0
  15. ultralytics/cfg/datasets/DOTAv1.5.yaml +37 -0
  16. ultralytics/cfg/datasets/DOTAv1.yaml +36 -0
  17. ultralytics/cfg/datasets/GlobalWheat2020.yaml +68 -0
  18. ultralytics/cfg/datasets/HomeObjects-3K.yaml +32 -0
  19. ultralytics/cfg/datasets/ImageNet.yaml +2025 -0
  20. ultralytics/cfg/datasets/Objects365.yaml +447 -0
  21. ultralytics/cfg/datasets/SKU-110K.yaml +58 -0
  22. ultralytics/cfg/datasets/VOC.yaml +102 -0
  23. ultralytics/cfg/datasets/VisDrone.yaml +87 -0
  24. ultralytics/cfg/datasets/african-wildlife.yaml +25 -0
  25. ultralytics/cfg/datasets/brain-tumor.yaml +22 -0
  26. ultralytics/cfg/datasets/carparts-seg.yaml +44 -0
  27. ultralytics/cfg/datasets/coco-pose.yaml +64 -0
  28. ultralytics/cfg/datasets/coco.yaml +118 -0
  29. ultralytics/cfg/datasets/coco128-seg.yaml +101 -0
  30. ultralytics/cfg/datasets/coco128.yaml +101 -0
  31. ultralytics/cfg/datasets/coco8-grayscale.yaml +103 -0
  32. ultralytics/cfg/datasets/coco8-multispectral.yaml +104 -0
  33. ultralytics/cfg/datasets/coco8-pose.yaml +47 -0
  34. ultralytics/cfg/datasets/coco8-seg.yaml +101 -0
  35. ultralytics/cfg/datasets/coco8.yaml +101 -0
  36. ultralytics/cfg/datasets/construction-ppe.yaml +32 -0
  37. ultralytics/cfg/datasets/crack-seg.yaml +22 -0
  38. ultralytics/cfg/datasets/dog-pose.yaml +52 -0
  39. ultralytics/cfg/datasets/dota8-multispectral.yaml +38 -0
  40. ultralytics/cfg/datasets/dota8.yaml +35 -0
  41. ultralytics/cfg/datasets/hand-keypoints.yaml +50 -0
  42. ultralytics/cfg/datasets/kitti.yaml +27 -0
  43. ultralytics/cfg/datasets/lvis.yaml +1240 -0
  44. ultralytics/cfg/datasets/medical-pills.yaml +21 -0
  45. ultralytics/cfg/datasets/open-images-v7.yaml +663 -0
  46. ultralytics/cfg/datasets/package-seg.yaml +22 -0
  47. ultralytics/cfg/datasets/signature.yaml +21 -0
  48. ultralytics/cfg/datasets/tiger-pose.yaml +41 -0
  49. ultralytics/cfg/datasets/xView.yaml +155 -0
  50. ultralytics/cfg/default.yaml +130 -0
  51. ultralytics/cfg/models/11/yolo11-cls-resnet18.yaml +17 -0
  52. ultralytics/cfg/models/11/yolo11-cls.yaml +33 -0
  53. ultralytics/cfg/models/11/yolo11-obb.yaml +50 -0
  54. ultralytics/cfg/models/11/yolo11-pose.yaml +51 -0
  55. ultralytics/cfg/models/11/yolo11-seg.yaml +50 -0
  56. ultralytics/cfg/models/11/yolo11.yaml +50 -0
  57. ultralytics/cfg/models/11/yoloe-11-seg.yaml +48 -0
  58. ultralytics/cfg/models/11/yoloe-11.yaml +48 -0
  59. ultralytics/cfg/models/12/yolo12-cls.yaml +32 -0
  60. ultralytics/cfg/models/12/yolo12-obb.yaml +48 -0
  61. ultralytics/cfg/models/12/yolo12-pose.yaml +49 -0
  62. ultralytics/cfg/models/12/yolo12-seg.yaml +48 -0
  63. ultralytics/cfg/models/12/yolo12.yaml +48 -0
  64. ultralytics/cfg/models/rt-detr/rtdetr-l.yaml +53 -0
  65. ultralytics/cfg/models/rt-detr/rtdetr-resnet101.yaml +45 -0
  66. ultralytics/cfg/models/rt-detr/rtdetr-resnet50.yaml +45 -0
  67. ultralytics/cfg/models/rt-detr/rtdetr-x.yaml +57 -0
  68. ultralytics/cfg/models/v10/yolov10b.yaml +45 -0
  69. ultralytics/cfg/models/v10/yolov10l.yaml +45 -0
  70. ultralytics/cfg/models/v10/yolov10m.yaml +45 -0
  71. ultralytics/cfg/models/v10/yolov10n.yaml +45 -0
  72. ultralytics/cfg/models/v10/yolov10s.yaml +45 -0
  73. ultralytics/cfg/models/v10/yolov10x.yaml +45 -0
  74. ultralytics/cfg/models/v3/yolov3-spp.yaml +49 -0
  75. ultralytics/cfg/models/v3/yolov3-tiny.yaml +40 -0
  76. ultralytics/cfg/models/v3/yolov3.yaml +49 -0
  77. ultralytics/cfg/models/v5/yolov5-p6.yaml +62 -0
  78. ultralytics/cfg/models/v5/yolov5.yaml +51 -0
  79. ultralytics/cfg/models/v6/yolov6.yaml +56 -0
  80. ultralytics/cfg/models/v8/yoloe-v8-seg.yaml +48 -0
  81. ultralytics/cfg/models/v8/yoloe-v8.yaml +48 -0
  82. ultralytics/cfg/models/v8/yolov8-cls-resnet101.yaml +28 -0
  83. ultralytics/cfg/models/v8/yolov8-cls-resnet50.yaml +28 -0
  84. ultralytics/cfg/models/v8/yolov8-cls.yaml +32 -0
  85. ultralytics/cfg/models/v8/yolov8-ghost-p2.yaml +58 -0
  86. ultralytics/cfg/models/v8/yolov8-ghost-p6.yaml +60 -0
  87. ultralytics/cfg/models/v8/yolov8-ghost.yaml +50 -0
  88. ultralytics/cfg/models/v8/yolov8-obb.yaml +49 -0
  89. ultralytics/cfg/models/v8/yolov8-p2.yaml +57 -0
  90. ultralytics/cfg/models/v8/yolov8-p6.yaml +59 -0
  91. ultralytics/cfg/models/v8/yolov8-pose-p6.yaml +60 -0
  92. ultralytics/cfg/models/v8/yolov8-pose.yaml +50 -0
  93. ultralytics/cfg/models/v8/yolov8-rtdetr.yaml +49 -0
  94. ultralytics/cfg/models/v8/yolov8-seg-p6.yaml +59 -0
  95. ultralytics/cfg/models/v8/yolov8-seg.yaml +49 -0
  96. ultralytics/cfg/models/v8/yolov8-world.yaml +51 -0
  97. ultralytics/cfg/models/v8/yolov8-worldv2.yaml +49 -0
  98. ultralytics/cfg/models/v8/yolov8.yaml +49 -0
  99. ultralytics/cfg/models/v9/yolov9c-seg.yaml +41 -0
  100. ultralytics/cfg/models/v9/yolov9c.yaml +41 -0
  101. ultralytics/cfg/models/v9/yolov9e-seg.yaml +64 -0
  102. ultralytics/cfg/models/v9/yolov9e.yaml +64 -0
  103. ultralytics/cfg/models/v9/yolov9m.yaml +41 -0
  104. ultralytics/cfg/models/v9/yolov9s.yaml +41 -0
  105. ultralytics/cfg/models/v9/yolov9t.yaml +41 -0
  106. ultralytics/cfg/trackers/botsort.yaml +21 -0
  107. ultralytics/cfg/trackers/bytetrack.yaml +12 -0
  108. ultralytics/data/__init__.py +26 -0
  109. ultralytics/data/annotator.py +66 -0
  110. ultralytics/data/augment.py +2801 -0
  111. ultralytics/data/base.py +435 -0
  112. ultralytics/data/build.py +437 -0
  113. ultralytics/data/converter.py +855 -0
  114. ultralytics/data/dataset.py +834 -0
  115. ultralytics/data/loaders.py +704 -0
  116. ultralytics/data/scripts/download_weights.sh +18 -0
  117. ultralytics/data/scripts/get_coco.sh +61 -0
  118. ultralytics/data/scripts/get_coco128.sh +18 -0
  119. ultralytics/data/scripts/get_imagenet.sh +52 -0
  120. ultralytics/data/split.py +138 -0
  121. ultralytics/data/split_dota.py +344 -0
  122. ultralytics/data/utils.py +798 -0
  123. ultralytics/engine/__init__.py +1 -0
  124. ultralytics/engine/exporter.py +1574 -0
  125. ultralytics/engine/model.py +1124 -0
  126. ultralytics/engine/predictor.py +508 -0
  127. ultralytics/engine/results.py +1522 -0
  128. ultralytics/engine/trainer.py +974 -0
  129. ultralytics/engine/tuner.py +448 -0
  130. ultralytics/engine/validator.py +384 -0
  131. ultralytics/hub/__init__.py +166 -0
  132. ultralytics/hub/auth.py +151 -0
  133. ultralytics/hub/google/__init__.py +174 -0
  134. ultralytics/hub/session.py +422 -0
  135. ultralytics/hub/utils.py +162 -0
  136. ultralytics/models/__init__.py +9 -0
  137. ultralytics/models/fastsam/__init__.py +7 -0
  138. ultralytics/models/fastsam/model.py +79 -0
  139. ultralytics/models/fastsam/predict.py +169 -0
  140. ultralytics/models/fastsam/utils.py +23 -0
  141. ultralytics/models/fastsam/val.py +38 -0
  142. ultralytics/models/nas/__init__.py +7 -0
  143. ultralytics/models/nas/model.py +98 -0
  144. ultralytics/models/nas/predict.py +56 -0
  145. ultralytics/models/nas/val.py +38 -0
  146. ultralytics/models/rtdetr/__init__.py +7 -0
  147. ultralytics/models/rtdetr/model.py +63 -0
  148. ultralytics/models/rtdetr/predict.py +88 -0
  149. ultralytics/models/rtdetr/train.py +89 -0
  150. ultralytics/models/rtdetr/val.py +216 -0
  151. ultralytics/models/sam/__init__.py +25 -0
  152. ultralytics/models/sam/amg.py +275 -0
  153. ultralytics/models/sam/build.py +365 -0
  154. ultralytics/models/sam/build_sam3.py +377 -0
  155. ultralytics/models/sam/model.py +169 -0
  156. ultralytics/models/sam/modules/__init__.py +1 -0
  157. ultralytics/models/sam/modules/blocks.py +1067 -0
  158. ultralytics/models/sam/modules/decoders.py +495 -0
  159. ultralytics/models/sam/modules/encoders.py +794 -0
  160. ultralytics/models/sam/modules/memory_attention.py +298 -0
  161. ultralytics/models/sam/modules/sam.py +1160 -0
  162. ultralytics/models/sam/modules/tiny_encoder.py +979 -0
  163. ultralytics/models/sam/modules/transformer.py +344 -0
  164. ultralytics/models/sam/modules/utils.py +512 -0
  165. ultralytics/models/sam/predict.py +3940 -0
  166. ultralytics/models/sam/sam3/__init__.py +3 -0
  167. ultralytics/models/sam/sam3/decoder.py +546 -0
  168. ultralytics/models/sam/sam3/encoder.py +529 -0
  169. ultralytics/models/sam/sam3/geometry_encoders.py +415 -0
  170. ultralytics/models/sam/sam3/maskformer_segmentation.py +286 -0
  171. ultralytics/models/sam/sam3/model_misc.py +199 -0
  172. ultralytics/models/sam/sam3/necks.py +129 -0
  173. ultralytics/models/sam/sam3/sam3_image.py +339 -0
  174. ultralytics/models/sam/sam3/text_encoder_ve.py +307 -0
  175. ultralytics/models/sam/sam3/vitdet.py +547 -0
  176. ultralytics/models/sam/sam3/vl_combiner.py +160 -0
  177. ultralytics/models/utils/__init__.py +1 -0
  178. ultralytics/models/utils/loss.py +466 -0
  179. ultralytics/models/utils/ops.py +315 -0
  180. ultralytics/models/yolo/__init__.py +7 -0
  181. ultralytics/models/yolo/classify/__init__.py +7 -0
  182. ultralytics/models/yolo/classify/predict.py +90 -0
  183. ultralytics/models/yolo/classify/train.py +202 -0
  184. ultralytics/models/yolo/classify/val.py +216 -0
  185. ultralytics/models/yolo/detect/__init__.py +7 -0
  186. ultralytics/models/yolo/detect/predict.py +122 -0
  187. ultralytics/models/yolo/detect/train.py +227 -0
  188. ultralytics/models/yolo/detect/val.py +507 -0
  189. ultralytics/models/yolo/model.py +430 -0
  190. ultralytics/models/yolo/obb/__init__.py +7 -0
  191. ultralytics/models/yolo/obb/predict.py +56 -0
  192. ultralytics/models/yolo/obb/train.py +79 -0
  193. ultralytics/models/yolo/obb/val.py +302 -0
  194. ultralytics/models/yolo/pose/__init__.py +7 -0
  195. ultralytics/models/yolo/pose/predict.py +65 -0
  196. ultralytics/models/yolo/pose/train.py +110 -0
  197. ultralytics/models/yolo/pose/val.py +248 -0
  198. ultralytics/models/yolo/segment/__init__.py +7 -0
  199. ultralytics/models/yolo/segment/predict.py +109 -0
  200. ultralytics/models/yolo/segment/train.py +69 -0
  201. ultralytics/models/yolo/segment/val.py +307 -0
  202. ultralytics/models/yolo/world/__init__.py +5 -0
  203. ultralytics/models/yolo/world/train.py +173 -0
  204. ultralytics/models/yolo/world/train_world.py +178 -0
  205. ultralytics/models/yolo/yoloe/__init__.py +22 -0
  206. ultralytics/models/yolo/yoloe/predict.py +162 -0
  207. ultralytics/models/yolo/yoloe/train.py +287 -0
  208. ultralytics/models/yolo/yoloe/train_seg.py +122 -0
  209. ultralytics/models/yolo/yoloe/val.py +206 -0
  210. ultralytics/nn/__init__.py +27 -0
  211. ultralytics/nn/autobackend.py +958 -0
  212. ultralytics/nn/modules/__init__.py +182 -0
  213. ultralytics/nn/modules/activation.py +54 -0
  214. ultralytics/nn/modules/block.py +1947 -0
  215. ultralytics/nn/modules/conv.py +669 -0
  216. ultralytics/nn/modules/head.py +1183 -0
  217. ultralytics/nn/modules/transformer.py +793 -0
  218. ultralytics/nn/modules/utils.py +159 -0
  219. ultralytics/nn/tasks.py +1768 -0
  220. ultralytics/nn/text_model.py +356 -0
  221. ultralytics/py.typed +1 -0
  222. ultralytics/solutions/__init__.py +41 -0
  223. ultralytics/solutions/ai_gym.py +108 -0
  224. ultralytics/solutions/analytics.py +264 -0
  225. ultralytics/solutions/config.py +107 -0
  226. ultralytics/solutions/distance_calculation.py +123 -0
  227. ultralytics/solutions/heatmap.py +125 -0
  228. ultralytics/solutions/instance_segmentation.py +86 -0
  229. ultralytics/solutions/object_blurrer.py +89 -0
  230. ultralytics/solutions/object_counter.py +190 -0
  231. ultralytics/solutions/object_cropper.py +87 -0
  232. ultralytics/solutions/parking_management.py +280 -0
  233. ultralytics/solutions/queue_management.py +93 -0
  234. ultralytics/solutions/region_counter.py +133 -0
  235. ultralytics/solutions/security_alarm.py +151 -0
  236. ultralytics/solutions/similarity_search.py +219 -0
  237. ultralytics/solutions/solutions.py +828 -0
  238. ultralytics/solutions/speed_estimation.py +114 -0
  239. ultralytics/solutions/streamlit_inference.py +260 -0
  240. ultralytics/solutions/templates/similarity-search.html +156 -0
  241. ultralytics/solutions/trackzone.py +88 -0
  242. ultralytics/solutions/vision_eye.py +67 -0
  243. ultralytics/trackers/__init__.py +7 -0
  244. ultralytics/trackers/basetrack.py +115 -0
  245. ultralytics/trackers/bot_sort.py +257 -0
  246. ultralytics/trackers/byte_tracker.py +469 -0
  247. ultralytics/trackers/track.py +116 -0
  248. ultralytics/trackers/utils/__init__.py +1 -0
  249. ultralytics/trackers/utils/gmc.py +339 -0
  250. ultralytics/trackers/utils/kalman_filter.py +482 -0
  251. ultralytics/trackers/utils/matching.py +154 -0
  252. ultralytics/utils/__init__.py +1450 -0
  253. ultralytics/utils/autobatch.py +118 -0
  254. ultralytics/utils/autodevice.py +205 -0
  255. ultralytics/utils/benchmarks.py +728 -0
  256. ultralytics/utils/callbacks/__init__.py +5 -0
  257. ultralytics/utils/callbacks/base.py +233 -0
  258. ultralytics/utils/callbacks/clearml.py +146 -0
  259. ultralytics/utils/callbacks/comet.py +625 -0
  260. ultralytics/utils/callbacks/dvc.py +197 -0
  261. ultralytics/utils/callbacks/hub.py +110 -0
  262. ultralytics/utils/callbacks/mlflow.py +134 -0
  263. ultralytics/utils/callbacks/neptune.py +126 -0
  264. ultralytics/utils/callbacks/platform.py +73 -0
  265. ultralytics/utils/callbacks/raytune.py +42 -0
  266. ultralytics/utils/callbacks/tensorboard.py +123 -0
  267. ultralytics/utils/callbacks/wb.py +188 -0
  268. ultralytics/utils/checks.py +998 -0
  269. ultralytics/utils/cpu.py +85 -0
  270. ultralytics/utils/dist.py +123 -0
  271. ultralytics/utils/downloads.py +529 -0
  272. ultralytics/utils/errors.py +35 -0
  273. ultralytics/utils/events.py +113 -0
  274. ultralytics/utils/export/__init__.py +7 -0
  275. ultralytics/utils/export/engine.py +237 -0
  276. ultralytics/utils/export/imx.py +315 -0
  277. ultralytics/utils/export/tensorflow.py +231 -0
  278. ultralytics/utils/files.py +219 -0
  279. ultralytics/utils/git.py +137 -0
  280. ultralytics/utils/instance.py +484 -0
  281. ultralytics/utils/logger.py +444 -0
  282. ultralytics/utils/loss.py +849 -0
  283. ultralytics/utils/metrics.py +1560 -0
  284. ultralytics/utils/nms.py +337 -0
  285. ultralytics/utils/ops.py +664 -0
  286. ultralytics/utils/patches.py +201 -0
  287. ultralytics/utils/plotting.py +1045 -0
  288. ultralytics/utils/tal.py +403 -0
  289. ultralytics/utils/torch_utils.py +984 -0
  290. ultralytics/utils/tqdm.py +440 -0
  291. ultralytics/utils/triton.py +112 -0
  292. ultralytics/utils/tuner.py +160 -0
  293. ultralytics_opencv_headless-8.3.242.dist-info/METADATA +374 -0
  294. ultralytics_opencv_headless-8.3.242.dist-info/RECORD +298 -0
  295. ultralytics_opencv_headless-8.3.242.dist-info/WHEEL +5 -0
  296. ultralytics_opencv_headless-8.3.242.dist-info/entry_points.txt +3 -0
  297. ultralytics_opencv_headless-8.3.242.dist-info/licenses/LICENSE +661 -0
  298. ultralytics_opencv_headless-8.3.242.dist-info/top_level.txt +1 -0
@@ -0,0 +1,18 @@
1
+ #!/bin/bash
2
+ # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
3
+
4
+ # Download latest models from https://github.com/ultralytics/assets/releases
5
+ # Example usage: bash ultralytics/data/scripts/download_weights.sh
6
+ # parent
7
+ # └── weights
8
+ # ├── yolov8n.pt ← downloads here
9
+ # ├── yolov8s.pt
10
+ # └── ...
11
+
12
+ python << EOF
13
+ from ultralytics.utils.downloads import attempt_download_asset
14
+
15
+ assets = [f"yolov8{size}{suffix}.pt" for size in "nsmlx" for suffix in ("", "-cls", "-seg", "-pose")]
16
+ for x in assets:
17
+ attempt_download_asset(f"weights/{x}")
18
+ EOF
@@ -0,0 +1,61 @@
1
+ #!/bin/bash
2
+ # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
3
+
4
+ # Download COCO 2017 dataset https://cocodataset.org
5
+ # Example usage: bash data/scripts/get_coco.sh
6
+ # parent
7
+ # ├── ultralytics
8
+ # └── datasets
9
+ # └── coco ← downloads here
10
+
11
+ # Arguments (optional) Usage: bash data/scripts/get_coco.sh --train --val --test --segments
12
+ if [ "$#" -gt 0 ]; then
13
+ for opt in "$@"; do
14
+ case "${opt}" in
15
+ --train) train=true ;;
16
+ --val) val=true ;;
17
+ --test) test=true ;;
18
+ --segments) segments=true ;;
19
+ --sama) sama=true ;;
20
+ esac
21
+ done
22
+ else
23
+ train=true
24
+ val=true
25
+ test=false
26
+ segments=false
27
+ sama=false
28
+ fi
29
+
30
+ # Download/unzip labels
31
+ d='../datasets' # unzip directory
32
+ url=https://github.com/ultralytics/assets/releases/download/v0.0.0/
33
+ if [ "$segments" == "true" ]; then
34
+ f='coco2017labels-segments.zip' # 169 MB
35
+ elif [ "$sama" == "true" ]; then
36
+ f='coco2017labels-segments-sama.zip' # 199 MB https://www.sama.com/sama-coco-dataset/
37
+ else
38
+ f='coco2017labels.zip' # 46 MB
39
+ fi
40
+ echo 'Downloading' $url$f ' ...'
41
+ curl -L $url$f -o $f -# && unzip -q $f -d $d && rm $f &
42
+
43
+ # Download/unzip images
44
+ d='../datasets/coco/images' # unzip directory
45
+ url=http://images.cocodataset.org/zips/
46
+ if [ "$train" == "true" ]; then
47
+ f='train2017.zip' # 19G, 118k images
48
+ echo 'Downloading' $url$f '...'
49
+ curl -L $url$f -o $f -# && unzip -q $f -d $d && rm $f &
50
+ fi
51
+ if [ "$val" == "true" ]; then
52
+ f='val2017.zip' # 1G, 5k images
53
+ echo 'Downloading' $url$f '...'
54
+ curl -L $url$f -o $f -# && unzip -q $f -d $d && rm $f &
55
+ fi
56
+ if [ "$test" == "true" ]; then
57
+ f='test2017.zip' # 7G, 41k images (optional)
58
+ echo 'Downloading' $url$f '...'
59
+ curl -L $url$f -o $f -# && unzip -q $f -d $d && rm $f &
60
+ fi
61
+ wait # finish background tasks
@@ -0,0 +1,18 @@
1
+ #!/bin/bash
2
+ # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
3
+
4
+ # Download COCO128 dataset https://www.kaggle.com/ultralytics/coco128 (first 128 images from COCO train2017)
5
+ # Example usage: bash data/scripts/get_coco128.sh
6
+ # parent
7
+ # ├── ultralytics
8
+ # └── datasets
9
+ # └── coco128 ← downloads here
10
+
11
+ # Download/unzip images and labels
12
+ d='../datasets' # unzip directory
13
+ url=https://github.com/ultralytics/assets/releases/download/v0.0.0/
14
+ f='coco128.zip' # or 'coco128-segments.zip', 68 MB
15
+ echo 'Downloading' $url$f ' ...'
16
+ curl -L $url$f -o $f -# && unzip -q $f -d $d && rm $f &
17
+
18
+ wait # finish background tasks
@@ -0,0 +1,52 @@
1
+ #!/bin/bash
2
+ # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
3
+
4
+ # Download ILSVRC2012 ImageNet dataset https://image-net.org
5
+ # Example usage: bash data/scripts/get_imagenet.sh
6
+ # parent
7
+ # ├── ultralytics
8
+ # └── datasets
9
+ # └── imagenet ← downloads here
10
+
11
+ # Arguments (optional) Usage: bash data/scripts/get_imagenet.sh --train --val
12
+ if [ "$#" -gt 0 ]; then
13
+ for opt in "$@"; do
14
+ case "${opt}" in
15
+ --train) train=true ;;
16
+ --val) val=true ;;
17
+ esac
18
+ done
19
+ else
20
+ train=true
21
+ val=true
22
+ fi
23
+
24
+ # Make dir
25
+ d='../datasets/imagenet' # unzip directory
26
+ mkdir -p $d && cd $d
27
+
28
+ # Download/unzip train
29
+ if [ "$train" == "true" ]; then
30
+ wget https://image-net.org/data/ILSVRC/2012/ILSVRC2012_img_train.tar # download 138G, 1281167 images
31
+ mkdir train && mv ILSVRC2012_img_train.tar train/ && cd train
32
+ tar -xf ILSVRC2012_img_train.tar && rm -f ILSVRC2012_img_train.tar
33
+ find . -name "*.tar" | while read NAME; do
34
+ mkdir -p "${NAME%.tar}"
35
+ tar -xf "${NAME}" -C "${NAME%.tar}"
36
+ rm -f "${NAME}"
37
+ done
38
+ cd ..
39
+ fi
40
+
41
+ # Download/unzip val
42
+ if [ "$val" == "true" ]; then
43
+ wget https://image-net.org/data/ILSVRC/2012/ILSVRC2012_img_val.tar # download 6.3G, 50000 images
44
+ mkdir val && mv ILSVRC2012_img_val.tar val/ && cd val && tar -xf ILSVRC2012_img_val.tar
45
+ wget -qO- https://raw.githubusercontent.com/soumith/imagenetloader.torch/master/valprep.sh | bash # move into subdirs
46
+ fi
47
+
48
+ # Delete corrupted image (optional: PNG under JPEG name that may cause dataloaders to fail)
49
+ # rm train/n04266014/n04266014_10835.JPEG
50
+
51
+ # TFRecords (optional)
52
+ # wget https://raw.githubusercontent.com/tensorflow/models/master/research/slim/datasets/imagenet_lsvrc_2015_synsets.txt
@@ -0,0 +1,138 @@
1
+ # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2
+
3
+ from __future__ import annotations
4
+
5
+ import random
6
+ import shutil
7
+ from pathlib import Path
8
+
9
+ from ultralytics.data.utils import IMG_FORMATS, img2label_paths
10
+ from ultralytics.utils import DATASETS_DIR, LOGGER, TQDM
11
+
12
+
13
+ def split_classify_dataset(source_dir: str | Path, train_ratio: float = 0.8) -> Path:
14
+ """Split classification dataset into train and val directories in a new directory.
15
+
16
+ Creates a new directory '{source_dir}_split' with train/val subdirectories, preserving the original class structure
17
+ with an 80/20 split by default.
18
+
19
+ Directory structure:
20
+ Before:
21
+ caltech/
22
+ ├── class1/
23
+ │ ├── img1.jpg
24
+ │ ├── img2.jpg
25
+ │ └── ...
26
+ ├── class2/
27
+ │ ├── img1.jpg
28
+ │ └── ...
29
+ └── ...
30
+
31
+ After:
32
+ caltech_split/
33
+ ├── train/
34
+ │ ├── class1/
35
+ │ │ ├── img1.jpg
36
+ │ │ └── ...
37
+ │ ├── class2/
38
+ │ │ ├── img1.jpg
39
+ │ │ └── ...
40
+ │ └── ...
41
+ └── val/
42
+ ├── class1/
43
+ │ ├── img2.jpg
44
+ │ └── ...
45
+ ├── class2/
46
+ │ └── ...
47
+ └── ...
48
+
49
+ Args:
50
+ source_dir (str | Path): Path to classification dataset root directory.
51
+ train_ratio (float): Ratio for train split, between 0 and 1.
52
+
53
+ Returns:
54
+ (Path): Path to the created split directory.
55
+
56
+ Examples:
57
+ Split dataset with default 80/20 ratio
58
+ >>> split_classify_dataset("path/to/caltech")
59
+
60
+ Split with custom ratio
61
+ >>> split_classify_dataset("path/to/caltech", 0.75)
62
+ """
63
+ source_path = Path(source_dir)
64
+ split_path = Path(f"{source_path}_split")
65
+ train_path, val_path = split_path / "train", split_path / "val"
66
+
67
+ # Create directory structure
68
+ split_path.mkdir(exist_ok=True)
69
+ train_path.mkdir(exist_ok=True)
70
+ val_path.mkdir(exist_ok=True)
71
+
72
+ # Process class directories
73
+ class_dirs = [d for d in source_path.iterdir() if d.is_dir()]
74
+ total_images = sum(len(list(d.glob("*.*"))) for d in class_dirs)
75
+ stats = f"{len(class_dirs)} classes, {total_images} images"
76
+ LOGGER.info(f"Splitting {source_path} ({stats}) into {train_ratio:.0%} train, {1 - train_ratio:.0%} val...")
77
+
78
+ for class_dir in class_dirs:
79
+ # Create class directories
80
+ (train_path / class_dir.name).mkdir(exist_ok=True)
81
+ (val_path / class_dir.name).mkdir(exist_ok=True)
82
+
83
+ # Split and copy files
84
+ image_files = list(class_dir.glob("*.*"))
85
+ random.shuffle(image_files)
86
+ split_idx = int(len(image_files) * train_ratio)
87
+
88
+ for img in image_files[:split_idx]:
89
+ shutil.copy2(img, train_path / class_dir.name / img.name)
90
+
91
+ for img in image_files[split_idx:]:
92
+ shutil.copy2(img, val_path / class_dir.name / img.name)
93
+
94
+ LOGGER.info(f"Split complete in {split_path} ✅")
95
+ return split_path
96
+
97
+
98
+ def autosplit(
99
+ path: Path = DATASETS_DIR / "coco8/images",
100
+ weights: tuple[float, float, float] = (0.9, 0.1, 0.0),
101
+ annotated_only: bool = False,
102
+ ) -> None:
103
+ """Automatically split a dataset into train/val/test splits and save the resulting splits into autosplit_*.txt
104
+ files.
105
+
106
+ Args:
107
+ path (Path): Path to images directory.
108
+ weights (tuple): Train, validation, and test split fractions.
109
+ annotated_only (bool): If True, only images with an associated txt file are used.
110
+
111
+ Examples:
112
+ Split images with default weights
113
+ >>> from ultralytics.data.split import autosplit
114
+ >>> autosplit()
115
+
116
+ Split with custom weights and annotated images only
117
+ >>> autosplit(path="path/to/images", weights=(0.8, 0.15, 0.05), annotated_only=True)
118
+ """
119
+ path = Path(path) # images dir
120
+ files = sorted(x for x in path.rglob("*.*") if x.suffix[1:].lower() in IMG_FORMATS) # image files only
121
+ n = len(files) # number of files
122
+ random.seed(0) # for reproducibility
123
+ indices = random.choices([0, 1, 2], weights=weights, k=n) # assign each image to a split
124
+
125
+ txt = ["autosplit_train.txt", "autosplit_val.txt", "autosplit_test.txt"] # 3 txt files
126
+ for x in txt:
127
+ if (path.parent / x).exists():
128
+ (path.parent / x).unlink() # remove existing
129
+
130
+ LOGGER.info(f"Autosplitting images from {path}" + ", using *.txt labeled images only" * annotated_only)
131
+ for i, img in TQDM(zip(indices, files), total=n):
132
+ if not annotated_only or Path(img2label_paths([str(img)])[0]).exists(): # check label
133
+ with open(path.parent / txt[i], "a", encoding="utf-8") as f:
134
+ f.write(f"./{img.relative_to(path.parent).as_posix()}" + "\n") # add image to txt file
135
+
136
+
137
+ if __name__ == "__main__":
138
+ split_classify_dataset("caltech101")
@@ -0,0 +1,344 @@
1
+ # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2
+
3
+ from __future__ import annotations
4
+
5
+ import itertools
6
+ from glob import glob
7
+ from math import ceil
8
+ from pathlib import Path
9
+ from typing import Any
10
+
11
+ import cv2
12
+ import numpy as np
13
+ from PIL import Image
14
+
15
+ from ultralytics.data.utils import exif_size, img2label_paths
16
+ from ultralytics.utils import TQDM
17
+ from ultralytics.utils.checks import check_requirements
18
+
19
+
20
+ def bbox_iof(polygon1: np.ndarray, bbox2: np.ndarray, eps: float = 1e-6) -> np.ndarray:
21
+ """Calculate Intersection over Foreground (IoF) between polygons and bounding boxes.
22
+
23
+ Args:
24
+ polygon1 (np.ndarray): Polygon coordinates with shape (N, 8).
25
+ bbox2 (np.ndarray): Bounding boxes with shape (N, 4).
26
+ eps (float, optional): Small value to prevent division by zero.
27
+
28
+ Returns:
29
+ (np.ndarray): IoF scores with shape (N, 1) or (N, M) if bbox2 is (M, 4).
30
+
31
+ Notes:
32
+ Polygon format: [x1, y1, x2, y2, x3, y3, x4, y4].
33
+ Bounding box format: [x_min, y_min, x_max, y_max].
34
+ """
35
+ check_requirements("shapely>=2.0.0")
36
+ from shapely.geometry import Polygon
37
+
38
+ polygon1 = polygon1.reshape(-1, 4, 2)
39
+ lt_point = np.min(polygon1, axis=-2) # left-top
40
+ rb_point = np.max(polygon1, axis=-2) # right-bottom
41
+ bbox1 = np.concatenate([lt_point, rb_point], axis=-1)
42
+
43
+ lt = np.maximum(bbox1[:, None, :2], bbox2[..., :2])
44
+ rb = np.minimum(bbox1[:, None, 2:], bbox2[..., 2:])
45
+ wh = np.clip(rb - lt, 0, np.inf)
46
+ h_overlaps = wh[..., 0] * wh[..., 1]
47
+
48
+ left, top, right, bottom = (bbox2[..., i] for i in range(4))
49
+ polygon2 = np.stack([left, top, right, top, right, bottom, left, bottom], axis=-1).reshape(-1, 4, 2)
50
+
51
+ sg_polys1 = [Polygon(p) for p in polygon1]
52
+ sg_polys2 = [Polygon(p) for p in polygon2]
53
+ overlaps = np.zeros(h_overlaps.shape)
54
+ for p in zip(*np.nonzero(h_overlaps)):
55
+ overlaps[p] = sg_polys1[p[0]].intersection(sg_polys2[p[-1]]).area
56
+ unions = np.array([p.area for p in sg_polys1], dtype=np.float32)
57
+ unions = unions[..., None]
58
+
59
+ unions = np.clip(unions, eps, np.inf)
60
+ outputs = overlaps / unions
61
+ if outputs.ndim == 1:
62
+ outputs = outputs[..., None]
63
+ return outputs
64
+
65
+
66
+ def load_yolo_dota(data_root: str, split: str = "train") -> list[dict[str, Any]]:
67
+ """Load DOTA dataset annotations and image information.
68
+
69
+ Args:
70
+ data_root (str): Data root directory.
71
+ split (str, optional): The split data set, could be 'train' or 'val'.
72
+
73
+ Returns:
74
+ (list[dict[str, Any]]): List of annotation dictionaries containing image information.
75
+
76
+ Notes:
77
+ The directory structure assumed for the DOTA dataset:
78
+ - data_root
79
+ - images
80
+ - train
81
+ - val
82
+ - labels
83
+ - train
84
+ - val
85
+ """
86
+ assert split in {"train", "val"}, f"Split must be 'train' or 'val', not {split}."
87
+ im_dir = Path(data_root) / "images" / split
88
+ assert im_dir.exists(), f"Can't find {im_dir}, please check your data root."
89
+ im_files = glob(str(Path(data_root) / "images" / split / "*"))
90
+ lb_files = img2label_paths(im_files)
91
+ annos = []
92
+ for im_file, lb_file in zip(im_files, lb_files):
93
+ w, h = exif_size(Image.open(im_file))
94
+ with open(lb_file, encoding="utf-8") as f:
95
+ lb = [x.split() for x in f.read().strip().splitlines() if len(x)]
96
+ lb = np.array(lb, dtype=np.float32)
97
+ annos.append(dict(ori_size=(h, w), label=lb, filepath=im_file))
98
+ return annos
99
+
100
+
101
+ def get_windows(
102
+ im_size: tuple[int, int],
103
+ crop_sizes: tuple[int, ...] = (1024,),
104
+ gaps: tuple[int, ...] = (200,),
105
+ im_rate_thr: float = 0.6,
106
+ eps: float = 0.01,
107
+ ) -> np.ndarray:
108
+ """Get the coordinates of sliding windows for image cropping.
109
+
110
+ Args:
111
+ im_size (tuple[int, int]): Original image size, (H, W).
112
+ crop_sizes (tuple[int, ...], optional): Crop size of windows.
113
+ gaps (tuple[int, ...], optional): Gap between crops.
114
+ im_rate_thr (float, optional): Threshold of windows areas divided by image areas.
115
+ eps (float, optional): Epsilon value for math operations.
116
+
117
+ Returns:
118
+ (np.ndarray): Array of window coordinates of shape (N, 4) where each row is [x_start, y_start, x_stop, y_stop].
119
+ """
120
+ h, w = im_size
121
+ windows = []
122
+ for crop_size, gap in zip(crop_sizes, gaps):
123
+ assert crop_size > gap, f"invalid crop_size gap pair [{crop_size} {gap}]"
124
+ step = crop_size - gap
125
+
126
+ xn = 1 if w <= crop_size else ceil((w - crop_size) / step + 1)
127
+ xs = [step * i for i in range(xn)]
128
+ if len(xs) > 1 and xs[-1] + crop_size > w:
129
+ xs[-1] = w - crop_size
130
+
131
+ yn = 1 if h <= crop_size else ceil((h - crop_size) / step + 1)
132
+ ys = [step * i for i in range(yn)]
133
+ if len(ys) > 1 and ys[-1] + crop_size > h:
134
+ ys[-1] = h - crop_size
135
+
136
+ start = np.array(list(itertools.product(xs, ys)), dtype=np.int64)
137
+ stop = start + crop_size
138
+ windows.append(np.concatenate([start, stop], axis=1))
139
+ windows = np.concatenate(windows, axis=0)
140
+
141
+ im_in_wins = windows.copy()
142
+ im_in_wins[:, 0::2] = np.clip(im_in_wins[:, 0::2], 0, w)
143
+ im_in_wins[:, 1::2] = np.clip(im_in_wins[:, 1::2], 0, h)
144
+ im_areas = (im_in_wins[:, 2] - im_in_wins[:, 0]) * (im_in_wins[:, 3] - im_in_wins[:, 1])
145
+ win_areas = (windows[:, 2] - windows[:, 0]) * (windows[:, 3] - windows[:, 1])
146
+ im_rates = im_areas / win_areas
147
+ if not (im_rates > im_rate_thr).any():
148
+ max_rate = im_rates.max()
149
+ im_rates[abs(im_rates - max_rate) < eps] = 1
150
+ return windows[im_rates > im_rate_thr]
151
+
152
+
153
+ def get_window_obj(anno: dict[str, Any], windows: np.ndarray, iof_thr: float = 0.7) -> list[np.ndarray]:
154
+ """Get objects for each window based on IoF threshold."""
155
+ h, w = anno["ori_size"]
156
+ label = anno["label"]
157
+ if len(label):
158
+ label[:, 1::2] *= w
159
+ label[:, 2::2] *= h
160
+ iofs = bbox_iof(label[:, 1:], windows)
161
+ # Unnormalized and misaligned coordinates
162
+ return [(label[iofs[:, i] >= iof_thr]) for i in range(len(windows))] # window_anns
163
+ else:
164
+ return [np.zeros((0, 9), dtype=np.float32) for _ in range(len(windows))] # window_anns
165
+
166
+
167
+ def crop_and_save(
168
+ anno: dict[str, Any],
169
+ windows: np.ndarray,
170
+ window_objs: list[np.ndarray],
171
+ im_dir: str,
172
+ lb_dir: str,
173
+ allow_background_images: bool = True,
174
+ ) -> None:
175
+ """Crop images and save new labels for each window.
176
+
177
+ Args:
178
+ anno (dict[str, Any]): Annotation dict, including 'filepath', 'label', 'ori_size' as its keys.
179
+ windows (np.ndarray): Array of windows coordinates with shape (N, 4).
180
+ window_objs (list[np.ndarray]): A list of labels inside each window.
181
+ im_dir (str): The output directory path of images.
182
+ lb_dir (str): The output directory path of labels.
183
+ allow_background_images (bool, optional): Whether to include background images without labels.
184
+
185
+ Notes:
186
+ The directory structure assumed for the DOTA dataset:
187
+ - data_root
188
+ - images
189
+ - train
190
+ - val
191
+ - labels
192
+ - train
193
+ - val
194
+ """
195
+ im = cv2.imread(anno["filepath"])
196
+ name = Path(anno["filepath"]).stem
197
+ for i, window in enumerate(windows):
198
+ x_start, y_start, x_stop, y_stop = window.tolist()
199
+ new_name = f"{name}__{x_stop - x_start}__{x_start}___{y_start}"
200
+ patch_im = im[y_start:y_stop, x_start:x_stop]
201
+ ph, pw = patch_im.shape[:2]
202
+
203
+ label = window_objs[i]
204
+ if len(label) or allow_background_images:
205
+ cv2.imwrite(str(Path(im_dir) / f"{new_name}.jpg"), patch_im)
206
+ if len(label):
207
+ label[:, 1::2] -= x_start
208
+ label[:, 2::2] -= y_start
209
+ label[:, 1::2] /= pw
210
+ label[:, 2::2] /= ph
211
+
212
+ with open(Path(lb_dir) / f"{new_name}.txt", "w", encoding="utf-8") as f:
213
+ for lb in label:
214
+ formatted_coords = [f"{coord:.6g}" for coord in lb[1:]]
215
+ f.write(f"{int(lb[0])} {' '.join(formatted_coords)}\n")
216
+
217
+
218
+ def split_images_and_labels(
219
+ data_root: str,
220
+ save_dir: str,
221
+ split: str = "train",
222
+ crop_sizes: tuple[int, ...] = (1024,),
223
+ gaps: tuple[int, ...] = (200,),
224
+ ) -> None:
225
+ """Split both images and labels for a given dataset split.
226
+
227
+ Args:
228
+ data_root (str): Root directory of the dataset.
229
+ save_dir (str): Directory to save the split dataset.
230
+ split (str, optional): The split data set, could be 'train' or 'val'.
231
+ crop_sizes (tuple[int, ...], optional): Tuple of crop sizes.
232
+ gaps (tuple[int, ...], optional): Tuple of gaps between crops.
233
+
234
+ Notes:
235
+ The directory structure assumed for the DOTA dataset:
236
+ - data_root
237
+ - images
238
+ - split
239
+ - labels
240
+ - split
241
+ and the output directory structure is:
242
+ - save_dir
243
+ - images
244
+ - split
245
+ - labels
246
+ - split
247
+ """
248
+ im_dir = Path(save_dir) / "images" / split
249
+ im_dir.mkdir(parents=True, exist_ok=True)
250
+ lb_dir = Path(save_dir) / "labels" / split
251
+ lb_dir.mkdir(parents=True, exist_ok=True)
252
+
253
+ annos = load_yolo_dota(data_root, split=split)
254
+ for anno in TQDM(annos, total=len(annos), desc=split):
255
+ windows = get_windows(anno["ori_size"], crop_sizes, gaps)
256
+ window_objs = get_window_obj(anno, windows)
257
+ crop_and_save(anno, windows, window_objs, str(im_dir), str(lb_dir))
258
+
259
+
260
+ def split_trainval(
261
+ data_root: str, save_dir: str, crop_size: int = 1024, gap: int = 200, rates: tuple[float, ...] = (1.0,)
262
+ ) -> None:
263
+ """Split train and val sets of DOTA dataset with multiple scaling rates.
264
+
265
+ Args:
266
+ data_root (str): Root directory of the dataset.
267
+ save_dir (str): Directory to save the split dataset.
268
+ crop_size (int, optional): Base crop size.
269
+ gap (int, optional): Base gap between crops.
270
+ rates (tuple[float, ...], optional): Scaling rates for crop_size and gap.
271
+
272
+ Notes:
273
+ The directory structure assumed for the DOTA dataset:
274
+ - data_root
275
+ - images
276
+ - train
277
+ - val
278
+ - labels
279
+ - train
280
+ - val
281
+ and the output directory structure is:
282
+ - save_dir
283
+ - images
284
+ - train
285
+ - val
286
+ - labels
287
+ - train
288
+ - val
289
+ """
290
+ crop_sizes, gaps = [], []
291
+ for r in rates:
292
+ crop_sizes.append(int(crop_size / r))
293
+ gaps.append(int(gap / r))
294
+ for split in {"train", "val"}:
295
+ split_images_and_labels(data_root, save_dir, split, crop_sizes, gaps)
296
+
297
+
298
+ def split_test(
299
+ data_root: str, save_dir: str, crop_size: int = 1024, gap: int = 200, rates: tuple[float, ...] = (1.0,)
300
+ ) -> None:
301
+ """Split test set of DOTA dataset, labels are not included within this set.
302
+
303
+ Args:
304
+ data_root (str): Root directory of the dataset.
305
+ save_dir (str): Directory to save the split dataset.
306
+ crop_size (int, optional): Base crop size.
307
+ gap (int, optional): Base gap between crops.
308
+ rates (tuple[float, ...], optional): Scaling rates for crop_size and gap.
309
+
310
+ Notes:
311
+ The directory structure assumed for the DOTA dataset:
312
+ - data_root
313
+ - images
314
+ - test
315
+ and the output directory structure is:
316
+ - save_dir
317
+ - images
318
+ - test
319
+ """
320
+ crop_sizes, gaps = [], []
321
+ for r in rates:
322
+ crop_sizes.append(int(crop_size / r))
323
+ gaps.append(int(gap / r))
324
+ save_dir = Path(save_dir) / "images" / "test"
325
+ save_dir.mkdir(parents=True, exist_ok=True)
326
+
327
+ im_dir = Path(data_root) / "images" / "test"
328
+ assert im_dir.exists(), f"Can't find {im_dir}, please check your data root."
329
+ im_files = glob(str(im_dir / "*"))
330
+ for im_file in TQDM(im_files, total=len(im_files), desc="test"):
331
+ w, h = exif_size(Image.open(im_file))
332
+ windows = get_windows((h, w), crop_sizes=crop_sizes, gaps=gaps)
333
+ im = cv2.imread(im_file)
334
+ name = Path(im_file).stem
335
+ for window in windows:
336
+ x_start, y_start, x_stop, y_stop = window.tolist()
337
+ new_name = f"{name}__{x_stop - x_start}__{x_start}___{y_start}"
338
+ patch_im = im[y_start:y_stop, x_start:x_stop]
339
+ cv2.imwrite(str(save_dir / f"{new_name}.jpg"), patch_im)
340
+
341
+
342
+ if __name__ == "__main__":
343
+ split_trainval(data_root="DOTAv2", save_dir="DOTAv2-split")
344
+ split_test(data_root="DOTAv2", save_dir="DOTAv2-split")