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,422 @@
1
+ # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2
+
3
+ from __future__ import annotations
4
+
5
+ import shutil
6
+ import threading
7
+ import time
8
+ from http import HTTPStatus
9
+ from pathlib import Path
10
+ from typing import Any
11
+ from urllib.parse import parse_qs, urlparse
12
+
13
+ from ultralytics import __version__
14
+ from ultralytics.hub.utils import HELP_MSG, HUB_WEB_ROOT, PREFIX
15
+ from ultralytics.utils import IS_COLAB, LOGGER, SETTINGS, TQDM, checks, emojis
16
+ from ultralytics.utils.errors import HUBModelError
17
+
18
+ AGENT_NAME = f"python-{__version__}-colab" if IS_COLAB else f"python-{__version__}-local"
19
+
20
+
21
+ class HUBTrainingSession:
22
+ """HUB training session for Ultralytics HUB YOLO models.
23
+
24
+ This class encapsulates the functionality for interacting with Ultralytics HUB during model training, including
25
+ model creation, metrics tracking, and checkpoint uploading.
26
+
27
+ Attributes:
28
+ model_id (str): Identifier for the YOLO model being trained.
29
+ model_url (str): URL for the model in Ultralytics HUB.
30
+ rate_limits (dict[str, int]): Rate limits for different API calls in seconds.
31
+ timers (dict[str, Any]): Timers for rate limiting.
32
+ metrics_queue (dict[str, Any]): Queue for the model's metrics.
33
+ metrics_upload_failed_queue (dict[str, Any]): Queue for metrics that failed to upload.
34
+ model (Any): Model data fetched from Ultralytics HUB.
35
+ model_file (str): Path to the model file.
36
+ train_args (dict[str, Any]): Arguments for training the model.
37
+ client (Any): Client for interacting with Ultralytics HUB.
38
+ filename (str): Filename of the model.
39
+
40
+ Examples:
41
+ Create a training session with a model URL
42
+ >>> session = HUBTrainingSession("https://hub.ultralytics.com/models/example-model")
43
+ >>> session.upload_metrics()
44
+ """
45
+
46
+ def __init__(self, identifier: str):
47
+ """Initialize the HUBTrainingSession with the provided model identifier.
48
+
49
+ Args:
50
+ identifier (str): Model identifier used to initialize the HUB training session. It can be a URL string or a
51
+ model key with specific format.
52
+
53
+ Raises:
54
+ ValueError: If the provided model identifier is invalid.
55
+ ConnectionError: If connecting with global API key is not supported.
56
+ ModuleNotFoundError: If hub-sdk package is not installed.
57
+ """
58
+ from hub_sdk import HUBClient
59
+
60
+ self.rate_limits = {"metrics": 3, "ckpt": 900, "heartbeat": 300} # rate limits (seconds)
61
+ self.metrics_queue = {} # holds metrics for each epoch until upload
62
+ self.metrics_upload_failed_queue = {} # holds metrics for each epoch if upload failed
63
+ self.timers = {} # holds timers in ultralytics/utils/callbacks/hub.py
64
+ self.model = None
65
+ self.model_url = None
66
+ self.model_file = None
67
+ self.train_args = None
68
+
69
+ # Parse input
70
+ api_key, model_id, self.filename = self._parse_identifier(identifier)
71
+
72
+ # Get credentials
73
+ active_key = api_key or SETTINGS.get("api_key")
74
+ credentials = {"api_key": active_key} if active_key else None # set credentials
75
+
76
+ # Initialize client
77
+ self.client = HUBClient(credentials)
78
+
79
+ # Load models
80
+ try:
81
+ if model_id:
82
+ self.load_model(model_id) # load existing model
83
+ else:
84
+ self.model = self.client.model() # load empty model
85
+ except Exception:
86
+ if identifier.startswith(f"{HUB_WEB_ROOT}/models/") and not self.client.authenticated:
87
+ LOGGER.warning(
88
+ f"{PREFIX}Please log in using 'yolo login API_KEY'. "
89
+ "You can find your API Key at: https://hub.ultralytics.com/settings?tab=api+keys."
90
+ )
91
+
92
+ @classmethod
93
+ def create_session(cls, identifier: str, args: dict[str, Any] | None = None):
94
+ """Create an authenticated HUBTrainingSession or return None.
95
+
96
+ Args:
97
+ identifier (str): Model identifier used to initialize the HUB training session.
98
+ args (dict[str, Any], optional): Arguments for creating a new model if identifier is not a HUB model URL.
99
+
100
+ Returns:
101
+ session (HUBTrainingSession | None): An authenticated session or None if creation fails.
102
+ """
103
+ try:
104
+ session = cls(identifier)
105
+ if args and not identifier.startswith(f"{HUB_WEB_ROOT}/models/"): # not a HUB model URL
106
+ session.create_model(args)
107
+ assert session.model.id, "HUB model not loaded correctly"
108
+ return session
109
+ # PermissionError and ModuleNotFoundError indicate hub-sdk not installed
110
+ except (PermissionError, ModuleNotFoundError, AssertionError):
111
+ return None
112
+
113
+ def load_model(self, model_id: str):
114
+ """Load an existing model from Ultralytics HUB using the provided model identifier.
115
+
116
+ Args:
117
+ model_id (str): The identifier of the model to load.
118
+
119
+ Raises:
120
+ ValueError: If the specified HUB model does not exist.
121
+ """
122
+ self.model = self.client.model(model_id)
123
+ if not self.model.data: # then model does not exist
124
+ raise ValueError(emojis("❌ The specified HUB model does not exist")) # TODO: improve error handling
125
+
126
+ self.model_url = f"{HUB_WEB_ROOT}/models/{self.model.id}"
127
+ if self.model.is_trained():
128
+ LOGGER.info(f"Loading trained HUB model {self.model_url} 🚀")
129
+ url = self.model.get_weights_url("best") # download URL with auth
130
+ self.model_file = checks.check_file(url, download_dir=Path(SETTINGS["weights_dir"]) / "hub" / self.model.id)
131
+ return
132
+
133
+ # Set training args and start heartbeats for HUB to monitor agent
134
+ self._set_train_args()
135
+ self.model.start_heartbeat(self.rate_limits["heartbeat"])
136
+ LOGGER.info(f"{PREFIX}View model at {self.model_url} 🚀")
137
+
138
+ def create_model(self, model_args: dict[str, Any]):
139
+ """Initialize a HUB training session with the specified model arguments.
140
+
141
+ Args:
142
+ model_args (dict[str, Any]): Arguments for creating the model, including batch size, epochs, image size,
143
+ etc.
144
+
145
+ Returns:
146
+ (None): If the model could not be created.
147
+ """
148
+ payload = {
149
+ "config": {
150
+ "batchSize": model_args.get("batch", -1),
151
+ "epochs": model_args.get("epochs", 300),
152
+ "imageSize": model_args.get("imgsz", 640),
153
+ "patience": model_args.get("patience", 100),
154
+ "device": str(model_args.get("device", "")), # convert None to string
155
+ "cache": str(model_args.get("cache", "ram")), # convert True, False, None to string
156
+ },
157
+ "dataset": {"name": model_args.get("data")},
158
+ "lineage": {
159
+ "architecture": {"name": self.filename.replace(".pt", "").replace(".yaml", "")},
160
+ "parent": {},
161
+ },
162
+ "meta": {"name": self.filename},
163
+ }
164
+
165
+ if self.filename.endswith(".pt"):
166
+ payload["lineage"]["parent"]["name"] = self.filename
167
+
168
+ self.model.create_model(payload)
169
+
170
+ # Model could not be created
171
+ # TODO: improve error handling
172
+ if not self.model.id:
173
+ return None
174
+
175
+ self.model_url = f"{HUB_WEB_ROOT}/models/{self.model.id}"
176
+
177
+ # Start heartbeats for HUB to monitor agent
178
+ self.model.start_heartbeat(self.rate_limits["heartbeat"])
179
+
180
+ LOGGER.info(f"{PREFIX}View model at {self.model_url} 🚀")
181
+
182
+ @staticmethod
183
+ def _parse_identifier(identifier: str):
184
+ """Parse the given identifier to determine the type and extract relevant components.
185
+
186
+ The method supports different identifier formats:
187
+ - A HUB model URL https://hub.ultralytics.com/models/MODEL
188
+ - A HUB model URL with API Key https://hub.ultralytics.com/models/MODEL?api_key=APIKEY
189
+ - A local filename that ends with '.pt' or '.yaml'
190
+
191
+ Args:
192
+ identifier (str): The identifier string to be parsed.
193
+
194
+ Returns:
195
+ api_key (str | None): Extracted API key if present.
196
+ model_id (str | None): Extracted model ID if present.
197
+ filename (str | None): Extracted filename if present.
198
+
199
+ Raises:
200
+ HUBModelError: If the identifier format is not recognized.
201
+ """
202
+ api_key, model_id, filename = None, None, None
203
+ if identifier.endswith((".pt", ".yaml")):
204
+ filename = identifier
205
+ elif identifier.startswith(f"{HUB_WEB_ROOT}/models/"):
206
+ parsed_url = urlparse(identifier)
207
+ model_id = Path(parsed_url.path).stem # handle possible final backslash robustly
208
+ query_params = parse_qs(parsed_url.query) # dictionary, i.e. {"api_key": ["API_KEY_HERE"]}
209
+ api_key = query_params.get("api_key", [None])[0]
210
+ else:
211
+ raise HUBModelError(f"model='{identifier} invalid, correct format is {HUB_WEB_ROOT}/models/MODEL_ID")
212
+ return api_key, model_id, filename
213
+
214
+ def _set_train_args(self):
215
+ """Initialize training arguments and create a model entry on the Ultralytics HUB.
216
+
217
+ This method sets up training arguments based on the model's state and updates them with any additional arguments
218
+ provided. It handles different states of the model, such as whether it's resumable, pretrained, or requires
219
+ specific file setup.
220
+
221
+ Raises:
222
+ ValueError: If the model is already trained, if required dataset information is missing, or if there are
223
+ issues with the provided training arguments.
224
+ """
225
+ if self.model.is_resumable():
226
+ # Model has saved weights
227
+ self.train_args = {"data": self.model.get_dataset_url(), "resume": True}
228
+ self.model_file = self.model.get_weights_url("last")
229
+ else:
230
+ # Model has no saved weights
231
+ self.train_args = self.model.data.get("train_args") # new response
232
+
233
+ # Set the model file as either a *.pt or *.yaml file
234
+ self.model_file = (
235
+ self.model.get_weights_url("parent") if self.model.is_pretrained() else self.model.get_architecture()
236
+ )
237
+
238
+ if "data" not in self.train_args:
239
+ # RF bug - datasets are sometimes not exported
240
+ raise ValueError("Dataset may still be processing. Please wait a minute and try again.")
241
+
242
+ self.model_file = checks.check_yolov5u_filename(self.model_file, verbose=False) # YOLOv5->YOLOv5u
243
+ self.model_id = self.model.id
244
+
245
+ def request_queue(
246
+ self,
247
+ request_func,
248
+ retry: int = 3,
249
+ timeout: int = 30,
250
+ thread: bool = True,
251
+ verbose: bool = True,
252
+ progress_total: int | None = None,
253
+ stream_response: bool | None = None,
254
+ *args,
255
+ **kwargs,
256
+ ):
257
+ """Execute request_func with retries, timeout handling, optional threading, and progress tracking.
258
+
259
+ Args:
260
+ request_func (callable): The function to execute.
261
+ retry (int): Number of retry attempts.
262
+ timeout (int): Maximum time to wait for the request to complete.
263
+ thread (bool): Whether to run the request in a separate thread.
264
+ verbose (bool): Whether to log detailed messages.
265
+ progress_total (int, optional): Total size for progress tracking.
266
+ stream_response (bool, optional): Whether to stream the response.
267
+ *args (Any): Additional positional arguments for request_func.
268
+ **kwargs (Any): Additional keyword arguments for request_func.
269
+
270
+ Returns:
271
+ (requests.Response | None): The response object if thread=False, otherwise None.
272
+ """
273
+
274
+ def retry_request():
275
+ """Attempt to call request_func with retries, timeout, and optional threading."""
276
+ t0 = time.time() # Record the start time for the timeout
277
+ response = None
278
+ for i in range(retry + 1):
279
+ if (time.time() - t0) > timeout:
280
+ LOGGER.warning(f"{PREFIX}Timeout for request reached. {HELP_MSG}")
281
+ break # Timeout reached, exit loop
282
+
283
+ response = request_func(*args, **kwargs)
284
+ if response is None:
285
+ LOGGER.warning(f"{PREFIX}Received no response from the request. {HELP_MSG}")
286
+ time.sleep(2**i) # Exponential backoff before retrying
287
+ continue # Skip further processing and retry
288
+
289
+ if progress_total:
290
+ self._show_upload_progress(progress_total, response)
291
+ elif stream_response:
292
+ self._iterate_content(response)
293
+
294
+ if HTTPStatus.OK <= response.status_code < HTTPStatus.MULTIPLE_CHOICES:
295
+ # if request related to metrics upload
296
+ if kwargs.get("metrics"):
297
+ self.metrics_upload_failed_queue = {}
298
+ return response # Success, no need to retry
299
+
300
+ if i == 0:
301
+ # Initial attempt, check status code and provide messages
302
+ message = self._get_failure_message(response, retry, timeout)
303
+
304
+ if verbose:
305
+ LOGGER.warning(f"{PREFIX}{message} {HELP_MSG} ({response.status_code})")
306
+
307
+ if not self._should_retry(response.status_code):
308
+ LOGGER.warning(f"{PREFIX}Request failed. {HELP_MSG} ({response.status_code}")
309
+ break # Not an error that should be retried, exit loop
310
+
311
+ time.sleep(2**i) # Exponential backoff for retries
312
+
313
+ # if request related to metrics upload and exceed retries
314
+ if response is None and kwargs.get("metrics"):
315
+ self.metrics_upload_failed_queue.update(kwargs.get("metrics"))
316
+
317
+ return response
318
+
319
+ if thread:
320
+ # Start a new thread to run the retry_request function
321
+ threading.Thread(target=retry_request, daemon=True).start()
322
+ else:
323
+ # If running in the main thread, call retry_request directly
324
+ return retry_request()
325
+
326
+ @staticmethod
327
+ def _should_retry(status_code: int) -> bool:
328
+ """Determine if a request should be retried based on the HTTP status code."""
329
+ retry_codes = {
330
+ HTTPStatus.REQUEST_TIMEOUT,
331
+ HTTPStatus.BAD_GATEWAY,
332
+ HTTPStatus.GATEWAY_TIMEOUT,
333
+ }
334
+ return status_code in retry_codes
335
+
336
+ def _get_failure_message(self, response, retry: int, timeout: int) -> str:
337
+ """Generate a retry message based on the response status code.
338
+
339
+ Args:
340
+ response (requests.Response): The HTTP response object.
341
+ retry (int): The number of retry attempts allowed.
342
+ timeout (int): The maximum timeout duration.
343
+
344
+ Returns:
345
+ (str): The retry message.
346
+ """
347
+ if self._should_retry(response.status_code):
348
+ return f"Retrying {retry}x for {timeout}s." if retry else ""
349
+ elif response.status_code == HTTPStatus.TOO_MANY_REQUESTS: # rate limit
350
+ headers = response.headers
351
+ return (
352
+ f"Rate limit reached ({headers['X-RateLimit-Remaining']}/{headers['X-RateLimit-Limit']}). "
353
+ f"Please retry after {headers['Retry-After']}s."
354
+ )
355
+ else:
356
+ try:
357
+ return response.json().get("message", "No JSON message.")
358
+ except AttributeError:
359
+ return "Unable to read JSON."
360
+
361
+ def upload_metrics(self):
362
+ """Upload model metrics to Ultralytics HUB."""
363
+ return self.request_queue(self.model.upload_metrics, metrics=self.metrics_queue.copy(), thread=True)
364
+
365
+ def upload_model(
366
+ self,
367
+ epoch: int,
368
+ weights: str,
369
+ is_best: bool = False,
370
+ map: float = 0.0,
371
+ final: bool = False,
372
+ ) -> None:
373
+ """Upload a model checkpoint to Ultralytics HUB.
374
+
375
+ Args:
376
+ epoch (int): The current training epoch.
377
+ weights (str): Path to the model weights file.
378
+ is_best (bool): Indicates if the current model is the best one so far.
379
+ map (float): Mean average precision of the model.
380
+ final (bool): Indicates if the model is the final model after training.
381
+ """
382
+ weights = Path(weights)
383
+ if not weights.is_file():
384
+ last = weights.with_name(f"last{weights.suffix}")
385
+ if final and last.is_file():
386
+ LOGGER.warning(
387
+ f"{PREFIX} Model 'best.pt' not found, copying 'last.pt' to 'best.pt' and uploading. "
388
+ "This often happens when resuming training in transient environments like Google Colab. "
389
+ "For more reliable training, consider using Ultralytics HUB Cloud. "
390
+ "Learn more at https://docs.ultralytics.com/hub/cloud-training."
391
+ )
392
+ shutil.copy(last, weights) # copy last.pt to best.pt
393
+ else:
394
+ LOGGER.warning(f"{PREFIX} Model upload issue. Missing model {weights}.")
395
+ return
396
+
397
+ self.request_queue(
398
+ self.model.upload_model,
399
+ epoch=epoch,
400
+ weights=str(weights),
401
+ is_best=is_best,
402
+ map=map,
403
+ final=final,
404
+ retry=10,
405
+ timeout=3600,
406
+ thread=not final,
407
+ progress_total=weights.stat().st_size if final else None, # only show progress if final
408
+ stream_response=True,
409
+ )
410
+
411
+ @staticmethod
412
+ def _show_upload_progress(content_length: int, response) -> None:
413
+ """Display a progress bar to track the upload progress of a file download."""
414
+ with TQDM(total=content_length, unit="B", unit_scale=True, unit_divisor=1024) as pbar:
415
+ for data in response.iter_content(chunk_size=1024):
416
+ pbar.update(len(data))
417
+
418
+ @staticmethod
419
+ def _iterate_content(response) -> None:
420
+ """Process the streamed HTTP response data."""
421
+ for _ in response.iter_content(chunk_size=1024):
422
+ pass # Do nothing with data chunks
@@ -0,0 +1,162 @@
1
+ # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2
+
3
+ import os
4
+ import threading
5
+ import time
6
+ from typing import Any
7
+
8
+ from ultralytics.utils import (
9
+ IS_COLAB,
10
+ LOGGER,
11
+ TQDM,
12
+ TryExcept,
13
+ colorstr,
14
+ )
15
+
16
+ HUB_API_ROOT = os.environ.get("ULTRALYTICS_HUB_API", "https://api.ultralytics.com")
17
+ HUB_WEB_ROOT = os.environ.get("ULTRALYTICS_HUB_WEB", "https://hub.ultralytics.com")
18
+
19
+ PREFIX = colorstr("Ultralytics HUB: ")
20
+ HELP_MSG = "If this issue persists please visit https://github.com/ultralytics/hub/issues for assistance."
21
+
22
+
23
+ def request_with_credentials(url: str) -> Any:
24
+ """Make an AJAX request with cookies attached in a Google Colab environment.
25
+
26
+ Args:
27
+ url (str): The URL to make the request to.
28
+
29
+ Returns:
30
+ (Any): The response data from the AJAX request.
31
+
32
+ Raises:
33
+ OSError: If the function is not run in a Google Colab environment.
34
+ """
35
+ if not IS_COLAB:
36
+ raise OSError("request_with_credentials() must run in a Colab environment")
37
+ from google.colab import output
38
+ from IPython import display
39
+
40
+ display.display(
41
+ display.Javascript(
42
+ f"""
43
+ window._hub_tmp = new Promise((resolve, reject) => {{
44
+ const timeout = setTimeout(() => reject("Failed authenticating existing browser session"), 5000)
45
+ fetch("{url}", {{
46
+ method: 'POST',
47
+ credentials: 'include'
48
+ }})
49
+ .then((response) => resolve(response.json()))
50
+ .then((json) => {{
51
+ clearTimeout(timeout);
52
+ }}).catch((err) => {{
53
+ clearTimeout(timeout);
54
+ reject(err);
55
+ }});
56
+ }});
57
+ """
58
+ )
59
+ )
60
+ return output.eval_js("_hub_tmp")
61
+
62
+
63
+ def requests_with_progress(method: str, url: str, **kwargs):
64
+ """Make an HTTP request using the specified method and URL, with an optional progress bar.
65
+
66
+ Args:
67
+ method (str): The HTTP method to use (e.g. 'GET', 'POST').
68
+ url (str): The URL to send the request to.
69
+ **kwargs (Any): Additional keyword arguments to pass to the underlying `requests.request` function.
70
+
71
+ Returns:
72
+ (requests.Response): The response object from the HTTP request.
73
+
74
+ Notes:
75
+ - If 'progress' is set to True, the progress bar will display the download progress for responses with a known
76
+ content length.
77
+ - If 'progress' is a number then progress bar will display assuming content length = progress.
78
+ """
79
+ import requests # scoped as slow import
80
+
81
+ progress = kwargs.pop("progress", False)
82
+ if not progress:
83
+ return requests.request(method, url, **kwargs)
84
+ response = requests.request(method, url, stream=True, **kwargs)
85
+ total = int(response.headers.get("content-length", 0) if isinstance(progress, bool) else progress) # total size
86
+ try:
87
+ pbar = TQDM(total=total, unit="B", unit_scale=True, unit_divisor=1024)
88
+ for data in response.iter_content(chunk_size=1024):
89
+ pbar.update(len(data))
90
+ pbar.close()
91
+ except requests.exceptions.ChunkedEncodingError: # avoid 'Connection broken: IncompleteRead' warnings
92
+ response.close()
93
+ return response
94
+
95
+
96
+ def smart_request(
97
+ method: str,
98
+ url: str,
99
+ retry: int = 3,
100
+ timeout: int = 30,
101
+ thread: bool = True,
102
+ code: int = -1,
103
+ verbose: bool = True,
104
+ progress: bool = False,
105
+ **kwargs,
106
+ ):
107
+ """Make an HTTP request using the 'requests' library, with exponential backoff retries up to a specified timeout.
108
+
109
+ Args:
110
+ method (str): The HTTP method to use for the request. Choices are 'post' and 'get'.
111
+ url (str): The URL to make the request to.
112
+ retry (int, optional): Number of retries to attempt before giving up.
113
+ timeout (int, optional): Timeout in seconds after which the function will give up retrying.
114
+ thread (bool, optional): Whether to execute the request in a separate daemon thread.
115
+ code (int, optional): An identifier for the request, used for logging purposes.
116
+ verbose (bool, optional): A flag to determine whether to print out to console or not.
117
+ progress (bool, optional): Whether to show a progress bar during the request.
118
+ **kwargs (Any): Keyword arguments to be passed to the requests function specified in method.
119
+
120
+ Returns:
121
+ (requests.Response | None): The HTTP response object. If the request is executed in a separate thread, returns
122
+ None.
123
+ """
124
+ retry_codes = (408, 500) # retry only these codes
125
+
126
+ @TryExcept(verbose=verbose)
127
+ def func(func_method, func_url, **func_kwargs):
128
+ """Make HTTP requests with retries and timeouts, with optional progress tracking."""
129
+ r = None # response
130
+ t0 = time.time() # initial time for timer
131
+ for i in range(retry + 1):
132
+ if (time.time() - t0) > timeout:
133
+ break
134
+ r = requests_with_progress(func_method, func_url, **func_kwargs) # i.e. get(url, data, json, files)
135
+ if r.status_code < 300: # return codes in the 2xx range are generally considered "good" or "successful"
136
+ break
137
+ try:
138
+ m = r.json().get("message", "No JSON message.")
139
+ except AttributeError:
140
+ m = "Unable to read JSON."
141
+ if i == 0:
142
+ if r.status_code in retry_codes:
143
+ m += f" Retrying {retry}x for {timeout}s." if retry else ""
144
+ elif r.status_code == 429: # rate limit
145
+ h = r.headers # response headers
146
+ m = (
147
+ f"Rate limit reached ({h['X-RateLimit-Remaining']}/{h['X-RateLimit-Limit']}). "
148
+ f"Please retry after {h['Retry-After']}s."
149
+ )
150
+ if verbose:
151
+ LOGGER.warning(f"{PREFIX}{m} {HELP_MSG} ({r.status_code} #{code})")
152
+ if r.status_code not in retry_codes:
153
+ return r
154
+ time.sleep(2**i) # exponential standoff
155
+ return r
156
+
157
+ args = method, url
158
+ kwargs["progress"] = progress
159
+ if thread:
160
+ threading.Thread(target=func, args=args, kwargs=kwargs, daemon=True).start()
161
+ else:
162
+ return func(*args, **kwargs)
@@ -0,0 +1,9 @@
1
+ # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2
+
3
+ from .fastsam import FastSAM
4
+ from .nas import NAS
5
+ from .rtdetr import RTDETR
6
+ from .sam import SAM
7
+ from .yolo import YOLO, YOLOE, YOLOWorld
8
+
9
+ __all__ = "NAS", "RTDETR", "SAM", "YOLO", "YOLOE", "FastSAM", "YOLOWorld" # allow simpler import
@@ -0,0 +1,7 @@
1
+ # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2
+
3
+ from .model import FastSAM
4
+ from .predict import FastSAMPredictor
5
+ from .val import FastSAMValidator
6
+
7
+ __all__ = "FastSAM", "FastSAMPredictor", "FastSAMValidator"
@@ -0,0 +1,79 @@
1
+ # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+ from typing import Any
7
+
8
+ from ultralytics.engine.model import Model
9
+
10
+ from .predict import FastSAMPredictor
11
+ from .val import FastSAMValidator
12
+
13
+
14
+ class FastSAM(Model):
15
+ """FastSAM model interface for Segment Anything tasks.
16
+
17
+ This class extends the base Model class to provide specific functionality for the FastSAM (Fast Segment Anything
18
+ Model) implementation, allowing for efficient and accurate image segmentation with optional prompting support.
19
+
20
+ Attributes:
21
+ model (str): Path to the pre-trained FastSAM model file.
22
+ task (str): The task type, set to "segment" for FastSAM models.
23
+
24
+ Methods:
25
+ predict: Perform segmentation prediction on image or video source with optional prompts.
26
+ task_map: Returns mapping of segment task to predictor and validator classes.
27
+
28
+ Examples:
29
+ Initialize FastSAM model and run prediction
30
+ >>> from ultralytics import FastSAM
31
+ >>> model = FastSAM("FastSAM-x.pt")
32
+ >>> results = model.predict("ultralytics/assets/bus.jpg")
33
+
34
+ Run prediction with bounding box prompts
35
+ >>> results = model.predict("image.jpg", bboxes=[[100, 100, 200, 200]])
36
+ """
37
+
38
+ def __init__(self, model: str | Path = "FastSAM-x.pt"):
39
+ """Initialize the FastSAM model with the specified pre-trained weights."""
40
+ if str(model) == "FastSAM.pt":
41
+ model = "FastSAM-x.pt"
42
+ assert Path(model).suffix not in {".yaml", ".yml"}, "FastSAM only supports pre-trained weights."
43
+ super().__init__(model=model, task="segment")
44
+
45
+ def predict(
46
+ self,
47
+ source,
48
+ stream: bool = False,
49
+ bboxes: list | None = None,
50
+ points: list | None = None,
51
+ labels: list | None = None,
52
+ texts: list | None = None,
53
+ **kwargs: Any,
54
+ ):
55
+ """Perform segmentation prediction on image or video source.
56
+
57
+ Supports prompted segmentation with bounding boxes, points, labels, and texts. The method packages these prompts
58
+ and passes them to the parent class predict method for processing.
59
+
60
+ Args:
61
+ source (str | PIL.Image | np.ndarray): Input source for prediction, can be a file path, URL, PIL image, or
62
+ numpy array.
63
+ stream (bool): Whether to enable real-time streaming mode for video inputs.
64
+ bboxes (list, optional): Bounding box coordinates for prompted segmentation in format [[x1, y1, x2, y2]].
65
+ points (list, optional): Point coordinates for prompted segmentation in format [[x, y]].
66
+ labels (list, optional): Class labels for prompted segmentation.
67
+ texts (list, optional): Text prompts for segmentation guidance.
68
+ **kwargs (Any): Additional keyword arguments passed to the predictor.
69
+
70
+ Returns:
71
+ (list): List of Results objects containing the prediction results.
72
+ """
73
+ prompts = dict(bboxes=bboxes, points=points, labels=labels, texts=texts)
74
+ return super().predict(source, stream, prompts=prompts, **kwargs)
75
+
76
+ @property
77
+ def task_map(self) -> dict[str, dict[str, Any]]:
78
+ """Returns a dictionary mapping segment task to corresponding predictor and validator classes."""
79
+ return {"segment": {"predictor": FastSAMPredictor, "validator": FastSAMValidator}}