ultralytics 8.3.88__py3-none-any.whl → 8.3.89__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 (47) hide show
  1. ultralytics/__init__.py +1 -1
  2. ultralytics/data/base.py +7 -9
  3. ultralytics/data/converter.py +30 -29
  4. ultralytics/data/utils.py +20 -28
  5. ultralytics/engine/model.py +2 -2
  6. ultralytics/engine/tuner.py +11 -21
  7. ultralytics/hub/__init__.py +13 -17
  8. ultralytics/models/fastsam/model.py +4 -7
  9. ultralytics/models/nas/model.py +8 -14
  10. ultralytics/models/nas/predict.py +7 -9
  11. ultralytics/models/nas/val.py +7 -9
  12. ultralytics/models/rtdetr/predict.py +6 -9
  13. ultralytics/models/rtdetr/train.py +5 -8
  14. ultralytics/models/rtdetr/val.py +5 -8
  15. ultralytics/models/yolo/classify/predict.py +6 -9
  16. ultralytics/models/yolo/classify/train.py +5 -8
  17. ultralytics/models/yolo/classify/val.py +5 -8
  18. ultralytics/models/yolo/detect/predict.py +6 -9
  19. ultralytics/models/yolo/detect/train.py +5 -8
  20. ultralytics/models/yolo/detect/val.py +5 -8
  21. ultralytics/models/yolo/obb/predict.py +6 -9
  22. ultralytics/models/yolo/obb/train.py +5 -8
  23. ultralytics/models/yolo/obb/val.py +10 -15
  24. ultralytics/models/yolo/pose/predict.py +6 -9
  25. ultralytics/models/yolo/pose/train.py +5 -8
  26. ultralytics/models/yolo/pose/val.py +12 -17
  27. ultralytics/models/yolo/segment/predict.py +6 -9
  28. ultralytics/models/yolo/segment/train.py +5 -8
  29. ultralytics/models/yolo/segment/val.py +10 -15
  30. ultralytics/models/yolo/world/train.py +5 -8
  31. ultralytics/models/yolo/world/train_world.py +21 -25
  32. ultralytics/nn/modules/__init__.py +9 -12
  33. ultralytics/nn/tasks.py +7 -12
  34. ultralytics/utils/__init__.py +5 -8
  35. ultralytics/utils/checks.py +25 -35
  36. ultralytics/utils/downloads.py +25 -48
  37. ultralytics/utils/instance.py +6 -8
  38. ultralytics/utils/ops.py +5 -9
  39. ultralytics/utils/plotting.py +8 -14
  40. ultralytics/utils/torch_utils.py +23 -33
  41. ultralytics/utils/tuner.py +5 -9
  42. {ultralytics-8.3.88.dist-info → ultralytics-8.3.89.dist-info}/METADATA +2 -2
  43. {ultralytics-8.3.88.dist-info → ultralytics-8.3.89.dist-info}/RECORD +47 -47
  44. {ultralytics-8.3.88.dist-info → ultralytics-8.3.89.dist-info}/LICENSE +0 -0
  45. {ultralytics-8.3.88.dist-info → ultralytics-8.3.89.dist-info}/WHEEL +0 -0
  46. {ultralytics-8.3.88.dist-info → ultralytics-8.3.89.dist-info}/entry_points.txt +0 -0
  47. {ultralytics-8.3.88.dist-info → ultralytics-8.3.89.dist-info}/top_level.txt +0 -0
@@ -11,14 +11,11 @@ class OBBTrainer(yolo.detect.DetectionTrainer):
11
11
  """
12
12
  A class extending the DetectionTrainer class for training based on an Oriented Bounding Box (OBB) model.
13
13
 
14
- Example:
15
- ```python
16
- from ultralytics.models.yolo.obb import OBBTrainer
17
-
18
- args = dict(model="yolo11n-obb.pt", data="dota8.yaml", epochs=3)
19
- trainer = OBBTrainer(overrides=args)
20
- trainer.train()
21
- ```
14
+ Examples:
15
+ >>> from ultralytics.models.yolo.obb import OBBTrainer
16
+ >>> args = dict(model="yolo11n-obb.pt", data="dota8.yaml", epochs=3)
17
+ >>> trainer = OBBTrainer(overrides=args)
18
+ >>> trainer.train()
22
19
  """
23
20
 
24
21
  def __init__(self, cfg=DEFAULT_CFG, overrides=None, _callbacks=None):
@@ -14,14 +14,11 @@ class OBBValidator(DetectionValidator):
14
14
  """
15
15
  A class extending the DetectionValidator class for validation based on an Oriented Bounding Box (OBB) model.
16
16
 
17
- Example:
18
- ```python
19
- from ultralytics.models.yolo.obb import OBBValidator
20
-
21
- args = dict(model="yolo11n-obb.pt", data="dota8.yaml")
22
- validator = OBBValidator(args=args)
23
- validator(model=args["model"])
24
- ```
17
+ Examples:
18
+ >>> from ultralytics.models.yolo.obb import OBBValidator
19
+ >>> args = dict(model="yolo11n-obb.pt", data="dota8.yaml")
20
+ >>> validator = OBBValidator(args=args)
21
+ >>> validator(model=args["model"])
25
22
  """
26
23
 
27
24
  def __init__(self, dataloader=None, save_dir=None, pbar=None, args=None, _callbacks=None):
@@ -51,13 +48,11 @@ class OBBValidator(DetectionValidator):
51
48
  (torch.Tensor): The correct prediction matrix with shape (N, 10), which includes 10 IoU (Intersection over
52
49
  Union) levels for each detection, indicating the accuracy of predictions compared to the ground truth.
53
50
 
54
- Example:
55
- ```python
56
- detections = torch.rand(100, 7) # 100 sample detections
57
- gt_bboxes = torch.rand(50, 5) # 50 sample ground truth boxes
58
- gt_cls = torch.randint(0, 5, (50,)) # 50 ground truth class labels
59
- correct_matrix = OBBValidator._process_batch(detections, gt_bboxes, gt_cls)
60
- ```
51
+ Examples:
52
+ >>> detections = torch.rand(100, 7) # 100 sample detections
53
+ >>> gt_bboxes = torch.rand(50, 5) # 50 sample ground truth boxes
54
+ >>> gt_cls = torch.randint(0, 5, (50,)) # 50 ground truth class labels
55
+ >>> correct_matrix = OBBValidator._process_batch(detections, gt_bboxes, gt_cls)
61
56
 
62
57
  Note:
63
58
  This method relies on `batch_probiou` to calculate IoU between detections and ground truth bounding boxes.
@@ -8,15 +8,12 @@ class PosePredictor(DetectionPredictor):
8
8
  """
9
9
  A class extending the DetectionPredictor class for prediction based on a pose model.
10
10
 
11
- Example:
12
- ```python
13
- from ultralytics.utils import ASSETS
14
- from ultralytics.models.yolo.pose import PosePredictor
15
-
16
- args = dict(model="yolo11n-pose.pt", source=ASSETS)
17
- predictor = PosePredictor(overrides=args)
18
- predictor.predict_cli()
19
- ```
11
+ Examples:
12
+ >>> from ultralytics.utils import ASSETS
13
+ >>> from ultralytics.models.yolo.pose import PosePredictor
14
+ >>> args = dict(model="yolo11n-pose.pt", source=ASSETS)
15
+ >>> predictor = PosePredictor(overrides=args)
16
+ >>> predictor.predict_cli()
20
17
  """
21
18
 
22
19
  def __init__(self, cfg=DEFAULT_CFG, overrides=None, _callbacks=None):
@@ -12,14 +12,11 @@ class PoseTrainer(yolo.detect.DetectionTrainer):
12
12
  """
13
13
  A class extending the DetectionTrainer class for training based on a pose model.
14
14
 
15
- Example:
16
- ```python
17
- from ultralytics.models.yolo.pose import PoseTrainer
18
-
19
- args = dict(model="yolo11n-pose.pt", data="coco8-pose.yaml", epochs=3)
20
- trainer = PoseTrainer(overrides=args)
21
- trainer.train()
22
- ```
15
+ Examples:
16
+ >>> from ultralytics.models.yolo.pose import PoseTrainer
17
+ >>> args = dict(model="yolo11n-pose.pt", data="coco8-pose.yaml", epochs=3)
18
+ >>> trainer = PoseTrainer(overrides=args)
19
+ >>> trainer.train()
23
20
  """
24
21
 
25
22
  def __init__(self, cfg=DEFAULT_CFG, overrides=None, _callbacks=None):
@@ -16,14 +16,11 @@ class PoseValidator(DetectionValidator):
16
16
  """
17
17
  A class extending the DetectionValidator class for validation based on a pose model.
18
18
 
19
- Example:
20
- ```python
21
- from ultralytics.models.yolo.pose import PoseValidator
22
-
23
- args = dict(model="yolo11n-pose.pt", data="coco8-pose.yaml")
24
- validator = PoseValidator(args=args)
25
- validator()
26
- ```
19
+ Examples:
20
+ >>> from ultralytics.models.yolo.pose import PoseValidator
21
+ >>> args = dict(model="yolo11n-pose.pt", data="coco8-pose.yaml")
22
+ >>> validator = PoseValidator(args=args)
23
+ >>> validator()
27
24
  """
28
25
 
29
26
  def __init__(self, dataloader=None, save_dir=None, pbar=None, args=None, _callbacks=None):
@@ -161,15 +158,13 @@ class PoseValidator(DetectionValidator):
161
158
  (torch.Tensor): A tensor with shape (N, 10) representing the correct prediction matrix for 10 IoU levels,
162
159
  where N is the number of detections.
163
160
 
164
- Example:
165
- ```python
166
- detections = torch.rand(100, 6) # 100 predictions: (x1, y1, x2, y2, conf, class)
167
- gt_bboxes = torch.rand(50, 4) # 50 ground truth boxes: (x1, y1, x2, y2)
168
- gt_cls = torch.randint(0, 2, (50,)) # 50 ground truth class indices
169
- pred_kpts = torch.rand(100, 51) # 100 predicted keypoints
170
- gt_kpts = torch.rand(50, 51) # 50 ground truth keypoints
171
- correct_preds = _process_batch(detections, gt_bboxes, gt_cls, pred_kpts, gt_kpts)
172
- ```
161
+ Examples:
162
+ >>> detections = torch.rand(100, 6) # 100 predictions: (x1, y1, x2, y2, conf, class)
163
+ >>> gt_bboxes = torch.rand(50, 4) # 50 ground truth boxes: (x1, y1, x2, y2)
164
+ >>> gt_cls = torch.randint(0, 2, (50,)) # 50 ground truth class indices
165
+ >>> pred_kpts = torch.rand(100, 51) # 100 predicted keypoints
166
+ >>> gt_kpts = torch.rand(50, 51) # 50 ground truth keypoints
167
+ >>> correct_preds = _process_batch(detections, gt_bboxes, gt_cls, pred_kpts, gt_kpts)
173
168
 
174
169
  Note:
175
170
  `0.53` scale factor used in area computation is referenced from https://github.com/jin-s13/xtcocoapi/blob/master/xtcocotools/cocoeval.py#L384.
@@ -9,15 +9,12 @@ class SegmentationPredictor(DetectionPredictor):
9
9
  """
10
10
  A class extending the DetectionPredictor class for prediction based on a segmentation model.
11
11
 
12
- Example:
13
- ```python
14
- from ultralytics.utils import ASSETS
15
- from ultralytics.models.yolo.segment import SegmentationPredictor
16
-
17
- args = dict(model="yolo11n-seg.pt", source=ASSETS)
18
- predictor = SegmentationPredictor(overrides=args)
19
- predictor.predict_cli()
20
- ```
12
+ Examples:
13
+ >>> from ultralytics.utils import ASSETS
14
+ >>> from ultralytics.models.yolo.segment import SegmentationPredictor
15
+ >>> args = dict(model="yolo11n-seg.pt", source=ASSETS)
16
+ >>> predictor = SegmentationPredictor(overrides=args)
17
+ >>> predictor.predict_cli()
21
18
  """
22
19
 
23
20
  def __init__(self, cfg=DEFAULT_CFG, overrides=None, _callbacks=None):
@@ -12,14 +12,11 @@ class SegmentationTrainer(yolo.detect.DetectionTrainer):
12
12
  """
13
13
  A class extending the DetectionTrainer class for training based on a segmentation model.
14
14
 
15
- Example:
16
- ```python
17
- from ultralytics.models.yolo.segment import SegmentationTrainer
18
-
19
- args = dict(model="yolo11n-seg.pt", data="coco8-seg.yaml", epochs=3)
20
- trainer = SegmentationTrainer(overrides=args)
21
- trainer.train()
22
- ```
15
+ Examples:
16
+ >>> from ultralytics.models.yolo.segment import SegmentationTrainer
17
+ >>> args = dict(model="yolo11n-seg.pt", data="coco8-seg.yaml", epochs=3)
18
+ >>> trainer = SegmentationTrainer(overrides=args)
19
+ >>> trainer.train()
23
20
  """
24
21
 
25
22
  def __init__(self, cfg=DEFAULT_CFG, overrides=None, _callbacks=None):
@@ -18,14 +18,11 @@ class SegmentationValidator(DetectionValidator):
18
18
  """
19
19
  A class extending the DetectionValidator class for validation based on a segmentation model.
20
20
 
21
- Example:
22
- ```python
23
- from ultralytics.models.yolo.segment import SegmentationValidator
24
-
25
- args = dict(model="yolo11n-seg.pt", data="coco8-seg.yaml")
26
- validator = SegmentationValidator(args=args)
27
- validator()
28
- ```
21
+ Examples:
22
+ >>> from ultralytics.models.yolo.segment import SegmentationValidator
23
+ >>> args = dict(model="yolo11n-seg.pt", data="coco8-seg.yaml")
24
+ >>> validator = SegmentationValidator(args=args)
25
+ >>> validator()
29
26
  """
30
27
 
31
28
  def __init__(self, dataloader=None, save_dir=None, pbar=None, args=None, _callbacks=None):
@@ -184,13 +181,11 @@ class SegmentationValidator(DetectionValidator):
184
181
  - If `masks` is True, the function computes IoU between predicted and ground truth masks.
185
182
  - If `overlap` is True and `masks` is True, overlapping masks are taken into account when computing IoU.
186
183
 
187
- Example:
188
- ```python
189
- detections = torch.tensor([[25, 30, 200, 300, 0.8, 1], [50, 60, 180, 290, 0.75, 0]])
190
- gt_bboxes = torch.tensor([[24, 29, 199, 299], [55, 65, 185, 295]])
191
- gt_cls = torch.tensor([1, 0])
192
- correct_preds = validator._process_batch(detections, gt_bboxes, gt_cls)
193
- ```
184
+ Examples:
185
+ >>> detections = torch.tensor([[25, 30, 200, 300, 0.8, 1], [50, 60, 180, 290, 0.75, 0]])
186
+ >>> gt_bboxes = torch.tensor([[24, 29, 199, 299], [55, 65, 185, 295]])
187
+ >>> gt_cls = torch.tensor([1, 0])
188
+ >>> correct_preds = validator._process_batch(detections, gt_bboxes, gt_cls)
194
189
  """
195
190
  if masks:
196
191
  if overlap:
@@ -25,14 +25,11 @@ class WorldTrainer(yolo.detect.DetectionTrainer):
25
25
  """
26
26
  A class to fine-tune a world model on a close-set dataset.
27
27
 
28
- Example:
29
- ```python
30
- from ultralytics.models.yolo.world import WorldModel
31
-
32
- args = dict(model="yolov8s-world.pt", data="coco8.yaml", epochs=3)
33
- trainer = WorldTrainer(overrides=args)
34
- trainer.train()
35
- ```
28
+ Examples:
29
+ >>> from ultralytics.models.yolo.world import WorldModel
30
+ >>> args = dict(model="yolov8s-world.pt", data="coco8.yaml", epochs=3)
31
+ >>> trainer = WorldTrainer(overrides=args)
32
+ >>> trainer.train()
36
33
  """
37
34
 
38
35
  def __init__(self, cfg=DEFAULT_CFG, overrides=None, _callbacks=None):
@@ -11,31 +11,27 @@ class WorldTrainerFromScratch(WorldTrainer):
11
11
  """
12
12
  A class extending the WorldTrainer class for training a world model from scratch on open-set dataset.
13
13
 
14
- Example:
15
- ```python
16
- from ultralytics.models.yolo.world.train_world import WorldTrainerFromScratch
17
- from ultralytics import YOLOWorld
18
-
19
- data = dict(
20
- train=dict(
21
- yolo_data=["Objects365.yaml"],
22
- grounding_data=[
23
- dict(
24
- img_path="../datasets/flickr30k/images",
25
- json_file="../datasets/flickr30k/final_flickr_separateGT_train.json",
26
- ),
27
- dict(
28
- img_path="../datasets/GQA/images",
29
- json_file="../datasets/GQA/final_mixed_train_no_coco.json",
30
- ),
31
- ],
32
- ),
33
- val=dict(yolo_data=["lvis.yaml"]),
34
- )
35
-
36
- model = YOLOWorld("yolov8s-worldv2.yaml")
37
- model.train(data=data, trainer=WorldTrainerFromScratch)
38
- ```
14
+ Examples:
15
+ >>> from ultralytics.models.yolo.world.train_world import WorldTrainerFromScratch
16
+ >>> from ultralytics import YOLOWorld
17
+ >>> data = dict(
18
+ ... train=dict(
19
+ ... yolo_data=["Objects365.yaml"],
20
+ ... grounding_data=[
21
+ ... dict(
22
+ ... img_path="../datasets/flickr30k/images",
23
+ ... json_file="../datasets/flickr30k/final_flickr_separateGT_train.json",
24
+ ... ),
25
+ ... dict(
26
+ ... img_path="../datasets/GQA/images",
27
+ ... json_file="../datasets/GQA/final_mixed_train_no_coco.json",
28
+ ... ),
29
+ ... ],
30
+ ... ),
31
+ ... val=dict(yolo_data=["lvis.yaml"]),
32
+ ... )
33
+ >>> model = YOLOWorld("yolov8s-worldv2.yaml")
34
+ >>> model.train(data=data, trainer=WorldTrainerFromScratch)
39
35
  """
40
36
 
41
37
  def __init__(self, cfg=DEFAULT_CFG, overrides=None, _callbacks=None):
@@ -2,19 +2,16 @@
2
2
  """
3
3
  Ultralytics modules.
4
4
 
5
- Example:
5
+ Examples:
6
6
  Visualize a module with Netron.
7
- ```python
8
- from ultralytics.nn.modules import *
9
- import torch
10
- import os
11
-
12
- x = torch.ones(1, 128, 40, 40)
13
- m = Conv(128, 128)
14
- f = f"{m._get_name()}.onnx"
15
- torch.onnx.export(m, x, f)
16
- os.system(f"onnxslim {f} {f} && open {f}") # pip install onnxslim
17
- ```
7
+ >>> from ultralytics.nn.modules import *
8
+ >>> import torch
9
+ >>> import os
10
+ >>> x = torch.ones(1, 128, 40, 40)
11
+ >>> m = Conv(128, 128)
12
+ >>> f = f"{m._get_name()}.onnx"
13
+ >>> torch.onnx.export(m, x, f)
14
+ >>> os.system(f"onnxslim {f} {f} && open {f}") # pip install onnxslim
18
15
  """
19
16
 
20
17
  from .block import (
ultralytics/nn/tasks.py CHANGED
@@ -713,12 +713,10 @@ def temporary_modules(modules=None, attributes=None):
713
713
  modules (dict, optional): A dictionary mapping old module paths to new module paths.
714
714
  attributes (dict, optional): A dictionary mapping old module attributes to new module attributes.
715
715
 
716
- Example:
717
- ```python
718
- with temporary_modules({"old.module": "new.module"}, {"old.module.attribute": "new.module.attribute"}):
719
- import old.module # this will now import new.module
720
- from old.module import attribute # this will now import new.module.attribute
721
- ```
716
+ Examples:
717
+ >>> with temporary_modules({"old.module": "new.module"}, {"old.module.attribute": "new.module.attribute"}):
718
+ >>> import old.module # this will now import new.module
719
+ >>> from old.module import attribute # this will now import new.module.attribute
722
720
 
723
721
  Note:
724
722
  The changes are only in effect inside the context manager and are undone once the context manager exits.
@@ -793,12 +791,9 @@ def torch_safe_load(weight, safe_only=False):
793
791
  weight (str): The file path of the PyTorch model.
794
792
  safe_only (bool): If True, replace unknown classes with SafeClass during loading.
795
793
 
796
- Example:
797
- ```python
798
- from ultralytics.nn.tasks import torch_safe_load
799
-
800
- ckpt, file = torch_safe_load("path/to/best.pt", safe_only=True)
801
- ```
794
+ Examples:
795
+ >>> from ultralytics.nn.tasks import torch_safe_load
796
+ >>> ckpt, file = torch_safe_load("path/to/best.pt", safe_only=True)
802
797
 
803
798
  Returns:
804
799
  ckpt (dict): The loaded model checkpoint.
@@ -427,14 +427,11 @@ class ThreadingLocked:
427
427
  Attributes:
428
428
  lock (threading.Lock): A lock object used to manage access to the decorated function.
429
429
 
430
- Example:
431
- ```python
432
- from ultralytics.utils import ThreadingLocked
433
-
434
- @ThreadingLocked()
435
- def my_function():
436
- # Your code here
437
- ```
430
+ Examples:
431
+ >>> from ultralytics.utils import ThreadingLocked
432
+ >>> @ThreadingLocked()
433
+ >>> def my_function():
434
+ ... # Your code here
438
435
  """
439
436
 
440
437
  def __init__(self):
@@ -60,12 +60,9 @@ def parse_requirements(file_path=ROOT.parent / "requirements.txt", package=""):
60
60
  Returns:
61
61
  (List[Dict[str, str]]): List of parsed requirements as dictionaries with `name` and `specifier` keys.
62
62
 
63
- Example:
64
- ```python
65
- from ultralytics.utils.checks import parse_requirements
66
-
67
- parse_requirements(package="ultralytics")
68
- ```
63
+ Examples:
64
+ >>> from ultralytics.utils.checks import parse_requirements
65
+ >>> parse_requirements(package="ultralytics")
69
66
  """
70
67
  if package:
71
68
  requires = [x for x in metadata.distribution(package).requires if "extra == " not in x]
@@ -194,20 +191,18 @@ def check_version(
194
191
  Returns:
195
192
  (bool): True if requirement is met, False otherwise.
196
193
 
197
- Example:
198
- ```python
199
- # Check if current version is exactly 22.04
200
- check_version(current="22.04", required="==22.04")
194
+ Examples:
195
+ Check if current version is exactly 22.04
196
+ >>> check_version(current="22.04", required="==22.04")
201
197
 
202
- # Check if current version is greater than or equal to 22.04
203
- check_version(current="22.10", required="22.04") # assumes '>=' inequality if none passed
198
+ Check if current version is greater than or equal to 22.04
199
+ >>> check_version(current="22.10", required="22.04") # assumes '>=' inequality if none passed
204
200
 
205
- # Check if current version is less than or equal to 22.04
206
- check_version(current="22.04", required="<=22.04")
201
+ Check if current version is less than or equal to 22.04
202
+ >>> check_version(current="22.04", required="<=22.04")
207
203
 
208
- # Check if current version is between 20.04 (inclusive) and 22.04 (exclusive)
209
- check_version(current="21.10", required=">20.04,<22.04")
210
- ```
204
+ Check if current version is between 20.04 (inclusive) and 22.04 (exclusive)
205
+ >>> check_version(current="21.10", required=">20.04,<22.04")
211
206
  """
212
207
  if not current: # if current is '' or None
213
208
  LOGGER.warning(f"WARNING ⚠️ invalid check_version({current}, {required}) requested, please check values.")
@@ -362,19 +357,17 @@ def check_requirements(requirements=ROOT.parent / "requirements.txt", exclude=()
362
357
  install (bool): If True, attempt to auto-update packages that don't meet requirements.
363
358
  cmds (str): Additional commands to pass to the pip install command when auto-updating.
364
359
 
365
- Example:
366
- ```python
367
- from ultralytics.utils.checks import check_requirements
360
+ Examples:
361
+ >>> from ultralytics.utils.checks import check_requirements
368
362
 
369
- # Check a requirements.txt file
370
- check_requirements("path/to/requirements.txt")
363
+ Check a requirements.txt file
364
+ >>> check_requirements("path/to/requirements.txt")
371
365
 
372
- # Check a single package
373
- check_requirements("ultralytics>=8.0.0")
366
+ Check a single package
367
+ >>> check_requirements("ultralytics>=8.0.0")
374
368
 
375
- # Check multiple packages
376
- check_requirements(["numpy", "ultralytics>=8.0.0"])
377
- ```
369
+ Check multiple packages
370
+ >>> check_requirements(["numpy", "ultralytics>=8.0.0"])
378
371
  """
379
372
  prefix = colorstr("red", "bold", "requirements:")
380
373
  if isinstance(requirements, Path): # requirements.txt file
@@ -657,14 +650,11 @@ def check_amp(model):
657
650
  Args:
658
651
  model (nn.Module): A YOLO11 model instance.
659
652
 
660
- Example:
661
- ```python
662
- from ultralytics import YOLO
663
- from ultralytics.utils.checks import check_amp
664
-
665
- model = YOLO("yolo11n.pt").model.cuda()
666
- check_amp(model)
667
- ```
653
+ Examples:
654
+ >>> from ultralytics import YOLO
655
+ >>> from ultralytics.utils.checks import check_amp
656
+ >>> model = YOLO("yolo11n.pt").model.cuda()
657
+ >>> check_amp(model)
668
658
 
669
659
  Returns:
670
660
  (bool): Returns True if the AMP functionality works correctly with YOLO11 model, else False.
@@ -48,10 +48,8 @@ def is_url(url, check=False):
48
48
  (bool): Returns True for a valid URL. If 'check' is True, also returns True if the URL exists online.
49
49
  Returns False otherwise.
50
50
 
51
- Example:
52
- ```python
53
- valid = is_url("https://www.example.com")
54
- ```
51
+ Examples:
52
+ >>> valid = is_url("https://www.example.com")
55
53
  """
56
54
  try:
57
55
  url = str(url)
@@ -73,12 +71,9 @@ def delete_dsstore(path, files_to_delete=(".DS_Store", "__MACOSX")):
73
71
  path (str, optional): The directory path where the ".DS_store" files should be deleted.
74
72
  files_to_delete (tuple): The files to be deleted.
75
73
 
76
- Example:
77
- ```python
78
- from ultralytics.utils.downloads import delete_dsstore
79
-
80
- delete_dsstore("path/to/dir")
81
- ```
74
+ Examples:
75
+ >>> from ultralytics.utils.downloads import delete_dsstore
76
+ >>> delete_dsstore("path/to/dir")
82
77
 
83
78
  Note:
84
79
  ".DS_store" files are created by the Apple operating system and contain metadata about folders and files. They
@@ -105,12 +100,9 @@ def zip_directory(directory, compress=True, exclude=(".DS_Store", "__MACOSX"), p
105
100
  Returns:
106
101
  (Path): The path to the resulting zip file.
107
102
 
108
- Example:
109
- ```python
110
- from ultralytics.utils.downloads import zip_directory
111
-
112
- file = zip_directory("path/to/dir")
113
- ```
103
+ Examples:
104
+ >>> from ultralytics.utils.downloads import zip_directory
105
+ >>> file = zip_directory("path/to/dir")
114
106
  """
115
107
  from zipfile import ZIP_DEFLATED, ZIP_STORED, ZipFile
116
108
 
@@ -151,12 +143,9 @@ def unzip_file(file, path=None, exclude=(".DS_Store", "__MACOSX"), exist_ok=Fals
151
143
  Returns:
152
144
  (Path): The path to the directory where the zipfile was extracted.
153
145
 
154
- Example:
155
- ```python
156
- from ultralytics.utils.downloads import unzip_file
157
-
158
- dir = unzip_file("path/to/file.zip")
159
- ```
146
+ Examples:
147
+ >>> from ultralytics.utils.downloads import unzip_file
148
+ >>> directory = unzip_file("path/to/file.zip")
160
149
  """
161
150
  from zipfile import BadZipFile, ZipFile, is_zipfile
162
151
 
@@ -245,13 +234,10 @@ def get_google_drive_file_info(link):
245
234
  (str): Direct download URL for the Google Drive file.
246
235
  (str): Original filename of the Google Drive file. If filename extraction fails, returns None.
247
236
 
248
- Example:
249
- ```python
250
- from ultralytics.utils.downloads import get_google_drive_file_info
251
-
252
- link = "https://drive.google.com/file/d/1cqT-cJgANNrhIHCrEufUYhQ4RqiWG_lJ/view?usp=drive_link"
253
- url, filename = get_google_drive_file_info(link)
254
- ```
237
+ Examples:
238
+ >>> from ultralytics.utils.downloads import get_google_drive_file_info
239
+ >>> link = "https://drive.google.com/file/d/1cqT-cJgANNrhIHCrEufUYhQ4RqiWG_lJ/view?usp=drive_link"
240
+ >>> url, filename = get_google_drive_file_info(link)
255
241
  """
256
242
  file_id = link.split("/d/")[1].split("/view")[0]
257
243
  drive_url = f"https://drive.google.com/uc?export=download&id={file_id}"
@@ -305,13 +291,10 @@ def safe_download(
305
291
  exist_ok (bool, optional): Whether to overwrite existing contents during unzipping. Defaults to False.
306
292
  progress (bool, optional): Whether to display a progress bar during the download. Default: True.
307
293
 
308
- Example:
309
- ```python
310
- from ultralytics.utils.downloads import safe_download
311
-
312
- link = "https://ultralytics.com/assets/bus.jpg"
313
- path = safe_download(link)
314
- ```
294
+ Examples:
295
+ >>> from ultralytics.utils.downloads import safe_download
296
+ >>> link = "https://ultralytics.com/assets/bus.jpg"
297
+ >>> path = safe_download(link)
315
298
  """
316
299
  gdrive = url.startswith("https://drive.google.com/") # check if the URL is a Google Drive link
317
300
  if gdrive:
@@ -391,10 +374,8 @@ def get_github_assets(repo="ultralytics/assets", version="latest", retry=False):
391
374
  Returns:
392
375
  (tuple): A tuple containing the release tag and a list of asset names.
393
376
 
394
- Example:
395
- ```python
396
- tag, assets = get_github_assets(repo="ultralytics/assets", version="latest")
397
- ```
377
+ Examples:
378
+ >>> tag, assets = get_github_assets(repo="ultralytics/assets", version="latest")
398
379
  """
399
380
  if version != "latest":
400
381
  version = f"tags/{version}" # i.e. tags/v6.2
@@ -423,10 +404,8 @@ def attempt_download_asset(file, repo="ultralytics/assets", release="v8.3.0", **
423
404
  Returns:
424
405
  (str): The path to the downloaded file.
425
406
 
426
- Example:
427
- ```python
428
- file_path = attempt_download_asset("yolo11n.pt", repo="ultralytics/assets", release="latest")
429
- ```
407
+ Examples:
408
+ >>> file_path = attempt_download_asset("yolo11n.pt", repo="ultralytics/assets", release="latest")
430
409
  """
431
410
  from ultralytics.utils import SETTINGS # scoped for circular import
432
411
 
@@ -478,10 +457,8 @@ def download(url, dir=Path.cwd(), unzip=True, delete=False, curl=False, threads=
478
457
  retry (int, optional): Number of retries in case of download failure. Defaults to 3.
479
458
  exist_ok (bool, optional): Whether to overwrite existing contents during unzipping. Defaults to False.
480
459
 
481
- Example:
482
- ```python
483
- download("https://ultralytics.com/assets/example.zip", dir="path/to/dir", unzip=True)
484
- ```
460
+ Examples:
461
+ >>> download("https://ultralytics.com/assets/example.zip", dir="path/to/dir", unzip=True)
485
462
  """
486
463
  dir = Path(dir)
487
464
  dir.mkdir(parents=True, exist_ok=True) # make directory
@@ -200,14 +200,12 @@ class Instances:
200
200
  normalized (bool, optional): Whether the bounding box coordinates are normalized. Default is True.
201
201
 
202
202
  Examples:
203
- ```python
204
- # Create an Instances object
205
- instances = Instances(
206
- bboxes=np.array([[10, 10, 30, 30], [20, 20, 40, 40]]),
207
- segments=[np.array([[5, 5], [10, 10]]), np.array([[15, 15], [20, 20]])],
208
- keypoints=np.array([[[5, 5, 1], [10, 10, 1]], [[15, 15, 1], [20, 20, 1]]]),
209
- )
210
- ```
203
+ Create an Instances object
204
+ >>> instances = Instances(
205
+ ... bboxes=np.array([[10, 10, 30, 30], [20, 20, 40, 40]]),
206
+ ... segments=[np.array([[5, 5], [10, 10]]), np.array([[15, 15], [20, 20]])],
207
+ ... keypoints=np.array([[[5, 5, 1], [10, 10, 1]], [[15, 15, 1], [20, 20, 1]]]),
208
+ ... )
211
209
 
212
210
  Note:
213
211
  The bounding box format is either 'xywh' or 'xyxy', and is determined by the `bbox_format` argument.