dgenerate-ultralytics-headless 8.3.222__py3-none-any.whl → 8.3.225__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 (158) hide show
  1. {dgenerate_ultralytics_headless-8.3.222.dist-info → dgenerate_ultralytics_headless-8.3.225.dist-info}/METADATA +2 -2
  2. dgenerate_ultralytics_headless-8.3.225.dist-info/RECORD +286 -0
  3. tests/conftest.py +5 -8
  4. tests/test_cli.py +1 -8
  5. tests/test_python.py +1 -2
  6. ultralytics/__init__.py +1 -1
  7. ultralytics/cfg/__init__.py +34 -49
  8. ultralytics/cfg/datasets/ImageNet.yaml +1 -1
  9. ultralytics/cfg/datasets/kitti.yaml +27 -0
  10. ultralytics/cfg/datasets/lvis.yaml +5 -5
  11. ultralytics/cfg/datasets/open-images-v7.yaml +1 -1
  12. ultralytics/data/annotator.py +3 -4
  13. ultralytics/data/augment.py +244 -323
  14. ultralytics/data/base.py +12 -22
  15. ultralytics/data/build.py +47 -40
  16. ultralytics/data/converter.py +32 -42
  17. ultralytics/data/dataset.py +43 -71
  18. ultralytics/data/loaders.py +22 -34
  19. ultralytics/data/split.py +5 -6
  20. ultralytics/data/split_dota.py +8 -15
  21. ultralytics/data/utils.py +27 -36
  22. ultralytics/engine/exporter.py +49 -116
  23. ultralytics/engine/model.py +144 -180
  24. ultralytics/engine/predictor.py +18 -29
  25. ultralytics/engine/results.py +165 -231
  26. ultralytics/engine/trainer.py +11 -19
  27. ultralytics/engine/tuner.py +13 -23
  28. ultralytics/engine/validator.py +6 -10
  29. ultralytics/hub/__init__.py +7 -12
  30. ultralytics/hub/auth.py +6 -12
  31. ultralytics/hub/google/__init__.py +7 -10
  32. ultralytics/hub/session.py +15 -25
  33. ultralytics/hub/utils.py +3 -6
  34. ultralytics/models/fastsam/model.py +6 -8
  35. ultralytics/models/fastsam/predict.py +5 -10
  36. ultralytics/models/fastsam/utils.py +1 -2
  37. ultralytics/models/fastsam/val.py +2 -4
  38. ultralytics/models/nas/model.py +5 -8
  39. ultralytics/models/nas/predict.py +7 -9
  40. ultralytics/models/nas/val.py +1 -2
  41. ultralytics/models/rtdetr/model.py +5 -8
  42. ultralytics/models/rtdetr/predict.py +15 -18
  43. ultralytics/models/rtdetr/train.py +10 -13
  44. ultralytics/models/rtdetr/val.py +13 -20
  45. ultralytics/models/sam/amg.py +12 -18
  46. ultralytics/models/sam/build.py +6 -9
  47. ultralytics/models/sam/model.py +16 -23
  48. ultralytics/models/sam/modules/blocks.py +62 -84
  49. ultralytics/models/sam/modules/decoders.py +17 -24
  50. ultralytics/models/sam/modules/encoders.py +40 -56
  51. ultralytics/models/sam/modules/memory_attention.py +10 -16
  52. ultralytics/models/sam/modules/sam.py +41 -47
  53. ultralytics/models/sam/modules/tiny_encoder.py +64 -83
  54. ultralytics/models/sam/modules/transformer.py +17 -27
  55. ultralytics/models/sam/modules/utils.py +31 -42
  56. ultralytics/models/sam/predict.py +172 -209
  57. ultralytics/models/utils/loss.py +14 -26
  58. ultralytics/models/utils/ops.py +13 -17
  59. ultralytics/models/yolo/classify/predict.py +8 -11
  60. ultralytics/models/yolo/classify/train.py +8 -16
  61. ultralytics/models/yolo/classify/val.py +13 -20
  62. ultralytics/models/yolo/detect/predict.py +4 -8
  63. ultralytics/models/yolo/detect/train.py +11 -20
  64. ultralytics/models/yolo/detect/val.py +38 -48
  65. ultralytics/models/yolo/model.py +35 -47
  66. ultralytics/models/yolo/obb/predict.py +5 -8
  67. ultralytics/models/yolo/obb/train.py +11 -14
  68. ultralytics/models/yolo/obb/val.py +20 -28
  69. ultralytics/models/yolo/pose/predict.py +5 -8
  70. ultralytics/models/yolo/pose/train.py +4 -8
  71. ultralytics/models/yolo/pose/val.py +31 -39
  72. ultralytics/models/yolo/segment/predict.py +9 -14
  73. ultralytics/models/yolo/segment/train.py +3 -6
  74. ultralytics/models/yolo/segment/val.py +16 -26
  75. ultralytics/models/yolo/world/train.py +8 -14
  76. ultralytics/models/yolo/world/train_world.py +11 -16
  77. ultralytics/models/yolo/yoloe/predict.py +16 -23
  78. ultralytics/models/yolo/yoloe/train.py +30 -43
  79. ultralytics/models/yolo/yoloe/train_seg.py +5 -10
  80. ultralytics/models/yolo/yoloe/val.py +15 -20
  81. ultralytics/nn/autobackend.py +10 -18
  82. ultralytics/nn/modules/activation.py +4 -6
  83. ultralytics/nn/modules/block.py +99 -185
  84. ultralytics/nn/modules/conv.py +45 -90
  85. ultralytics/nn/modules/head.py +44 -98
  86. ultralytics/nn/modules/transformer.py +44 -76
  87. ultralytics/nn/modules/utils.py +14 -19
  88. ultralytics/nn/tasks.py +86 -146
  89. ultralytics/nn/text_model.py +25 -40
  90. ultralytics/solutions/ai_gym.py +10 -16
  91. ultralytics/solutions/analytics.py +7 -10
  92. ultralytics/solutions/config.py +4 -5
  93. ultralytics/solutions/distance_calculation.py +9 -12
  94. ultralytics/solutions/heatmap.py +7 -13
  95. ultralytics/solutions/instance_segmentation.py +5 -8
  96. ultralytics/solutions/object_blurrer.py +7 -10
  97. ultralytics/solutions/object_counter.py +8 -12
  98. ultralytics/solutions/object_cropper.py +5 -8
  99. ultralytics/solutions/parking_management.py +12 -14
  100. ultralytics/solutions/queue_management.py +4 -6
  101. ultralytics/solutions/region_counter.py +7 -10
  102. ultralytics/solutions/security_alarm.py +14 -19
  103. ultralytics/solutions/similarity_search.py +7 -12
  104. ultralytics/solutions/solutions.py +31 -53
  105. ultralytics/solutions/speed_estimation.py +6 -9
  106. ultralytics/solutions/streamlit_inference.py +2 -4
  107. ultralytics/solutions/trackzone.py +7 -10
  108. ultralytics/solutions/vision_eye.py +5 -8
  109. ultralytics/trackers/basetrack.py +2 -4
  110. ultralytics/trackers/bot_sort.py +6 -11
  111. ultralytics/trackers/byte_tracker.py +10 -15
  112. ultralytics/trackers/track.py +3 -6
  113. ultralytics/trackers/utils/gmc.py +6 -12
  114. ultralytics/trackers/utils/kalman_filter.py +35 -43
  115. ultralytics/trackers/utils/matching.py +6 -10
  116. ultralytics/utils/__init__.py +61 -100
  117. ultralytics/utils/autobatch.py +2 -4
  118. ultralytics/utils/autodevice.py +11 -13
  119. ultralytics/utils/benchmarks.py +25 -35
  120. ultralytics/utils/callbacks/base.py +8 -10
  121. ultralytics/utils/callbacks/clearml.py +2 -4
  122. ultralytics/utils/callbacks/comet.py +30 -44
  123. ultralytics/utils/callbacks/dvc.py +13 -18
  124. ultralytics/utils/callbacks/mlflow.py +4 -5
  125. ultralytics/utils/callbacks/neptune.py +4 -6
  126. ultralytics/utils/callbacks/raytune.py +3 -4
  127. ultralytics/utils/callbacks/tensorboard.py +4 -6
  128. ultralytics/utils/callbacks/wb.py +10 -13
  129. ultralytics/utils/checks.py +29 -56
  130. ultralytics/utils/cpu.py +1 -2
  131. ultralytics/utils/dist.py +8 -12
  132. ultralytics/utils/downloads.py +17 -27
  133. ultralytics/utils/errors.py +6 -8
  134. ultralytics/utils/events.py +2 -4
  135. ultralytics/utils/export/__init__.py +4 -239
  136. ultralytics/utils/export/engine.py +237 -0
  137. ultralytics/utils/export/imx.py +11 -17
  138. ultralytics/utils/export/tensorflow.py +217 -0
  139. ultralytics/utils/files.py +10 -15
  140. ultralytics/utils/git.py +5 -7
  141. ultralytics/utils/instance.py +30 -51
  142. ultralytics/utils/logger.py +11 -15
  143. ultralytics/utils/loss.py +8 -14
  144. ultralytics/utils/metrics.py +98 -138
  145. ultralytics/utils/nms.py +13 -16
  146. ultralytics/utils/ops.py +47 -74
  147. ultralytics/utils/patches.py +11 -18
  148. ultralytics/utils/plotting.py +29 -42
  149. ultralytics/utils/tal.py +25 -39
  150. ultralytics/utils/torch_utils.py +45 -73
  151. ultralytics/utils/tqdm.py +6 -8
  152. ultralytics/utils/triton.py +9 -12
  153. ultralytics/utils/tuner.py +1 -2
  154. dgenerate_ultralytics_headless-8.3.222.dist-info/RECORD +0 -283
  155. {dgenerate_ultralytics_headless-8.3.222.dist-info → dgenerate_ultralytics_headless-8.3.225.dist-info}/WHEEL +0 -0
  156. {dgenerate_ultralytics_headless-8.3.222.dist-info → dgenerate_ultralytics_headless-8.3.225.dist-info}/entry_points.txt +0 -0
  157. {dgenerate_ultralytics_headless-8.3.222.dist-info → dgenerate_ultralytics_headless-8.3.225.dist-info}/licenses/LICENSE +0 -0
  158. {dgenerate_ultralytics_headless-8.3.222.dist-info → dgenerate_ultralytics_headless-8.3.225.dist-info}/top_level.txt +0 -0
@@ -27,12 +27,11 @@ from ultralytics.utils import (
27
27
 
28
28
 
29
29
  class Model(torch.nn.Module):
30
- """
31
- A base class for implementing YOLO models, unifying APIs across different model types.
30
+ """A base class for implementing YOLO models, unifying APIs across different model types.
32
31
 
33
- This class provides a common interface for various operations related to YOLO models, such as training,
34
- validation, prediction, exporting, and benchmarking. It handles different types of models, including those
35
- loaded from local files, Ultralytics HUB, or Triton Server.
32
+ This class provides a common interface for various operations related to YOLO models, such as training, validation,
33
+ prediction, exporting, and benchmarking. It handles different types of models, including those loaded from local
34
+ files, Ultralytics HUB, or Triton Server.
36
35
 
37
36
  Attributes:
38
37
  callbacks (dict): A dictionary of callback functions for various events during model operations.
@@ -85,20 +84,17 @@ class Model(torch.nn.Module):
85
84
  task: str | None = None,
86
85
  verbose: bool = False,
87
86
  ) -> None:
88
- """
89
- Initialize a new instance of the YOLO model class.
87
+ """Initialize a new instance of the YOLO model class.
90
88
 
91
- This constructor sets up the model based on the provided model path or name. It handles various types of
92
- model sources, including local files, Ultralytics HUB models, and Triton Server models. The method
93
- initializes several important attributes of the model and prepares it for operations like training,
94
- prediction, or export.
89
+ This constructor sets up the model based on the provided model path or name. It handles various types of model
90
+ sources, including local files, Ultralytics HUB models, and Triton Server models. The method initializes several
91
+ important attributes of the model and prepares it for operations like training, prediction, or export.
95
92
 
96
93
  Args:
97
- model (str | Path | Model): Path or name of the model to load or create. Can be a local file path, a
98
- model name from Ultralytics HUB, a Triton Server model, or an already initialized Model instance.
94
+ model (str | Path | Model): Path or name of the model to load or create. Can be a local file path, a model
95
+ name from Ultralytics HUB, a Triton Server model, or an already initialized Model instance.
99
96
  task (str, optional): The specific task for the model. If None, it will be inferred from the config.
100
- verbose (bool): If True, enables verbose output during the model's initialization and subsequent
101
- operations.
97
+ verbose (bool): If True, enables verbose output during the model's initialization and subsequent operations.
102
98
 
103
99
  Raises:
104
100
  FileNotFoundError: If the specified model file does not exist or is inaccessible.
@@ -161,22 +157,21 @@ class Model(torch.nn.Module):
161
157
  stream: bool = False,
162
158
  **kwargs: Any,
163
159
  ) -> list:
164
- """
165
- Alias for the predict method, enabling the model instance to be callable for predictions.
160
+ """Alias for the predict method, enabling the model instance to be callable for predictions.
166
161
 
167
- This method simplifies the process of making predictions by allowing the model instance to be called
168
- directly with the required arguments.
162
+ This method simplifies the process of making predictions by allowing the model instance to be called directly
163
+ with the required arguments.
169
164
 
170
165
  Args:
171
- source (str | Path | int | PIL.Image | np.ndarray | torch.Tensor | list | tuple): The source of
172
- the image(s) to make predictions on. Can be a file path, URL, PIL image, numpy array, PyTorch
173
- tensor, or a list/tuple of these.
166
+ source (str | Path | int | PIL.Image | np.ndarray | torch.Tensor | list | tuple): The source of the image(s)
167
+ to make predictions on. Can be a file path, URL, PIL image, numpy array, PyTorch tensor, or a list/tuple
168
+ of these.
174
169
  stream (bool): If True, treat the input source as a continuous stream for predictions.
175
170
  **kwargs (Any): Additional keyword arguments to configure the prediction process.
176
171
 
177
172
  Returns:
178
- (list[ultralytics.engine.results.Results]): A list of prediction results, each encapsulated in a
179
- Results object.
173
+ (list[ultralytics.engine.results.Results]): A list of prediction results, each encapsulated in a Results
174
+ object.
180
175
 
181
176
  Examples:
182
177
  >>> model = YOLO("yolo11n.pt")
@@ -188,11 +183,10 @@ class Model(torch.nn.Module):
188
183
 
189
184
  @staticmethod
190
185
  def is_triton_model(model: str) -> bool:
191
- """
192
- Check if the given model string is a Triton Server URL.
186
+ """Check if the given model string is a Triton Server URL.
193
187
 
194
- This static method determines whether the provided model string represents a valid Triton Server URL by
195
- parsing its components using urllib.parse.urlsplit().
188
+ This static method determines whether the provided model string represents a valid Triton Server URL by parsing
189
+ its components using urllib.parse.urlsplit().
196
190
 
197
191
  Args:
198
192
  model (str): The model string to be checked.
@@ -213,8 +207,7 @@ class Model(torch.nn.Module):
213
207
 
214
208
  @staticmethod
215
209
  def is_hub_model(model: str) -> bool:
216
- """
217
- Check if the provided model is an Ultralytics HUB model.
210
+ """Check if the provided model is an Ultralytics HUB model.
218
211
 
219
212
  This static method determines whether the given model string represents a valid Ultralytics HUB model
220
213
  identifier.
@@ -236,17 +229,16 @@ class Model(torch.nn.Module):
236
229
  return model.startswith(f"{HUB_WEB_ROOT}/models/")
237
230
 
238
231
  def _new(self, cfg: str, task=None, model=None, verbose=False) -> None:
239
- """
240
- Initialize a new model and infer the task type from model definitions.
232
+ """Initialize a new model and infer the task type from model definitions.
241
233
 
242
- Creates a new model instance based on the provided configuration file. Loads the model configuration, infers
243
- the task type if not specified, and initializes the model using the appropriate class from the task map.
234
+ Creates a new model instance based on the provided configuration file. Loads the model configuration, infers the
235
+ task type if not specified, and initializes the model using the appropriate class from the task map.
244
236
 
245
237
  Args:
246
238
  cfg (str): Path to the model configuration file in YAML format.
247
239
  task (str, optional): The specific task for the model. If None, it will be inferred from the config.
248
- model (torch.nn.Module, optional): A custom model instance. If provided, it will be used instead of
249
- creating a new one.
240
+ model (torch.nn.Module, optional): A custom model instance. If provided, it will be used instead of creating
241
+ a new one.
250
242
  verbose (bool): If True, displays model information during loading.
251
243
 
252
244
  Raises:
@@ -270,11 +262,10 @@ class Model(torch.nn.Module):
270
262
  self.model_name = cfg
271
263
 
272
264
  def _load(self, weights: str, task=None) -> None:
273
- """
274
- Load a model from a checkpoint file or initialize it from a weights file.
265
+ """Load a model from a checkpoint file or initialize it from a weights file.
275
266
 
276
- This method handles loading models from either .pt checkpoint files or other weight file formats. It sets
277
- up the model, task, and related attributes based on the loaded weights.
267
+ This method handles loading models from either .pt checkpoint files or other weight file formats. It sets up the
268
+ model, task, and related attributes based on the loaded weights.
278
269
 
279
270
  Args:
280
271
  weights (str): Path to the model weights file to be loaded.
@@ -308,11 +299,10 @@ class Model(torch.nn.Module):
308
299
  self.model_name = weights
309
300
 
310
301
  def _check_is_pytorch_model(self) -> None:
311
- """
312
- Check if the model is a PyTorch model and raise TypeError if it's not.
302
+ """Check if the model is a PyTorch model and raise TypeError if it's not.
313
303
 
314
- This method verifies that the model is either a PyTorch module or a .pt file. It's used to ensure that
315
- certain operations that require a PyTorch model are only performed on compatible model types.
304
+ This method verifies that the model is either a PyTorch module or a .pt file. It's used to ensure that certain
305
+ operations that require a PyTorch model are only performed on compatible model types.
316
306
 
317
307
  Raises:
318
308
  TypeError: If the model is not a PyTorch module or a .pt file. The error message provides detailed
@@ -336,12 +326,11 @@ class Model(torch.nn.Module):
336
326
  )
337
327
 
338
328
  def reset_weights(self) -> Model:
339
- """
340
- Reset the model's weights to their initial state.
329
+ """Reset the model's weights to their initial state.
341
330
 
342
331
  This method iterates through all modules in the model and resets their parameters if they have a
343
- 'reset_parameters' method. It also ensures that all parameters have 'requires_grad' set to True,
344
- enabling them to be updated during training.
332
+ 'reset_parameters' method. It also ensures that all parameters have 'requires_grad' set to True, enabling them
333
+ to be updated during training.
345
334
 
346
335
  Returns:
347
336
  (Model): The instance of the class with reset weights.
@@ -362,8 +351,7 @@ class Model(torch.nn.Module):
362
351
  return self
363
352
 
364
353
  def load(self, weights: str | Path = "yolo11n.pt") -> Model:
365
- """
366
- Load parameters from the specified weights file into the model.
354
+ """Load parameters from the specified weights file into the model.
367
355
 
368
356
  This method supports loading weights from a file or directly from a weights object. It matches parameters by
369
357
  name and shape and transfers them to the model.
@@ -390,11 +378,10 @@ class Model(torch.nn.Module):
390
378
  return self
391
379
 
392
380
  def save(self, filename: str | Path = "saved_model.pt") -> None:
393
- """
394
- Save the current model state to a file.
381
+ """Save the current model state to a file.
395
382
 
396
- This method exports the model's checkpoint (ckpt) to the specified filename. It includes metadata such as
397
- the date, Ultralytics version, license information, and a link to the documentation.
383
+ This method exports the model's checkpoint (ckpt) to the specified filename. It includes metadata such as the
384
+ date, Ultralytics version, license information, and a link to the documentation.
398
385
 
399
386
  Args:
400
387
  filename (str | Path): The name of the file to save the model to.
@@ -422,8 +409,7 @@ class Model(torch.nn.Module):
422
409
  torch.save({**self.ckpt, **updates}, filename)
423
410
 
424
411
  def info(self, detailed: bool = False, verbose: bool = True):
425
- """
426
- Display model information.
412
+ """Display model information.
427
413
 
428
414
  This method provides an overview or detailed information about the model, depending on the arguments
429
415
  passed. It can control the verbosity of the output and return the information as a list.
@@ -433,8 +419,8 @@ class Model(torch.nn.Module):
433
419
  verbose (bool): If True, prints the information. If False, returns the information as a list.
434
420
 
435
421
  Returns:
436
- (list[str]): A list of strings containing various types of information about the model, including
437
- model summary, layer details, and parameter counts. Empty if verbose is True.
422
+ (list[str]): A list of strings containing various types of information about the model, including model
423
+ summary, layer details, and parameter counts. Empty if verbose is True.
438
424
 
439
425
  Examples:
440
426
  >>> model = Model("yolo11n.pt")
@@ -445,12 +431,11 @@ class Model(torch.nn.Module):
445
431
  return self.model.info(detailed=detailed, verbose=verbose)
446
432
 
447
433
  def fuse(self) -> None:
448
- """
449
- Fuse Conv2d and BatchNorm2d layers in the model for optimized inference.
434
+ """Fuse Conv2d and BatchNorm2d layers in the model for optimized inference.
450
435
 
451
- This method iterates through the model's modules and fuses consecutive Conv2d and BatchNorm2d layers
452
- into a single layer. This fusion can significantly improve inference speed by reducing the number of
453
- operations and memory accesses required during forward passes.
436
+ This method iterates through the model's modules and fuses consecutive Conv2d and BatchNorm2d layers into a
437
+ single layer. This fusion can significantly improve inference speed by reducing the number of operations and
438
+ memory accesses required during forward passes.
454
439
 
455
440
  The fusion process typically involves folding the BatchNorm2d parameters (mean, variance, weight, and
456
441
  bias) into the preceding Conv2d layer's weights and biases. This results in a single Conv2d layer that
@@ -470,15 +455,14 @@ class Model(torch.nn.Module):
470
455
  stream: bool = False,
471
456
  **kwargs: Any,
472
457
  ) -> list:
473
- """
474
- Generate image embeddings based on the provided source.
458
+ """Generate image embeddings based on the provided source.
475
459
 
476
460
  This method is a wrapper around the 'predict()' method, focusing on generating embeddings from an image
477
461
  source. It allows customization of the embedding process through various keyword arguments.
478
462
 
479
463
  Args:
480
- source (str | Path | int | list | tuple | np.ndarray | torch.Tensor): The source of the image for
481
- generating embeddings. Can be a file path, URL, PIL image, numpy array, etc.
464
+ source (str | Path | int | list | tuple | np.ndarray | torch.Tensor): The source of the image for generating
465
+ embeddings. Can be a file path, URL, PIL image, numpy array, etc.
482
466
  stream (bool): If True, predictions are streamed.
483
467
  **kwargs (Any): Additional keyword arguments for configuring the embedding process.
484
468
 
@@ -502,25 +486,24 @@ class Model(torch.nn.Module):
502
486
  predictor=None,
503
487
  **kwargs: Any,
504
488
  ) -> list[Results]:
505
- """
506
- Perform predictions on the given image source using the YOLO model.
489
+ """Perform predictions on the given image source using the YOLO model.
507
490
 
508
- This method facilitates the prediction process, allowing various configurations through keyword arguments.
509
- It supports predictions with custom predictors or the default predictor method. The method handles different
510
- types of image sources and can operate in a streaming mode.
491
+ This method facilitates the prediction process, allowing various configurations through keyword arguments. It
492
+ supports predictions with custom predictors or the default predictor method. The method handles different types
493
+ of image sources and can operate in a streaming mode.
511
494
 
512
495
  Args:
513
- source (str | Path | int | PIL.Image | np.ndarray | torch.Tensor | list | tuple): The source
514
- of the image(s) to make predictions on. Accepts various types including file paths, URLs, PIL
515
- images, numpy arrays, and torch tensors.
496
+ source (str | Path | int | PIL.Image | np.ndarray | torch.Tensor | list | tuple): The source of the image(s)
497
+ to make predictions on. Accepts various types including file paths, URLs, PIL images, numpy arrays, and
498
+ torch tensors.
516
499
  stream (bool): If True, treats the input source as a continuous stream for predictions.
517
- predictor (BasePredictor, optional): An instance of a custom predictor class for making predictions.
518
- If None, the method uses a default predictor.
500
+ predictor (BasePredictor, optional): An instance of a custom predictor class for making predictions. If
501
+ None, the method uses a default predictor.
519
502
  **kwargs (Any): Additional keyword arguments for configuring the prediction process.
520
503
 
521
504
  Returns:
522
- (list[ultralytics.engine.results.Results]): A list of prediction results, each encapsulated in a
523
- Results object.
505
+ (list[ultralytics.engine.results.Results]): A list of prediction results, each encapsulated in a Results
506
+ object.
524
507
 
525
508
  Examples:
526
509
  >>> model = YOLO("yolo11n.pt")
@@ -563,8 +546,7 @@ class Model(torch.nn.Module):
563
546
  persist: bool = False,
564
547
  **kwargs: Any,
565
548
  ) -> list[Results]:
566
- """
567
- Conduct object tracking on the specified input source using the registered trackers.
549
+ """Conduct object tracking on the specified input source using the registered trackers.
568
550
 
569
551
  This method performs object tracking using the model's predictors and optionally registered trackers. It handles
570
552
  various input sources such as file paths or video streams, and supports customization through keyword arguments.
@@ -605,8 +587,7 @@ class Model(torch.nn.Module):
605
587
  validator=None,
606
588
  **kwargs: Any,
607
589
  ):
608
- """
609
- Validate the model using a specified dataset and validation configuration.
590
+ """Validate the model using a specified dataset and validation configuration.
610
591
 
611
592
  This method facilitates the model validation process, allowing for customization through various settings. It
612
593
  supports validation with a custom validator or the default validation approach. The method combines default
@@ -637,13 +618,12 @@ class Model(torch.nn.Module):
637
618
  return validator.metrics
638
619
 
639
620
  def benchmark(self, data=None, format="", verbose=False, **kwargs: Any):
640
- """
641
- Benchmark the model across various export formats to evaluate performance.
621
+ """Benchmark the model across various export formats to evaluate performance.
642
622
 
643
- This method assesses the model's performance in different export formats, such as ONNX, TorchScript, etc.
644
- It uses the 'benchmark' function from the ultralytics.utils.benchmarks module. The benchmarking is
645
- configured using a combination of default configuration values, model-specific arguments, method-specific
646
- defaults, and any additional user-provided keyword arguments.
623
+ This method assesses the model's performance in different export formats, such as ONNX, TorchScript, etc. It
624
+ uses the 'benchmark' function from the ultralytics.utils.benchmarks module. The benchmarking is configured using
625
+ a combination of default configuration values, model-specific arguments, method-specific defaults, and any
626
+ additional user-provided keyword arguments.
647
627
 
648
628
  Args:
649
629
  data (str): Path to the dataset for benchmarking.
@@ -656,8 +636,8 @@ class Model(torch.nn.Module):
656
636
  - device (str): Device to run the benchmark on (e.g., 'cpu', 'cuda').
657
637
 
658
638
  Returns:
659
- (dict): A dictionary containing the results of the benchmarking process, including metrics for
660
- different export formats.
639
+ (dict): A dictionary containing the results of the benchmarking process, including metrics for different
640
+ export formats.
661
641
 
662
642
  Raises:
663
643
  AssertionError: If the model is not a PyTorch model.
@@ -691,23 +671,21 @@ class Model(torch.nn.Module):
691
671
  self,
692
672
  **kwargs: Any,
693
673
  ) -> str:
694
- """
695
- Export the model to a different format suitable for deployment.
674
+ """Export the model to a different format suitable for deployment.
696
675
 
697
676
  This method facilitates the export of the model to various formats (e.g., ONNX, TorchScript) for deployment
698
677
  purposes. It uses the 'Exporter' class for the export process, combining model-specific overrides, method
699
678
  defaults, and any additional arguments provided.
700
679
 
701
680
  Args:
702
- **kwargs (Any): Arbitrary keyword arguments to customize the export process. These are combined with
703
- the model's overrides and method defaults. Common arguments include:
704
- format (str): Export format (e.g., 'onnx', 'engine', 'coreml').
705
- half (bool): Export model in half-precision.
706
- int8 (bool): Export model in int8 precision.
707
- device (str): Device to run the export on.
708
- workspace (int): Maximum memory workspace size for TensorRT engines.
709
- nms (bool): Add Non-Maximum Suppression (NMS) module to model.
710
- simplify (bool): Simplify ONNX model.
681
+ **kwargs (Any): Arbitrary keyword arguments for export configuration. Common options include:
682
+ - format (str): Export format (e.g., 'onnx', 'engine', 'coreml').
683
+ - half (bool): Export model in half-precision.
684
+ - int8 (bool): Export model in int8 precision.
685
+ - device (str): Device to run the export on.
686
+ - workspace (int): Maximum memory workspace size for TensorRT engines.
687
+ - nms (bool): Add Non-Maximum Suppression (NMS) module to model.
688
+ - simplify (bool): Simplify ONNX model.
711
689
 
712
690
  Returns:
713
691
  (str): The path to the exported model file.
@@ -740,29 +718,28 @@ class Model(torch.nn.Module):
740
718
  trainer=None,
741
719
  **kwargs: Any,
742
720
  ):
743
- """
744
- Train the model using the specified dataset and training configuration.
721
+ """Train the model using the specified dataset and training configuration.
745
722
 
746
- This method facilitates model training with a range of customizable settings. It supports training with a
747
- custom trainer or the default training approach. The method handles scenarios such as resuming training
748
- from a checkpoint, integrating with Ultralytics HUB, and updating model and configuration after training.
723
+ This method facilitates model training with a range of customizable settings. It supports training with a custom
724
+ trainer or the default training approach. The method handles scenarios such as resuming training from a
725
+ checkpoint, integrating with Ultralytics HUB, and updating model and configuration after training.
749
726
 
750
- When using Ultralytics HUB, if the session has a loaded model, the method prioritizes HUB training
751
- arguments and warns if local arguments are provided. It checks for pip updates and combines default
752
- configurations, method-specific defaults, and user-provided arguments to configure the training process.
727
+ When using Ultralytics HUB, if the session has a loaded model, the method prioritizes HUB training arguments and
728
+ warns if local arguments are provided. It checks for pip updates and combines default configurations,
729
+ method-specific defaults, and user-provided arguments to configure the training process.
753
730
 
754
731
  Args:
755
732
  trainer (BaseTrainer, optional): Custom trainer instance for model training. If None, uses default.
756
733
  **kwargs (Any): Arbitrary keyword arguments for training configuration. Common options include:
757
- data (str): Path to dataset configuration file.
758
- epochs (int): Number of training epochs.
759
- batch (int): Batch size for training.
760
- imgsz (int): Input image size.
761
- device (str): Device to run training on (e.g., 'cuda', 'cpu').
762
- workers (int): Number of worker threads for data loading.
763
- optimizer (str): Optimizer to use for training.
764
- lr0 (float): Initial learning rate.
765
- patience (int): Epochs to wait for no observable improvement for early stopping of training.
734
+ - data (str): Path to dataset configuration file.
735
+ - epochs (int): Number of training epochs.
736
+ - batch (int): Batch size for training.
737
+ - imgsz (int): Input image size.
738
+ - device (str): Device to run training on (e.g., 'cuda', 'cpu').
739
+ - workers (int): Number of worker threads for data loading.
740
+ - optimizer (str): Optimizer to use for training.
741
+ - lr0 (float): Initial learning rate.
742
+ - patience (int): Epochs to wait for no observable improvement for early stopping of training.
766
743
 
767
744
  Returns:
768
745
  (dict | None): Training metrics if available and training is successful; otherwise, None.
@@ -813,13 +790,12 @@ class Model(torch.nn.Module):
813
790
  *args: Any,
814
791
  **kwargs: Any,
815
792
  ):
816
- """
817
- Conduct hyperparameter tuning for the model, with an option to use Ray Tune.
793
+ """Conduct hyperparameter tuning for the model, with an option to use Ray Tune.
818
794
 
819
- This method supports two modes of hyperparameter tuning: using Ray Tune or a custom tuning method.
820
- When Ray Tune is enabled, it leverages the 'run_ray_tune' function from the ultralytics.utils.tuner module.
821
- Otherwise, it uses the internal 'Tuner' class for tuning. The method combines default, overridden, and
822
- custom arguments to configure the tuning process.
795
+ This method supports two modes of hyperparameter tuning: using Ray Tune or a custom tuning method. When Ray Tune
796
+ is enabled, it leverages the 'run_ray_tune' function from the ultralytics.utils.tuner module. Otherwise, it uses
797
+ the internal 'Tuner' class for tuning. The method combines default, overridden, and custom arguments to
798
+ configure the tuning process.
823
799
 
824
800
  Args:
825
801
  use_ray (bool): Whether to use Ray Tune for hyperparameter tuning. If False, uses internal tuning method.
@@ -855,16 +831,15 @@ class Model(torch.nn.Module):
855
831
  return Tuner(args=args, _callbacks=self.callbacks)(model=self, iterations=iterations)
856
832
 
857
833
  def _apply(self, fn) -> Model:
858
- """
859
- Apply a function to model tensors that are not parameters or registered buffers.
834
+ """Apply a function to model tensors that are not parameters or registered buffers.
860
835
 
861
836
  This method extends the functionality of the parent class's _apply method by additionally resetting the
862
- predictor and updating the device in the model's overrides. It's typically used for operations like
863
- moving the model to a different device or changing its precision.
837
+ predictor and updating the device in the model's overrides. It's typically used for operations like moving the
838
+ model to a different device or changing its precision.
864
839
 
865
840
  Args:
866
- fn (Callable): A function to be applied to the model's tensors. This is typically a method like
867
- to(), cpu(), cuda(), half(), or float().
841
+ fn (Callable): A function to be applied to the model's tensors. This is typically a method like to(), cpu(),
842
+ cuda(), half(), or float().
868
843
 
869
844
  Returns:
870
845
  (Model): The model instance with the function applied and updated attributes.
@@ -884,8 +859,7 @@ class Model(torch.nn.Module):
884
859
 
885
860
  @property
886
861
  def names(self) -> dict[int, str]:
887
- """
888
- Retrieve the class names associated with the loaded model.
862
+ """Retrieve the class names associated with the loaded model.
889
863
 
890
864
  This property returns the class names if they are defined in the model. It checks the class names for validity
891
865
  using the 'check_class_names' function from the ultralytics.nn.autobackend module. If the predictor is not
@@ -915,8 +889,7 @@ class Model(torch.nn.Module):
915
889
 
916
890
  @property
917
891
  def device(self) -> torch.device:
918
- """
919
- Get the device on which the model's parameters are allocated.
892
+ """Get the device on which the model's parameters are allocated.
920
893
 
921
894
  This property determines the device (CPU or GPU) where the model's parameters are currently stored. It is
922
895
  applicable only to models that are instances of torch.nn.Module.
@@ -939,12 +912,11 @@ class Model(torch.nn.Module):
939
912
 
940
913
  @property
941
914
  def transforms(self):
942
- """
943
- Retrieve the transformations applied to the input data of the loaded model.
915
+ """Retrieve the transformations applied to the input data of the loaded model.
944
916
 
945
- This property returns the transformations if they are defined in the model. The transforms
946
- typically include preprocessing steps like resizing, normalization, and data augmentation
947
- that are applied to input data before it is fed into the model.
917
+ This property returns the transformations if they are defined in the model. The transforms typically include
918
+ preprocessing steps like resizing, normalization, and data augmentation that are applied to input data before it
919
+ is fed into the model.
948
920
 
949
921
  Returns:
950
922
  (object | None): The transform object of the model if available, otherwise None.
@@ -960,18 +932,17 @@ class Model(torch.nn.Module):
960
932
  return self.model.transforms if hasattr(self.model, "transforms") else None
961
933
 
962
934
  def add_callback(self, event: str, func) -> None:
963
- """
964
- Add a callback function for a specified event.
935
+ """Add a callback function for a specified event.
965
936
 
966
- This method allows registering custom callback functions that are triggered on specific events during
967
- model operations such as training or inference. Callbacks provide a way to extend and customize the
968
- behavior of the model at various stages of its lifecycle.
937
+ This method allows registering custom callback functions that are triggered on specific events during model
938
+ operations such as training or inference. Callbacks provide a way to extend and customize the behavior of the
939
+ model at various stages of its lifecycle.
969
940
 
970
941
  Args:
971
- event (str): The name of the event to attach the callback to. Must be a valid event name recognized
972
- by the Ultralytics framework.
973
- func (Callable): The callback function to be registered. This function will be called when the
974
- specified event occurs.
942
+ event (str): The name of the event to attach the callback to. Must be a valid event name recognized by the
943
+ Ultralytics framework.
944
+ func (Callable): The callback function to be registered. This function will be called when the specified
945
+ event occurs.
975
946
 
976
947
  Raises:
977
948
  ValueError: If the event name is not recognized or is invalid.
@@ -986,12 +957,11 @@ class Model(torch.nn.Module):
986
957
  self.callbacks[event].append(func)
987
958
 
988
959
  def clear_callback(self, event: str) -> None:
989
- """
990
- Clear all callback functions registered for a specified event.
960
+ """Clear all callback functions registered for a specified event.
991
961
 
992
- This method removes all custom and default callback functions associated with the given event.
993
- It resets the callback list for the specified event to an empty list, effectively removing all
994
- registered callbacks for that event.
962
+ This method removes all custom and default callback functions associated with the given event. It resets the
963
+ callback list for the specified event to an empty list, effectively removing all registered callbacks for that
964
+ event.
995
965
 
996
966
  Args:
997
967
  event (str): The name of the event for which to clear the callbacks. This should be a valid event name
@@ -1014,8 +984,7 @@ class Model(torch.nn.Module):
1014
984
  self.callbacks[event] = []
1015
985
 
1016
986
  def reset_callbacks(self) -> None:
1017
- """
1018
- Reset all callbacks to their default functions.
987
+ """Reset all callbacks to their default functions.
1019
988
 
1020
989
  This method reinstates the default callback functions for all events, removing any custom callbacks that were
1021
990
  previously added. It iterates through all default callback events and replaces the current callbacks with the
@@ -1038,12 +1007,11 @@ class Model(torch.nn.Module):
1038
1007
 
1039
1008
  @staticmethod
1040
1009
  def _reset_ckpt_args(args: dict[str, Any]) -> dict[str, Any]:
1041
- """
1042
- Reset specific arguments when loading a PyTorch model checkpoint.
1010
+ """Reset specific arguments when loading a PyTorch model checkpoint.
1043
1011
 
1044
- This method filters the input arguments dictionary to retain only a specific set of keys that are
1045
- considered important for model loading. It's used to ensure that only relevant arguments are preserved
1046
- when loading a model from a checkpoint, discarding any unnecessary or potentially conflicting settings.
1012
+ This method filters the input arguments dictionary to retain only a specific set of keys that are considered
1013
+ important for model loading. It's used to ensure that only relevant arguments are preserved when loading a model
1014
+ from a checkpoint, discarding any unnecessary or potentially conflicting settings.
1047
1015
 
1048
1016
  Args:
1049
1017
  args (dict): A dictionary containing various model arguments and settings.
@@ -1066,12 +1034,11 @@ class Model(torch.nn.Module):
1066
1034
  # raise AttributeError(f"'{name}' object has no attribute '{attr}'. See valid attributes below.\n{self.__doc__}")
1067
1035
 
1068
1036
  def _smart_load(self, key: str):
1069
- """
1070
- Intelligently load the appropriate module based on the model task.
1037
+ """Intelligently load the appropriate module based on the model task.
1071
1038
 
1072
- This method dynamically selects and returns the correct module (model, trainer, validator, or predictor)
1073
- based on the current task of the model and the provided key. It uses the task_map dictionary to determine
1074
- the appropriate module to load for the specific task.
1039
+ This method dynamically selects and returns the correct module (model, trainer, validator, or predictor) based
1040
+ on the current task of the model and the provided key. It uses the task_map dictionary to determine the
1041
+ appropriate module to load for the specific task.
1075
1042
 
1076
1043
  Args:
1077
1044
  key (str): The type of module to load. Must be one of 'model', 'trainer', 'validator', or 'predictor'.
@@ -1096,21 +1063,20 @@ class Model(torch.nn.Module):
1096
1063
 
1097
1064
  @property
1098
1065
  def task_map(self) -> dict:
1099
- """
1100
- Provide a mapping from model tasks to corresponding classes for different modes.
1066
+ """Provide a mapping from model tasks to corresponding classes for different modes.
1101
1067
 
1102
- This property method returns a dictionary that maps each supported task (e.g., detect, segment, classify)
1103
- to a nested dictionary. The nested dictionary contains mappings for different operational modes
1104
- (model, trainer, validator, predictor) to their respective class implementations.
1068
+ This property method returns a dictionary that maps each supported task (e.g., detect, segment, classify) to a
1069
+ nested dictionary. The nested dictionary contains mappings for different operational modes (model, trainer,
1070
+ validator, predictor) to their respective class implementations.
1105
1071
 
1106
- The mapping allows for dynamic loading of appropriate classes based on the model's task and the
1107
- desired operational mode. This facilitates a flexible and extensible architecture for handling
1108
- various tasks and modes within the Ultralytics framework.
1072
+ The mapping allows for dynamic loading of appropriate classes based on the model's task and the desired
1073
+ operational mode. This facilitates a flexible and extensible architecture for handling various tasks and modes
1074
+ within the Ultralytics framework.
1109
1075
 
1110
1076
  Returns:
1111
1077
  (dict[str, dict[str, Any]]): A dictionary mapping task names to nested dictionaries. Each nested dictionary
1112
- contains mappings for 'model', 'trainer', 'validator', and 'predictor' keys to their respective class
1113
- implementations for that task.
1078
+ contains mappings for 'model', 'trainer', 'validator', and 'predictor' keys to their respective class
1079
+ implementations for that task.
1114
1080
 
1115
1081
  Examples:
1116
1082
  >>> model = Model("yolo11n.pt")
@@ -1121,8 +1087,7 @@ class Model(torch.nn.Module):
1121
1087
  raise NotImplementedError("Please provide task map for your model!")
1122
1088
 
1123
1089
  def eval(self):
1124
- """
1125
- Sets the model to evaluation mode.
1090
+ """Sets the model to evaluation mode.
1126
1091
 
1127
1092
  This method changes the model's mode to evaluation, which affects layers like dropout and batch normalization
1128
1093
  that behave differently during training and evaluation. In evaluation mode, these layers use running statistics
@@ -1140,8 +1105,7 @@ class Model(torch.nn.Module):
1140
1105
  return self
1141
1106
 
1142
1107
  def __getattr__(self, name):
1143
- """
1144
- Enable accessing model attributes directly through the Model class.
1108
+ """Enable accessing model attributes directly through the Model class.
1145
1109
 
1146
1110
  This method provides a way to access attributes of the underlying model directly through the Model class
1147
1111
  instance. It first checks if the requested attribute is 'model', in which case it returns the model from