dgenerate-ultralytics-headless 8.3.141__py3-none-any.whl → 8.3.144__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 (148) hide show
  1. {dgenerate_ultralytics_headless-8.3.141.dist-info → dgenerate_ultralytics_headless-8.3.144.dist-info}/METADATA +1 -1
  2. dgenerate_ultralytics_headless-8.3.144.dist-info/RECORD +272 -0
  3. tests/conftest.py +7 -24
  4. tests/test_cli.py +1 -1
  5. tests/test_cuda.py +7 -2
  6. tests/test_engine.py +7 -8
  7. tests/test_exports.py +16 -16
  8. tests/test_integrations.py +1 -1
  9. tests/test_solutions.py +12 -12
  10. ultralytics/__init__.py +1 -1
  11. ultralytics/cfg/__init__.py +22 -19
  12. ultralytics/data/annotator.py +6 -5
  13. ultralytics/data/augment.py +127 -126
  14. ultralytics/data/base.py +54 -51
  15. ultralytics/data/build.py +47 -23
  16. ultralytics/data/converter.py +47 -43
  17. ultralytics/data/dataset.py +51 -50
  18. ultralytics/data/loaders.py +77 -44
  19. ultralytics/data/split.py +22 -9
  20. ultralytics/data/split_dota.py +63 -39
  21. ultralytics/data/utils.py +59 -39
  22. ultralytics/engine/exporter.py +79 -27
  23. ultralytics/engine/model.py +39 -39
  24. ultralytics/engine/predictor.py +37 -28
  25. ultralytics/engine/results.py +187 -158
  26. ultralytics/engine/trainer.py +36 -19
  27. ultralytics/engine/tuner.py +12 -9
  28. ultralytics/engine/validator.py +7 -9
  29. ultralytics/hub/__init__.py +11 -13
  30. ultralytics/hub/auth.py +22 -2
  31. ultralytics/hub/google/__init__.py +19 -19
  32. ultralytics/hub/session.py +37 -51
  33. ultralytics/hub/utils.py +19 -5
  34. ultralytics/models/fastsam/model.py +30 -12
  35. ultralytics/models/fastsam/predict.py +5 -6
  36. ultralytics/models/fastsam/utils.py +3 -3
  37. ultralytics/models/fastsam/val.py +10 -6
  38. ultralytics/models/nas/model.py +9 -5
  39. ultralytics/models/nas/predict.py +6 -6
  40. ultralytics/models/nas/val.py +3 -3
  41. ultralytics/models/rtdetr/model.py +7 -6
  42. ultralytics/models/rtdetr/predict.py +14 -7
  43. ultralytics/models/rtdetr/train.py +10 -4
  44. ultralytics/models/rtdetr/val.py +36 -9
  45. ultralytics/models/sam/amg.py +30 -12
  46. ultralytics/models/sam/build.py +22 -22
  47. ultralytics/models/sam/model.py +10 -9
  48. ultralytics/models/sam/modules/blocks.py +76 -80
  49. ultralytics/models/sam/modules/decoders.py +6 -8
  50. ultralytics/models/sam/modules/encoders.py +23 -26
  51. ultralytics/models/sam/modules/memory_attention.py +13 -1
  52. ultralytics/models/sam/modules/sam.py +57 -26
  53. ultralytics/models/sam/modules/tiny_encoder.py +232 -237
  54. ultralytics/models/sam/modules/transformer.py +13 -13
  55. ultralytics/models/sam/modules/utils.py +11 -19
  56. ultralytics/models/sam/predict.py +114 -101
  57. ultralytics/models/utils/loss.py +98 -77
  58. ultralytics/models/utils/ops.py +116 -67
  59. ultralytics/models/yolo/classify/predict.py +5 -5
  60. ultralytics/models/yolo/classify/train.py +32 -28
  61. ultralytics/models/yolo/classify/val.py +7 -8
  62. ultralytics/models/yolo/detect/predict.py +1 -0
  63. ultralytics/models/yolo/detect/train.py +15 -14
  64. ultralytics/models/yolo/detect/val.py +37 -36
  65. ultralytics/models/yolo/model.py +106 -23
  66. ultralytics/models/yolo/obb/predict.py +3 -4
  67. ultralytics/models/yolo/obb/train.py +14 -6
  68. ultralytics/models/yolo/obb/val.py +29 -23
  69. ultralytics/models/yolo/pose/predict.py +9 -8
  70. ultralytics/models/yolo/pose/train.py +24 -16
  71. ultralytics/models/yolo/pose/val.py +44 -26
  72. ultralytics/models/yolo/segment/predict.py +5 -5
  73. ultralytics/models/yolo/segment/train.py +11 -7
  74. ultralytics/models/yolo/segment/val.py +2 -2
  75. ultralytics/models/yolo/world/train.py +33 -23
  76. ultralytics/models/yolo/world/train_world.py +11 -3
  77. ultralytics/models/yolo/yoloe/predict.py +11 -11
  78. ultralytics/models/yolo/yoloe/train.py +73 -21
  79. ultralytics/models/yolo/yoloe/train_seg.py +10 -7
  80. ultralytics/models/yolo/yoloe/val.py +42 -18
  81. ultralytics/nn/autobackend.py +59 -15
  82. ultralytics/nn/modules/__init__.py +4 -4
  83. ultralytics/nn/modules/activation.py +4 -1
  84. ultralytics/nn/modules/block.py +178 -111
  85. ultralytics/nn/modules/conv.py +6 -5
  86. ultralytics/nn/modules/head.py +469 -121
  87. ultralytics/nn/modules/transformer.py +147 -58
  88. ultralytics/nn/tasks.py +227 -20
  89. ultralytics/nn/text_model.py +30 -33
  90. ultralytics/solutions/ai_gym.py +1 -1
  91. ultralytics/solutions/analytics.py +7 -4
  92. ultralytics/solutions/config.py +10 -10
  93. ultralytics/solutions/distance_calculation.py +13 -11
  94. ultralytics/solutions/heatmap.py +1 -1
  95. ultralytics/solutions/instance_segmentation.py +6 -3
  96. ultralytics/solutions/object_blurrer.py +3 -3
  97. ultralytics/solutions/object_counter.py +18 -12
  98. ultralytics/solutions/object_cropper.py +12 -5
  99. ultralytics/solutions/parking_management.py +29 -28
  100. ultralytics/solutions/queue_management.py +6 -6
  101. ultralytics/solutions/region_counter.py +10 -3
  102. ultralytics/solutions/security_alarm.py +3 -3
  103. ultralytics/solutions/similarity_search.py +85 -24
  104. ultralytics/solutions/solutions.py +215 -85
  105. ultralytics/solutions/speed_estimation.py +28 -22
  106. ultralytics/solutions/streamlit_inference.py +17 -12
  107. ultralytics/solutions/trackzone.py +4 -4
  108. ultralytics/trackers/basetrack.py +16 -23
  109. ultralytics/trackers/bot_sort.py +30 -20
  110. ultralytics/trackers/byte_tracker.py +70 -64
  111. ultralytics/trackers/track.py +4 -8
  112. ultralytics/trackers/utils/gmc.py +31 -58
  113. ultralytics/trackers/utils/kalman_filter.py +37 -37
  114. ultralytics/trackers/utils/matching.py +1 -1
  115. ultralytics/utils/__init__.py +105 -89
  116. ultralytics/utils/autobatch.py +16 -3
  117. ultralytics/utils/autodevice.py +54 -24
  118. ultralytics/utils/benchmarks.py +42 -28
  119. ultralytics/utils/callbacks/base.py +3 -3
  120. ultralytics/utils/callbacks/clearml.py +9 -9
  121. ultralytics/utils/callbacks/comet.py +67 -25
  122. ultralytics/utils/callbacks/dvc.py +7 -10
  123. ultralytics/utils/callbacks/mlflow.py +2 -5
  124. ultralytics/utils/callbacks/neptune.py +7 -13
  125. ultralytics/utils/callbacks/raytune.py +1 -1
  126. ultralytics/utils/callbacks/tensorboard.py +5 -6
  127. ultralytics/utils/callbacks/wb.py +14 -14
  128. ultralytics/utils/checks.py +14 -13
  129. ultralytics/utils/dist.py +5 -5
  130. ultralytics/utils/downloads.py +94 -67
  131. ultralytics/utils/errors.py +5 -5
  132. ultralytics/utils/export.py +61 -47
  133. ultralytics/utils/files.py +23 -22
  134. ultralytics/utils/instance.py +48 -52
  135. ultralytics/utils/loss.py +78 -40
  136. ultralytics/utils/metrics.py +186 -130
  137. ultralytics/utils/ops.py +186 -190
  138. ultralytics/utils/patches.py +15 -17
  139. ultralytics/utils/plotting.py +84 -42
  140. ultralytics/utils/tal.py +21 -15
  141. ultralytics/utils/torch_utils.py +53 -50
  142. ultralytics/utils/triton.py +5 -4
  143. ultralytics/utils/tuner.py +5 -5
  144. dgenerate_ultralytics_headless-8.3.141.dist-info/RECORD +0 -272
  145. {dgenerate_ultralytics_headless-8.3.141.dist-info → dgenerate_ultralytics_headless-8.3.144.dist-info}/WHEEL +0 -0
  146. {dgenerate_ultralytics_headless-8.3.141.dist-info → dgenerate_ultralytics_headless-8.3.144.dist-info}/entry_points.txt +0 -0
  147. {dgenerate_ultralytics_headless-8.3.141.dist-info → dgenerate_ultralytics_headless-8.3.144.dist-info}/licenses/LICENSE +0 -0
  148. {dgenerate_ultralytics_headless-8.3.141.dist-info → dgenerate_ultralytics_headless-8.3.144.dist-info}/top_level.txt +0 -0
@@ -8,6 +8,7 @@ Usage: See https://docs.ultralytics.com/modes/predict/
8
8
  from copy import deepcopy
9
9
  from functools import lru_cache
10
10
  from pathlib import Path
11
+ from typing import Any, Dict, List, Optional, Tuple, Union
11
12
 
12
13
  import numpy as np
13
14
  import torch
@@ -22,14 +23,18 @@ class BaseTensor(SimpleClass):
22
23
  """
23
24
  Base tensor class with additional methods for easy manipulation and device handling.
24
25
 
26
+ This class provides a foundation for tensor-like objects with device management capabilities,
27
+ supporting both PyTorch tensors and NumPy arrays. It includes methods for moving data between
28
+ devices and converting between tensor types.
29
+
25
30
  Attributes:
26
31
  data (torch.Tensor | np.ndarray): Prediction data such as bounding boxes, masks, or keypoints.
27
32
  orig_shape (Tuple[int, int]): Original shape of the image, typically in the format (height, width).
28
33
 
29
34
  Methods:
30
35
  cpu: Return a copy of the tensor stored in CPU memory.
31
- numpy: Returns a copy of the tensor as a numpy array.
32
- cuda: Moves the tensor to GPU memory, returning a new instance if necessary.
36
+ numpy: Return a copy of the tensor as a numpy array.
37
+ cuda: Move the tensor to GPU memory, returning a new instance if necessary.
33
38
  to: Return a copy of the tensor with the specified device and dtype.
34
39
 
35
40
  Examples:
@@ -42,7 +47,7 @@ class BaseTensor(SimpleClass):
42
47
  >>> gpu_tensor = base_tensor.cuda()
43
48
  """
44
49
 
45
- def __init__(self, data, orig_shape) -> None:
50
+ def __init__(self, data: Union[torch.Tensor, np.ndarray], orig_shape: Tuple[int, int]) -> None:
46
51
  """
47
52
  Initialize BaseTensor with prediction data and the original shape of the image.
48
53
 
@@ -61,9 +66,9 @@ class BaseTensor(SimpleClass):
61
66
  self.orig_shape = orig_shape
62
67
 
63
68
  @property
64
- def shape(self):
69
+ def shape(self) -> Tuple[int, ...]:
65
70
  """
66
- Returns the shape of the underlying data tensor.
71
+ Return the shape of the underlying data tensor.
67
72
 
68
73
  Returns:
69
74
  (Tuple[int, ...]): The shape of the data tensor.
@@ -78,7 +83,7 @@ class BaseTensor(SimpleClass):
78
83
 
79
84
  def cpu(self):
80
85
  """
81
- Returns a copy of the tensor stored in CPU memory.
86
+ Return a copy of the tensor stored in CPU memory.
82
87
 
83
88
  Returns:
84
89
  (BaseTensor): A new BaseTensor object with the data tensor moved to CPU memory.
@@ -96,7 +101,7 @@ class BaseTensor(SimpleClass):
96
101
 
97
102
  def numpy(self):
98
103
  """
99
- Returns a copy of the tensor as a numpy array.
104
+ Return a copy of the tensor as a numpy array.
100
105
 
101
106
  Returns:
102
107
  (np.ndarray): A numpy array containing the same data as the original tensor.
@@ -113,7 +118,7 @@ class BaseTensor(SimpleClass):
113
118
 
114
119
  def cuda(self):
115
120
  """
116
- Moves the tensor to GPU memory.
121
+ Move the tensor to GPU memory.
117
122
 
118
123
  Returns:
119
124
  (BaseTensor): A new BaseTensor instance with the data moved to GPU memory if it's not already a
@@ -148,9 +153,9 @@ class BaseTensor(SimpleClass):
148
153
  """
149
154
  return self.__class__(torch.as_tensor(self.data).to(*args, **kwargs), self.orig_shape)
150
155
 
151
- def __len__(self): # override len(results)
156
+ def __len__(self) -> int:
152
157
  """
153
- Returns the length of the underlying data tensor.
158
+ Return the length of the underlying data tensor.
154
159
 
155
160
  Returns:
156
161
  (int): The number of elements in the first dimension of the data tensor.
@@ -165,7 +170,7 @@ class BaseTensor(SimpleClass):
165
170
 
166
171
  def __getitem__(self, idx):
167
172
  """
168
- Returns a new BaseTensor instance containing the specified indexed elements of the data tensor.
173
+ Return a new BaseTensor instance containing the specified indexed elements of the data tensor.
169
174
 
170
175
  Args:
171
176
  idx (int | List[int] | torch.Tensor): Index or indices to select from the data tensor.
@@ -187,8 +192,9 @@ class Results(SimpleClass, DataExportMixin):
187
192
  """
188
193
  A class for storing and manipulating inference results.
189
194
 
190
- This class provides methods for accessing, manipulating, and visualizing inference results from various
195
+ This class provides comprehensive functionality for handling inference results from various
191
196
  Ultralytics models, including detection, segmentation, classification, and pose estimation.
197
+ It supports visualization, data export, and various coordinate transformations.
192
198
 
193
199
  Attributes:
194
200
  orig_img (numpy.ndarray): The original image as a numpy array.
@@ -204,25 +210,25 @@ class Results(SimpleClass, DataExportMixin):
204
210
  save_dir (str | None): Directory to save results.
205
211
 
206
212
  Methods:
207
- update: Updates the Results object with new detection data.
208
- cpu: Returns a copy of the Results object with all tensors moved to CPU memory.
209
- numpy: Converts all tensors in the Results object to numpy arrays.
210
- cuda: Moves all tensors in the Results object to GPU memory.
211
- to: Moves all tensors to the specified device and dtype.
212
- new: Creates a new Results object with the same image, path, names, and speed attributes.
213
- plot: Plots detection results on an input RGB image.
214
- show: Displays the image with annotated inference results.
215
- save: Saves annotated inference results image to file.
216
- verbose: Returns a log string for each task in the results.
217
- save_txt: Saves detection results to a text file.
218
- save_crop: Saves cropped detection images to specified directory.
219
- summary: Converts inference results to a summarized dictionary.
220
- to_df: Converts detection results to a Pandas Dataframe.
221
- to_json: Converts detection results to JSON format.
222
- to_csv: Converts detection results to a CSV format.
223
- to_xml: Converts detection results to XML format.
224
- to_html: Converts detection results to HTML format.
225
- to_sql: Converts detection results to an SQL-compatible format.
213
+ update: Update the Results object with new detection data.
214
+ cpu: Return a copy of the Results object with all tensors moved to CPU memory.
215
+ numpy: Convert all tensors in the Results object to numpy arrays.
216
+ cuda: Move all tensors in the Results object to GPU memory.
217
+ to: Move all tensors to the specified device and dtype.
218
+ new: Create a new Results object with the same image, path, names, and speed attributes.
219
+ plot: Plot detection results on an input RGB image.
220
+ show: Display the image with annotated inference results.
221
+ save: Save annotated inference results image to file.
222
+ verbose: Return a log string for each task in the results.
223
+ save_txt: Save detection results to a text file.
224
+ save_crop: Save cropped detection images to specified directory.
225
+ summary: Convert inference results to a summarized dictionary.
226
+ to_df: Convert detection results to a Pandas Dataframe.
227
+ to_json: Convert detection results to JSON format.
228
+ to_csv: Convert detection results to a CSV format.
229
+ to_xml: Convert detection results to XML format.
230
+ to_html: Convert detection results to HTML format.
231
+ to_sql: Convert detection results to an SQL-compatible format.
226
232
 
227
233
  Examples:
228
234
  >>> results = model("path/to/image.jpg")
@@ -234,7 +240,16 @@ class Results(SimpleClass, DataExportMixin):
234
240
  """
235
241
 
236
242
  def __init__(
237
- self, orig_img, path, names, boxes=None, masks=None, probs=None, keypoints=None, obb=None, speed=None
243
+ self,
244
+ orig_img: np.ndarray,
245
+ path: str,
246
+ names: Dict[int, str],
247
+ boxes: Optional[torch.Tensor] = None,
248
+ masks: Optional[torch.Tensor] = None,
249
+ probs: Optional[torch.Tensor] = None,
250
+ keypoints: Optional[torch.Tensor] = None,
251
+ obb: Optional[torch.Tensor] = None,
252
+ speed: Optional[Dict[str, float]] = None,
238
253
  ) -> None:
239
254
  """
240
255
  Initialize the Results class for storing and manipulating inference results.
@@ -293,7 +308,7 @@ class Results(SimpleClass, DataExportMixin):
293
308
  """
294
309
  return self._apply("__getitem__", idx)
295
310
 
296
- def __len__(self):
311
+ def __len__(self) -> int:
297
312
  """
298
313
  Return the number of detections in the Results object.
299
314
 
@@ -311,9 +326,16 @@ class Results(SimpleClass, DataExportMixin):
311
326
  if v is not None:
312
327
  return len(v)
313
328
 
314
- def update(self, boxes=None, masks=None, probs=None, obb=None, keypoints=None):
329
+ def update(
330
+ self,
331
+ boxes: Optional[torch.Tensor] = None,
332
+ masks: Optional[torch.Tensor] = None,
333
+ probs: Optional[torch.Tensor] = None,
334
+ obb: Optional[torch.Tensor] = None,
335
+ keypoints: Optional[torch.Tensor] = None,
336
+ ):
315
337
  """
316
- Updates the Results object with new detection data.
338
+ Update the Results object with new detection data.
317
339
 
318
340
  This method allows updating the boxes, masks, probabilities, and oriented bounding boxes (OBB) of the
319
341
  Results object. It ensures that boxes are clipped to the original image shape.
@@ -342,9 +364,9 @@ class Results(SimpleClass, DataExportMixin):
342
364
  if keypoints is not None:
343
365
  self.keypoints = Keypoints(keypoints, self.orig_shape)
344
366
 
345
- def _apply(self, fn, *args, **kwargs):
367
+ def _apply(self, fn: str, *args, **kwargs):
346
368
  """
347
- Applies a function to all non-empty attributes and returns a new Results object with modified attributes.
369
+ Apply a function to all non-empty attributes and return a new Results object with modified attributes.
348
370
 
349
371
  This method is internally called by methods like .to(), .cuda(), .cpu(), etc.
350
372
 
@@ -371,7 +393,7 @@ class Results(SimpleClass, DataExportMixin):
371
393
 
372
394
  def cpu(self):
373
395
  """
374
- Returns a copy of the Results object with all its tensors moved to CPU memory.
396
+ Return a copy of the Results object with all its tensors moved to CPU memory.
375
397
 
376
398
  This method creates a new Results object with all tensor attributes (boxes, masks, probs, keypoints, obb)
377
399
  transferred to CPU memory. It's useful for moving data from GPU to CPU for further processing or saving.
@@ -388,7 +410,7 @@ class Results(SimpleClass, DataExportMixin):
388
410
 
389
411
  def numpy(self):
390
412
  """
391
- Converts all tensors in the Results object to numpy arrays.
413
+ Convert all tensors in the Results object to numpy arrays.
392
414
 
393
415
  Returns:
394
416
  (Results): A new Results object with all tensors converted to numpy arrays.
@@ -407,7 +429,7 @@ class Results(SimpleClass, DataExportMixin):
407
429
 
408
430
  def cuda(self):
409
431
  """
410
- Moves all tensors in the Results object to GPU memory.
432
+ Move all tensors in the Results object to GPU memory.
411
433
 
412
434
  Returns:
413
435
  (Results): A new Results object with all tensors moved to CUDA device.
@@ -422,7 +444,7 @@ class Results(SimpleClass, DataExportMixin):
422
444
 
423
445
  def to(self, *args, **kwargs):
424
446
  """
425
- Moves all tensors in the Results object to the specified device and dtype.
447
+ Move all tensors in the Results object to the specified device and dtype.
426
448
 
427
449
  Args:
428
450
  *args (Any): Variable length argument list to be passed to torch.Tensor.to().
@@ -441,7 +463,7 @@ class Results(SimpleClass, DataExportMixin):
441
463
 
442
464
  def new(self):
443
465
  """
444
- Creates a new Results object with the same image, path, names, and speed attributes.
466
+ Create a new Results object with the same image, path, names, and speed attributes.
445
467
 
446
468
  Returns:
447
469
  (Results): A new Results object with copied attributes from the original instance.
@@ -454,27 +476,27 @@ class Results(SimpleClass, DataExportMixin):
454
476
 
455
477
  def plot(
456
478
  self,
457
- conf=True,
458
- line_width=None,
459
- font_size=None,
460
- font="Arial.ttf",
461
- pil=False,
462
- img=None,
463
- im_gpu=None,
464
- kpt_radius=5,
465
- kpt_line=True,
466
- labels=True,
467
- boxes=True,
468
- masks=True,
469
- probs=True,
470
- show=False,
471
- save=False,
472
- filename=None,
473
- color_mode="class",
474
- txt_color=(255, 255, 255),
475
- ):
476
- """
477
- Plots detection results on an input RGB image.
479
+ conf: bool = True,
480
+ line_width: Optional[float] = None,
481
+ font_size: Optional[float] = None,
482
+ font: str = "Arial.ttf",
483
+ pil: bool = False,
484
+ img: Optional[np.ndarray] = None,
485
+ im_gpu: Optional[torch.Tensor] = None,
486
+ kpt_radius: int = 5,
487
+ kpt_line: bool = True,
488
+ labels: bool = True,
489
+ boxes: bool = True,
490
+ masks: bool = True,
491
+ probs: bool = True,
492
+ show: bool = False,
493
+ save: bool = False,
494
+ filename: Optional[str] = None,
495
+ color_mode: str = "class",
496
+ txt_color: Tuple[int, int, int] = (255, 255, 255),
497
+ ) -> np.ndarray:
498
+ """
499
+ Plot detection results on an input RGB image.
478
500
 
479
501
  Args:
480
502
  conf (bool): Whether to plot detection confidence scores.
@@ -493,8 +515,8 @@ class Results(SimpleClass, DataExportMixin):
493
515
  show (bool): Whether to display the annotated image.
494
516
  save (bool): Whether to save the annotated image.
495
517
  filename (str | None): Filename to save image if save is True.
496
- color_mode (bool): Specify the color mode, e.g., 'instance' or 'class'. Default to 'class'.
497
- txt_color (tuple[int, int, int]): Specify the RGB text color for classification task
518
+ color_mode (str): Specify the color mode, e.g., 'instance' or 'class'.
519
+ txt_color (tuple[int, int, int]): Specify the RGB text color for classification task.
498
520
 
499
521
  Returns:
500
522
  (np.ndarray): Annotated image as a numpy array.
@@ -563,7 +585,6 @@ class Results(SimpleClass, DataExportMixin):
563
585
  else None,
564
586
  True,
565
587
  ),
566
- rotated=is_obb,
567
588
  )
568
589
 
569
590
  # Plot Classify results
@@ -612,9 +633,9 @@ class Results(SimpleClass, DataExportMixin):
612
633
  """
613
634
  self.plot(show=True, *args, **kwargs)
614
635
 
615
- def save(self, filename=None, *args, **kwargs):
636
+ def save(self, filename: Optional[str] = None, *args, **kwargs) -> str:
616
637
  """
617
- Saves annotated inference results image to file.
638
+ Save annotated inference results image to file.
618
639
 
619
640
  This method plots the detection results on the original image and saves the annotated image to a file. It
620
641
  utilizes the `plot` method to generate the annotated image and then saves it to the specified filename.
@@ -625,6 +646,9 @@ class Results(SimpleClass, DataExportMixin):
625
646
  *args (Any): Variable length argument list to be passed to the `plot` method.
626
647
  **kwargs (Any): Arbitrary keyword arguments to be passed to the `plot` method.
627
648
 
649
+ Returns:
650
+ (str): The filename where the image was saved.
651
+
628
652
  Examples:
629
653
  >>> results = model("path/to/image.jpg")
630
654
  >>> for result in results:
@@ -638,9 +662,9 @@ class Results(SimpleClass, DataExportMixin):
638
662
  self.plot(save=True, filename=filename, *args, **kwargs)
639
663
  return filename
640
664
 
641
- def verbose(self):
665
+ def verbose(self) -> str:
642
666
  """
643
- Returns a log string for each task in the results, detailing detection and classification outcomes.
667
+ Return a log string for each task in the results, detailing detection and classification outcomes.
644
668
 
645
669
  This method generates a human-readable string summarizing the detection and classification results. It includes
646
670
  the number of detections for each class and the top probabilities for classification tasks.
@@ -670,7 +694,7 @@ class Results(SimpleClass, DataExportMixin):
670
694
  counts = boxes.cls.int().bincount()
671
695
  return "".join(f"{n} {self.names[i]}{'s' * (n > 1)}, " for i, n in enumerate(counts) if n > 0)
672
696
 
673
- def save_txt(self, txt_file, save_conf=False):
697
+ def save_txt(self, txt_file: Union[str, Path], save_conf: bool = False) -> str:
674
698
  """
675
699
  Save detection results to a text file.
676
700
 
@@ -725,16 +749,18 @@ class Results(SimpleClass, DataExportMixin):
725
749
  with open(txt_file, "a", encoding="utf-8") as f:
726
750
  f.writelines(text + "\n" for text in texts)
727
751
 
728
- def save_crop(self, save_dir, file_name=Path("im.jpg")):
752
+ return str(txt_file)
753
+
754
+ def save_crop(self, save_dir: Union[str, Path], file_name: Union[str, Path] = Path("im.jpg")):
729
755
  """
730
- Saves cropped detection images to specified directory.
756
+ Save cropped detection images to specified directory.
731
757
 
732
758
  This method saves cropped images of detected objects to a specified directory. Each crop is saved in a
733
759
  subdirectory named after the object's class, with the filename based on the input file_name.
734
760
 
735
761
  Args:
736
762
  save_dir (str | Path): Directory path where cropped images will be saved.
737
- file_name (str | Path): Base filename for the saved cropped images. Default is Path("im.jpg").
763
+ file_name (str | Path): Base filename for the saved cropped images.
738
764
 
739
765
  Notes:
740
766
  - This method does not support Classify or Oriented Bounding Box (OBB) tasks.
@@ -761,9 +787,9 @@ class Results(SimpleClass, DataExportMixin):
761
787
  BGR=True,
762
788
  )
763
789
 
764
- def summary(self, normalize=False, decimals=5):
790
+ def summary(self, normalize: bool = False, decimals: int = 5) -> List[Dict[str, Any]]:
765
791
  """
766
- Converts inference results to a summarized dictionary with optional normalization for box coordinates.
792
+ Convert inference results to a summarized dictionary with optional normalization for box coordinates.
767
793
 
768
794
  This method creates a list of detection dictionaries, each containing information about a single
769
795
  detection or classification result. For classification tasks, it returns the top class and its
@@ -832,9 +858,9 @@ class Boxes(BaseTensor):
832
858
  """
833
859
  A class for managing and manipulating detection boxes.
834
860
 
835
- This class provides functionality for handling detection boxes, including their coordinates, confidence scores,
836
- class labels, and optional tracking IDs. It supports various box formats and offers methods for easy manipulation
837
- and conversion between different coordinate systems.
861
+ This class provides comprehensive functionality for handling detection boxes, including their coordinates,
862
+ confidence scores, class labels, and optional tracking IDs. It supports various box formats and offers
863
+ methods for easy manipulation and conversion between different coordinate systems.
838
864
 
839
865
  Attributes:
840
866
  data (torch.Tensor | numpy.ndarray): The raw tensor containing detection boxes and associated data.
@@ -849,10 +875,10 @@ class Boxes(BaseTensor):
849
875
  xywhn (torch.Tensor | numpy.ndarray): Normalized [x, y, width, height] boxes relative to orig_shape.
850
876
 
851
877
  Methods:
852
- cpu(): Returns a copy of the object with all tensors on CPU memory.
853
- numpy(): Returns a copy of the object with all tensors as numpy arrays.
854
- cuda(): Returns a copy of the object with all tensors on GPU memory.
855
- to(*args, **kwargs): Returns a copy of the object with tensors on specified device and dtype.
878
+ cpu: Return a copy of the object with all tensors on CPU memory.
879
+ numpy: Return a copy of the object with all tensors as numpy arrays.
880
+ cuda: Return a copy of the object with all tensors on GPU memory.
881
+ to: Return a copy of the object with tensors on specified device and dtype.
856
882
 
857
883
  Examples:
858
884
  >>> import torch
@@ -865,7 +891,7 @@ class Boxes(BaseTensor):
865
891
  >>> print(boxes.xywhn)
866
892
  """
867
893
 
868
- def __init__(self, boxes, orig_shape) -> None:
894
+ def __init__(self, boxes: Union[torch.Tensor, np.ndarray], orig_shape: Tuple[int, int]) -> None:
869
895
  """
870
896
  Initialize the Boxes class with detection box data and the original image shape.
871
897
 
@@ -901,9 +927,9 @@ class Boxes(BaseTensor):
901
927
  self.orig_shape = orig_shape
902
928
 
903
929
  @property
904
- def xyxy(self):
930
+ def xyxy(self) -> Union[torch.Tensor, np.ndarray]:
905
931
  """
906
- Returns bounding boxes in [x1, y1, x2, y2] format.
932
+ Return bounding boxes in [x1, y1, x2, y2] format.
907
933
 
908
934
  Returns:
909
935
  (torch.Tensor | numpy.ndarray): A tensor or numpy array of shape (n, 4) containing bounding box
@@ -918,9 +944,9 @@ class Boxes(BaseTensor):
918
944
  return self.data[:, :4]
919
945
 
920
946
  @property
921
- def conf(self):
947
+ def conf(self) -> Union[torch.Tensor, np.ndarray]:
922
948
  """
923
- Returns the confidence scores for each detection box.
949
+ Return the confidence scores for each detection box.
924
950
 
925
951
  Returns:
926
952
  (torch.Tensor | numpy.ndarray): A 1D tensor or array containing confidence scores for each detection,
@@ -935,9 +961,9 @@ class Boxes(BaseTensor):
935
961
  return self.data[:, -2]
936
962
 
937
963
  @property
938
- def cls(self):
964
+ def cls(self) -> Union[torch.Tensor, np.ndarray]:
939
965
  """
940
- Returns the class ID tensor representing category predictions for each bounding box.
966
+ Return the class ID tensor representing category predictions for each bounding box.
941
967
 
942
968
  Returns:
943
969
  (torch.Tensor | numpy.ndarray): A tensor or numpy array containing the class IDs for each detection box.
@@ -952,9 +978,9 @@ class Boxes(BaseTensor):
952
978
  return self.data[:, -1]
953
979
 
954
980
  @property
955
- def id(self):
981
+ def id(self) -> Optional[Union[torch.Tensor, np.ndarray]]:
956
982
  """
957
- Returns the tracking IDs for each detection box if available.
983
+ Return the tracking IDs for each detection box if available.
958
984
 
959
985
  Returns:
960
986
  (torch.Tensor | None): A tensor containing tracking IDs for each box if tracking is enabled,
@@ -977,15 +1003,16 @@ class Boxes(BaseTensor):
977
1003
  return self.data[:, -3] if self.is_track else None
978
1004
 
979
1005
  @property
980
- @lru_cache(maxsize=2) # maxsize 1 should suffice
981
- def xywh(self):
1006
+ @lru_cache(maxsize=2)
1007
+ def xywh(self) -> Union[torch.Tensor, np.ndarray]:
982
1008
  """
983
1009
  Convert bounding boxes from [x1, y1, x2, y2] format to [x, y, width, height] format.
984
1010
 
985
1011
  Returns:
986
- (torch.Tensor | numpy.ndarray): Boxes in [x_center, y_center, width, height] format, where x_center, y_center are the coordinates of
987
- the center point of the bounding box, width, height are the dimensions of the bounding box and the
988
- shape of the returned tensor is (N, 4), where N is the number of boxes.
1012
+ (torch.Tensor | numpy.ndarray): Boxes in [x_center, y_center, width, height] format, where x_center,
1013
+ y_center are the coordinates of the center point of the bounding box, width, height are the
1014
+ dimensions of the bounding box and the shape of the returned tensor is (N, 4), where N is the
1015
+ number of boxes.
989
1016
 
990
1017
  Examples:
991
1018
  >>> boxes = Boxes(torch.tensor([[100, 50, 150, 100], [200, 150, 300, 250]]), orig_shape=(480, 640))
@@ -998,9 +1025,9 @@ class Boxes(BaseTensor):
998
1025
 
999
1026
  @property
1000
1027
  @lru_cache(maxsize=2)
1001
- def xyxyn(self):
1028
+ def xyxyn(self) -> Union[torch.Tensor, np.ndarray]:
1002
1029
  """
1003
- Returns normalized bounding box coordinates relative to the original image size.
1030
+ Return normalized bounding box coordinates relative to the original image size.
1004
1031
 
1005
1032
  This property calculates and returns the bounding box coordinates in [x1, y1, x2, y2] format,
1006
1033
  normalized to the range [0, 1] based on the original image dimensions.
@@ -1022,9 +1049,9 @@ class Boxes(BaseTensor):
1022
1049
 
1023
1050
  @property
1024
1051
  @lru_cache(maxsize=2)
1025
- def xywhn(self):
1052
+ def xywhn(self) -> Union[torch.Tensor, np.ndarray]:
1026
1053
  """
1027
- Returns normalized bounding boxes in [x, y, width, height] format.
1054
+ Return normalized bounding boxes in [x, y, width, height] format.
1028
1055
 
1029
1056
  This property calculates and returns the normalized bounding box coordinates in the format
1030
1057
  [x_center, y_center, width, height], where all values are relative to the original image dimensions.
@@ -1060,10 +1087,10 @@ class Masks(BaseTensor):
1060
1087
  xyn (List[numpy.ndarray]): A list of normalized segments.
1061
1088
 
1062
1089
  Methods:
1063
- cpu(): Returns a copy of the Masks object with the mask tensor on CPU memory.
1064
- numpy(): Returns a copy of the Masks object with the mask tensor as a numpy array.
1065
- cuda(): Returns a copy of the Masks object with the mask tensor on GPU memory.
1066
- to(*args, **kwargs): Returns a copy of the Masks object with the mask tensor on specified device and dtype.
1090
+ cpu: Return a copy of the Masks object with the mask tensor on CPU memory.
1091
+ numpy: Return a copy of the Masks object with the mask tensor as a numpy array.
1092
+ cuda: Return a copy of the Masks object with the mask tensor on GPU memory.
1093
+ to: Return a copy of the Masks object with the mask tensor on specified device and dtype.
1067
1094
 
1068
1095
  Examples:
1069
1096
  >>> masks_data = torch.rand(1, 160, 160)
@@ -1073,7 +1100,7 @@ class Masks(BaseTensor):
1073
1100
  >>> normalized_coords = masks.xyn
1074
1101
  """
1075
1102
 
1076
- def __init__(self, masks, orig_shape) -> None:
1103
+ def __init__(self, masks: Union[torch.Tensor, np.ndarray], orig_shape: Tuple[int, int]) -> None:
1077
1104
  """
1078
1105
  Initialize the Masks class with detection mask data and the original image shape.
1079
1106
 
@@ -1094,9 +1121,9 @@ class Masks(BaseTensor):
1094
1121
 
1095
1122
  @property
1096
1123
  @lru_cache(maxsize=1)
1097
- def xyn(self):
1124
+ def xyn(self) -> List[np.ndarray]:
1098
1125
  """
1099
- Returns normalized xy-coordinates of the segmentation masks.
1126
+ Return normalized xy-coordinates of the segmentation masks.
1100
1127
 
1101
1128
  This property calculates and caches the normalized xy-coordinates of the segmentation masks. The coordinates
1102
1129
  are normalized relative to the original image shape.
@@ -1119,9 +1146,9 @@ class Masks(BaseTensor):
1119
1146
 
1120
1147
  @property
1121
1148
  @lru_cache(maxsize=1)
1122
- def xy(self):
1149
+ def xy(self) -> List[np.ndarray]:
1123
1150
  """
1124
- Returns the [x, y] pixel coordinates for each segment in the mask tensor.
1151
+ Return the [x, y] pixel coordinates for each segment in the mask tensor.
1125
1152
 
1126
1153
  This property calculates and returns a list of pixel coordinates for each segmentation mask in the
1127
1154
  Masks object. The coordinates are scaled to match the original image dimensions.
@@ -1149,7 +1176,8 @@ class Keypoints(BaseTensor):
1149
1176
  A class for storing and manipulating detection keypoints.
1150
1177
 
1151
1178
  This class encapsulates functionality for handling keypoint data, including coordinate manipulation,
1152
- normalization, and confidence values.
1179
+ normalization, and confidence values. It supports keypoint detection results with optional visibility
1180
+ information.
1153
1181
 
1154
1182
  Attributes:
1155
1183
  data (torch.Tensor): The raw tensor containing keypoint data.
@@ -1160,10 +1188,10 @@ class Keypoints(BaseTensor):
1160
1188
  conf (torch.Tensor): Confidence values for each keypoint, if available.
1161
1189
 
1162
1190
  Methods:
1163
- cpu(): Returns a copy of the keypoints tensor on CPU memory.
1164
- numpy(): Returns a copy of the keypoints tensor as a numpy array.
1165
- cuda(): Returns a copy of the keypoints tensor on GPU memory.
1166
- to(*args, **kwargs): Returns a copy of the keypoints tensor with specified device and dtype.
1191
+ cpu: Return a copy of the keypoints tensor on CPU memory.
1192
+ numpy: Return a copy of the keypoints tensor as a numpy array.
1193
+ cuda: Return a copy of the keypoints tensor on GPU memory.
1194
+ to: Return a copy of the keypoints tensor with specified device and dtype.
1167
1195
 
1168
1196
  Examples:
1169
1197
  >>> import torch
@@ -1177,9 +1205,9 @@ class Keypoints(BaseTensor):
1177
1205
  """
1178
1206
 
1179
1207
  @smart_inference_mode() # avoid keypoints < conf in-place error
1180
- def __init__(self, keypoints, orig_shape) -> None:
1208
+ def __init__(self, keypoints: Union[torch.Tensor, np.ndarray], orig_shape: Tuple[int, int]) -> None:
1181
1209
  """
1182
- Initializes the Keypoints object with detection keypoints and original image dimensions.
1210
+ Initialize the Keypoints object with detection keypoints and original image dimensions.
1183
1211
 
1184
1212
  This method processes the input keypoints tensor, handling both 2D and 3D formats. For 3D tensors
1185
1213
  (x, y, confidence), it masks out low-confidence keypoints by setting their coordinates to zero.
@@ -1205,9 +1233,9 @@ class Keypoints(BaseTensor):
1205
1233
 
1206
1234
  @property
1207
1235
  @lru_cache(maxsize=1)
1208
- def xy(self):
1236
+ def xy(self) -> Union[torch.Tensor, np.ndarray]:
1209
1237
  """
1210
- Returns x, y coordinates of keypoints.
1238
+ Return x, y coordinates of keypoints.
1211
1239
 
1212
1240
  Returns:
1213
1241
  (torch.Tensor): A tensor containing the x, y coordinates of keypoints with shape (N, K, 2), where N is
@@ -1229,9 +1257,9 @@ class Keypoints(BaseTensor):
1229
1257
 
1230
1258
  @property
1231
1259
  @lru_cache(maxsize=1)
1232
- def xyn(self):
1260
+ def xyn(self) -> Union[torch.Tensor, np.ndarray]:
1233
1261
  """
1234
- Returns normalized coordinates (x, y) of keypoints relative to the original image size.
1262
+ Return normalized coordinates (x, y) of keypoints relative to the original image size.
1235
1263
 
1236
1264
  Returns:
1237
1265
  (torch.Tensor | numpy.ndarray): A tensor or array of shape (N, K, 2) containing normalized keypoint
@@ -1251,9 +1279,9 @@ class Keypoints(BaseTensor):
1251
1279
 
1252
1280
  @property
1253
1281
  @lru_cache(maxsize=1)
1254
- def conf(self):
1282
+ def conf(self) -> Optional[Union[torch.Tensor, np.ndarray]]:
1255
1283
  """
1256
- Returns confidence values for each keypoint.
1284
+ Return confidence values for each keypoint.
1257
1285
 
1258
1286
  Returns:
1259
1287
  (torch.Tensor | None): A tensor containing confidence scores for each keypoint if available,
@@ -1284,10 +1312,10 @@ class Probs(BaseTensor):
1284
1312
  top5conf (torch.Tensor | numpy.ndarray): Confidence scores of the top 5 classes.
1285
1313
 
1286
1314
  Methods:
1287
- cpu(): Returns a copy of the probabilities tensor on CPU memory.
1288
- numpy(): Returns a copy of the probabilities tensor as a numpy array.
1289
- cuda(): Returns a copy of the probabilities tensor on GPU memory.
1290
- to(*args, **kwargs): Returns a copy of the probabilities tensor with specified device and dtype.
1315
+ cpu: Return a copy of the probabilities tensor on CPU memory.
1316
+ numpy: Return a copy of the probabilities tensor as a numpy array.
1317
+ cuda: Return a copy of the probabilities tensor on GPU memory.
1318
+ to: Return a copy of the probabilities tensor with specified device and dtype.
1291
1319
 
1292
1320
  Examples:
1293
1321
  >>> probs = torch.tensor([0.1, 0.3, 0.6])
@@ -1302,7 +1330,7 @@ class Probs(BaseTensor):
1302
1330
  tensor([0.6000, 0.3000, 0.1000])
1303
1331
  """
1304
1332
 
1305
- def __init__(self, probs, orig_shape=None) -> None:
1333
+ def __init__(self, probs: Union[torch.Tensor, np.ndarray], orig_shape: Optional[Tuple[int, int]] = None) -> None:
1306
1334
  """
1307
1335
  Initialize the Probs class with classification probabilities.
1308
1336
 
@@ -1311,8 +1339,8 @@ class Probs(BaseTensor):
1311
1339
 
1312
1340
  Args:
1313
1341
  probs (torch.Tensor | np.ndarray): A 1D tensor or array of classification probabilities.
1314
- orig_shape (tuple | None): The original image shape as (height, width). Not used in this class but kept for
1315
- consistency with other result classes.
1342
+ orig_shape (tuple | None): The original image shape as (height, width). Not used in this class but kept
1343
+ for consistency with other result classes.
1316
1344
 
1317
1345
  Attributes:
1318
1346
  data (torch.Tensor | np.ndarray): The raw tensor or array containing classification probabilities.
@@ -1336,9 +1364,9 @@ class Probs(BaseTensor):
1336
1364
 
1337
1365
  @property
1338
1366
  @lru_cache(maxsize=1)
1339
- def top1(self):
1367
+ def top1(self) -> int:
1340
1368
  """
1341
- Returns the index of the class with the highest probability.
1369
+ Return the index of the class with the highest probability.
1342
1370
 
1343
1371
  Returns:
1344
1372
  (int): Index of the class with the highest probability.
@@ -1352,9 +1380,9 @@ class Probs(BaseTensor):
1352
1380
 
1353
1381
  @property
1354
1382
  @lru_cache(maxsize=1)
1355
- def top5(self):
1383
+ def top5(self) -> List[int]:
1356
1384
  """
1357
- Returns the indices of the top 5 class probabilities.
1385
+ Return the indices of the top 5 class probabilities.
1358
1386
 
1359
1387
  Returns:
1360
1388
  (List[int]): A list containing the indices of the top 5 class probabilities, sorted in descending order.
@@ -1368,9 +1396,9 @@ class Probs(BaseTensor):
1368
1396
 
1369
1397
  @property
1370
1398
  @lru_cache(maxsize=1)
1371
- def top1conf(self):
1399
+ def top1conf(self) -> Union[torch.Tensor, np.ndarray]:
1372
1400
  """
1373
- Returns the confidence score of the highest probability class.
1401
+ Return the confidence score of the highest probability class.
1374
1402
 
1375
1403
  This property retrieves the confidence score (probability) of the class with the highest predicted probability
1376
1404
  from the classification results.
@@ -1388,9 +1416,9 @@ class Probs(BaseTensor):
1388
1416
 
1389
1417
  @property
1390
1418
  @lru_cache(maxsize=1)
1391
- def top5conf(self):
1419
+ def top5conf(self) -> Union[torch.Tensor, np.ndarray]:
1392
1420
  """
1393
- Returns confidence scores for the top 5 classification predictions.
1421
+ Return confidence scores for the top 5 classification predictions.
1394
1422
 
1395
1423
  This property retrieves the confidence scores corresponding to the top 5 class probabilities
1396
1424
  predicted by the model. It provides a quick way to access the most likely class predictions
@@ -1414,7 +1442,8 @@ class OBB(BaseTensor):
1414
1442
  A class for storing and manipulating Oriented Bounding Boxes (OBB).
1415
1443
 
1416
1444
  This class provides functionality to handle oriented bounding boxes, including conversion between
1417
- different formats, normalization, and access to various properties of the boxes.
1445
+ different formats, normalization, and access to various properties of the boxes. It supports
1446
+ both tracking and non-tracking scenarios.
1418
1447
 
1419
1448
  Attributes:
1420
1449
  data (torch.Tensor): The raw OBB tensor containing box coordinates and associated data.
@@ -1429,10 +1458,10 @@ class OBB(BaseTensor):
1429
1458
  xyxy (torch.Tensor | numpy.ndarray): Axis-aligned bounding boxes in [x1, y1, x2, y2] format.
1430
1459
 
1431
1460
  Methods:
1432
- cpu(): Returns a copy of the OBB object with all tensors on CPU memory.
1433
- numpy(): Returns a copy of the OBB object with all tensors as numpy arrays.
1434
- cuda(): Returns a copy of the OBB object with all tensors on GPU memory.
1435
- to(*args, **kwargs): Returns a copy of the OBB object with tensors on specified device and dtype.
1461
+ cpu: Return a copy of the OBB object with all tensors on CPU memory.
1462
+ numpy: Return a copy of the OBB object with all tensors as numpy arrays.
1463
+ cuda: Return a copy of the OBB object with all tensors on GPU memory.
1464
+ to: Return a copy of the OBB object with tensors on specified device and dtype.
1436
1465
 
1437
1466
  Examples:
1438
1467
  >>> boxes = torch.tensor([[100, 50, 150, 100, 30, 0.9, 0]]) # xywhr, conf, cls
@@ -1442,7 +1471,7 @@ class OBB(BaseTensor):
1442
1471
  >>> print(obb.cls)
1443
1472
  """
1444
1473
 
1445
- def __init__(self, boxes, orig_shape) -> None:
1474
+ def __init__(self, boxes: Union[torch.Tensor, np.ndarray], orig_shape: Tuple[int, int]) -> None:
1446
1475
  """
1447
1476
  Initialize an OBB (Oriented Bounding Box) instance with oriented bounding box data and original image shape.
1448
1477
 
@@ -1479,9 +1508,9 @@ class OBB(BaseTensor):
1479
1508
  self.orig_shape = orig_shape
1480
1509
 
1481
1510
  @property
1482
- def xywhr(self):
1511
+ def xywhr(self) -> Union[torch.Tensor, np.ndarray]:
1483
1512
  """
1484
- Returns boxes in [x_center, y_center, width, height, rotation] format.
1513
+ Return boxes in [x_center, y_center, width, height, rotation] format.
1485
1514
 
1486
1515
  Returns:
1487
1516
  (torch.Tensor | numpy.ndarray): A tensor or numpy array containing the oriented bounding boxes with format
@@ -1497,9 +1526,9 @@ class OBB(BaseTensor):
1497
1526
  return self.data[:, :5]
1498
1527
 
1499
1528
  @property
1500
- def conf(self):
1529
+ def conf(self) -> Union[torch.Tensor, np.ndarray]:
1501
1530
  """
1502
- Returns the confidence scores for Oriented Bounding Boxes (OBBs).
1531
+ Return the confidence scores for Oriented Bounding Boxes (OBBs).
1503
1532
 
1504
1533
  This property retrieves the confidence values associated with each OBB detection. The confidence score
1505
1534
  represents the model's certainty in the detection.
@@ -1517,9 +1546,9 @@ class OBB(BaseTensor):
1517
1546
  return self.data[:, -2]
1518
1547
 
1519
1548
  @property
1520
- def cls(self):
1549
+ def cls(self) -> Union[torch.Tensor, np.ndarray]:
1521
1550
  """
1522
- Returns the class values of the oriented bounding boxes.
1551
+ Return the class values of the oriented bounding boxes.
1523
1552
 
1524
1553
  Returns:
1525
1554
  (torch.Tensor | numpy.ndarray): A tensor or numpy array containing the class values for each oriented
@@ -1535,9 +1564,9 @@ class OBB(BaseTensor):
1535
1564
  return self.data[:, -1]
1536
1565
 
1537
1566
  @property
1538
- def id(self):
1567
+ def id(self) -> Optional[Union[torch.Tensor, np.ndarray]]:
1539
1568
  """
1540
- Returns the tracking IDs of the oriented bounding boxes (if available).
1569
+ Return the tracking IDs of the oriented bounding boxes (if available).
1541
1570
 
1542
1571
  Returns:
1543
1572
  (torch.Tensor | numpy.ndarray | None): A tensor or numpy array containing the tracking IDs for each
@@ -1555,9 +1584,9 @@ class OBB(BaseTensor):
1555
1584
 
1556
1585
  @property
1557
1586
  @lru_cache(maxsize=2)
1558
- def xyxyxyxy(self):
1587
+ def xyxyxyxy(self) -> Union[torch.Tensor, np.ndarray]:
1559
1588
  """
1560
- Converts OBB format to 8-point (xyxyxyxy) coordinate format for rotated bounding boxes.
1589
+ Convert OBB format to 8-point (xyxyxyxy) coordinate format for rotated bounding boxes.
1561
1590
 
1562
1591
  Returns:
1563
1592
  (torch.Tensor | numpy.ndarray): Rotated bounding boxes in xyxyxyxy format with shape (N, 4, 2), where N is
@@ -1574,9 +1603,9 @@ class OBB(BaseTensor):
1574
1603
 
1575
1604
  @property
1576
1605
  @lru_cache(maxsize=2)
1577
- def xyxyxyxyn(self):
1606
+ def xyxyxyxyn(self) -> Union[torch.Tensor, np.ndarray]:
1578
1607
  """
1579
- Converts rotated bounding boxes to normalized xyxyxyxy format.
1608
+ Convert rotated bounding boxes to normalized xyxyxyxy format.
1580
1609
 
1581
1610
  Returns:
1582
1611
  (torch.Tensor | numpy.ndarray): Normalized rotated bounding boxes in xyxyxyxy format with shape (N, 4, 2),
@@ -1596,9 +1625,9 @@ class OBB(BaseTensor):
1596
1625
 
1597
1626
  @property
1598
1627
  @lru_cache(maxsize=2)
1599
- def xyxy(self):
1628
+ def xyxy(self) -> Union[torch.Tensor, np.ndarray]:
1600
1629
  """
1601
- Converts oriented bounding boxes (OBB) to axis-aligned bounding boxes in xyxy format.
1630
+ Convert oriented bounding boxes (OBB) to axis-aligned bounding boxes in xyxy format.
1602
1631
 
1603
1632
  This property calculates the minimal enclosing rectangle for each oriented bounding box and returns it in
1604
1633
  xyxy format (x1, y1, x2, y2). This is useful for operations that require axis-aligned bounding boxes, such