ultralytics 8.3.143__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.
- tests/conftest.py +7 -24
- tests/test_cli.py +1 -1
- tests/test_cuda.py +7 -2
- tests/test_engine.py +7 -8
- tests/test_exports.py +16 -16
- tests/test_integrations.py +1 -1
- tests/test_solutions.py +11 -11
- ultralytics/__init__.py +1 -1
- ultralytics/cfg/__init__.py +16 -13
- ultralytics/data/annotator.py +6 -5
- ultralytics/data/augment.py +127 -126
- ultralytics/data/base.py +54 -51
- ultralytics/data/build.py +47 -23
- ultralytics/data/converter.py +47 -43
- ultralytics/data/dataset.py +51 -50
- ultralytics/data/loaders.py +77 -44
- ultralytics/data/split.py +22 -9
- ultralytics/data/split_dota.py +63 -39
- ultralytics/data/utils.py +59 -39
- ultralytics/engine/exporter.py +79 -27
- ultralytics/engine/model.py +39 -39
- ultralytics/engine/predictor.py +37 -28
- ultralytics/engine/results.py +187 -157
- ultralytics/engine/trainer.py +36 -19
- ultralytics/engine/tuner.py +12 -9
- ultralytics/engine/validator.py +7 -9
- ultralytics/hub/__init__.py +11 -13
- ultralytics/hub/auth.py +22 -2
- ultralytics/hub/google/__init__.py +19 -19
- ultralytics/hub/session.py +37 -51
- ultralytics/hub/utils.py +19 -5
- ultralytics/models/fastsam/model.py +30 -12
- ultralytics/models/fastsam/predict.py +5 -6
- ultralytics/models/fastsam/utils.py +3 -3
- ultralytics/models/fastsam/val.py +10 -6
- ultralytics/models/nas/model.py +9 -5
- ultralytics/models/nas/predict.py +6 -6
- ultralytics/models/nas/val.py +3 -3
- ultralytics/models/rtdetr/model.py +7 -6
- ultralytics/models/rtdetr/predict.py +14 -7
- ultralytics/models/rtdetr/train.py +10 -4
- ultralytics/models/rtdetr/val.py +36 -9
- ultralytics/models/sam/amg.py +30 -12
- ultralytics/models/sam/build.py +22 -22
- ultralytics/models/sam/model.py +10 -9
- ultralytics/models/sam/modules/blocks.py +76 -80
- ultralytics/models/sam/modules/decoders.py +6 -8
- ultralytics/models/sam/modules/encoders.py +23 -26
- ultralytics/models/sam/modules/memory_attention.py +13 -1
- ultralytics/models/sam/modules/sam.py +57 -26
- ultralytics/models/sam/modules/tiny_encoder.py +232 -237
- ultralytics/models/sam/modules/transformer.py +13 -13
- ultralytics/models/sam/modules/utils.py +11 -19
- ultralytics/models/sam/predict.py +114 -101
- ultralytics/models/utils/loss.py +98 -77
- ultralytics/models/utils/ops.py +116 -67
- ultralytics/models/yolo/classify/predict.py +5 -5
- ultralytics/models/yolo/classify/train.py +32 -28
- ultralytics/models/yolo/classify/val.py +7 -8
- ultralytics/models/yolo/detect/predict.py +1 -0
- ultralytics/models/yolo/detect/train.py +15 -14
- ultralytics/models/yolo/detect/val.py +37 -36
- ultralytics/models/yolo/model.py +106 -23
- ultralytics/models/yolo/obb/predict.py +3 -4
- ultralytics/models/yolo/obb/train.py +14 -6
- ultralytics/models/yolo/obb/val.py +29 -23
- ultralytics/models/yolo/pose/predict.py +9 -8
- ultralytics/models/yolo/pose/train.py +24 -16
- ultralytics/models/yolo/pose/val.py +44 -26
- ultralytics/models/yolo/segment/predict.py +5 -5
- ultralytics/models/yolo/segment/train.py +11 -7
- ultralytics/models/yolo/segment/val.py +2 -2
- ultralytics/models/yolo/world/train.py +33 -23
- ultralytics/models/yolo/world/train_world.py +11 -3
- ultralytics/models/yolo/yoloe/predict.py +11 -11
- ultralytics/models/yolo/yoloe/train.py +73 -21
- ultralytics/models/yolo/yoloe/train_seg.py +10 -7
- ultralytics/models/yolo/yoloe/val.py +42 -18
- ultralytics/nn/autobackend.py +59 -15
- ultralytics/nn/modules/__init__.py +4 -4
- ultralytics/nn/modules/activation.py +4 -1
- ultralytics/nn/modules/block.py +178 -111
- ultralytics/nn/modules/conv.py +6 -5
- ultralytics/nn/modules/head.py +469 -121
- ultralytics/nn/modules/transformer.py +147 -58
- ultralytics/nn/tasks.py +227 -20
- ultralytics/nn/text_model.py +30 -33
- ultralytics/solutions/ai_gym.py +1 -1
- ultralytics/solutions/analytics.py +7 -4
- ultralytics/solutions/config.py +10 -10
- ultralytics/solutions/distance_calculation.py +11 -10
- ultralytics/solutions/heatmap.py +1 -1
- ultralytics/solutions/instance_segmentation.py +6 -3
- ultralytics/solutions/object_blurrer.py +3 -3
- ultralytics/solutions/object_counter.py +15 -7
- ultralytics/solutions/object_cropper.py +3 -2
- ultralytics/solutions/parking_management.py +29 -28
- ultralytics/solutions/queue_management.py +6 -6
- ultralytics/solutions/region_counter.py +10 -3
- ultralytics/solutions/security_alarm.py +3 -3
- ultralytics/solutions/similarity_search.py +85 -24
- ultralytics/solutions/solutions.py +184 -75
- ultralytics/solutions/speed_estimation.py +28 -22
- ultralytics/solutions/streamlit_inference.py +17 -12
- ultralytics/solutions/trackzone.py +4 -4
- ultralytics/trackers/basetrack.py +16 -23
- ultralytics/trackers/bot_sort.py +30 -20
- ultralytics/trackers/byte_tracker.py +70 -64
- ultralytics/trackers/track.py +4 -8
- ultralytics/trackers/utils/gmc.py +31 -58
- ultralytics/trackers/utils/kalman_filter.py +37 -37
- ultralytics/trackers/utils/matching.py +1 -1
- ultralytics/utils/__init__.py +105 -89
- ultralytics/utils/autobatch.py +16 -3
- ultralytics/utils/autodevice.py +54 -24
- ultralytics/utils/benchmarks.py +42 -28
- ultralytics/utils/callbacks/base.py +3 -3
- ultralytics/utils/callbacks/clearml.py +9 -9
- ultralytics/utils/callbacks/comet.py +67 -25
- ultralytics/utils/callbacks/dvc.py +7 -10
- ultralytics/utils/callbacks/mlflow.py +2 -5
- ultralytics/utils/callbacks/neptune.py +7 -13
- ultralytics/utils/callbacks/raytune.py +1 -1
- ultralytics/utils/callbacks/tensorboard.py +5 -6
- ultralytics/utils/callbacks/wb.py +14 -14
- ultralytics/utils/checks.py +14 -13
- ultralytics/utils/dist.py +5 -5
- ultralytics/utils/downloads.py +94 -67
- ultralytics/utils/errors.py +5 -5
- ultralytics/utils/export.py +61 -47
- ultralytics/utils/files.py +23 -22
- ultralytics/utils/instance.py +48 -52
- ultralytics/utils/loss.py +78 -40
- ultralytics/utils/metrics.py +186 -130
- ultralytics/utils/ops.py +186 -190
- ultralytics/utils/patches.py +15 -17
- ultralytics/utils/plotting.py +71 -27
- ultralytics/utils/tal.py +21 -15
- ultralytics/utils/torch_utils.py +53 -50
- ultralytics/utils/triton.py +5 -4
- ultralytics/utils/tuner.py +5 -5
- {ultralytics-8.3.143.dist-info → ultralytics-8.3.144.dist-info}/METADATA +1 -1
- ultralytics-8.3.144.dist-info/RECORD +272 -0
- ultralytics-8.3.143.dist-info/RECORD +0 -272
- {ultralytics-8.3.143.dist-info → ultralytics-8.3.144.dist-info}/WHEEL +0 -0
- {ultralytics-8.3.143.dist-info → ultralytics-8.3.144.dist-info}/entry_points.txt +0 -0
- {ultralytics-8.3.143.dist-info → ultralytics-8.3.144.dist-info}/licenses/LICENSE +0 -0
- {ultralytics-8.3.143.dist-info → ultralytics-8.3.144.dist-info}/top_level.txt +0 -0
ultralytics/engine/results.py
CHANGED
@@ -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:
|
32
|
-
cuda:
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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)
|
156
|
+
def __len__(self) -> int:
|
152
157
|
"""
|
153
|
-
|
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
|
-
|
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
|
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:
|
208
|
-
cpu:
|
209
|
-
numpy:
|
210
|
-
cuda:
|
211
|
-
to:
|
212
|
-
new:
|
213
|
-
plot:
|
214
|
-
show:
|
215
|
-
save:
|
216
|
-
verbose:
|
217
|
-
save_txt:
|
218
|
-
save_crop:
|
219
|
-
summary:
|
220
|
-
to_df:
|
221
|
-
to_json:
|
222
|
-
to_csv:
|
223
|
-
to_xml:
|
224
|
-
to_html:
|
225
|
-
to_sql:
|
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,
|
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(
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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 (
|
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.
|
@@ -611,9 +633,9 @@ class Results(SimpleClass, DataExportMixin):
|
|
611
633
|
"""
|
612
634
|
self.plot(show=True, *args, **kwargs)
|
613
635
|
|
614
|
-
def save(self, filename=None, *args, **kwargs):
|
636
|
+
def save(self, filename: Optional[str] = None, *args, **kwargs) -> str:
|
615
637
|
"""
|
616
|
-
|
638
|
+
Save annotated inference results image to file.
|
617
639
|
|
618
640
|
This method plots the detection results on the original image and saves the annotated image to a file. It
|
619
641
|
utilizes the `plot` method to generate the annotated image and then saves it to the specified filename.
|
@@ -624,6 +646,9 @@ class Results(SimpleClass, DataExportMixin):
|
|
624
646
|
*args (Any): Variable length argument list to be passed to the `plot` method.
|
625
647
|
**kwargs (Any): Arbitrary keyword arguments to be passed to the `plot` method.
|
626
648
|
|
649
|
+
Returns:
|
650
|
+
(str): The filename where the image was saved.
|
651
|
+
|
627
652
|
Examples:
|
628
653
|
>>> results = model("path/to/image.jpg")
|
629
654
|
>>> for result in results:
|
@@ -637,9 +662,9 @@ class Results(SimpleClass, DataExportMixin):
|
|
637
662
|
self.plot(save=True, filename=filename, *args, **kwargs)
|
638
663
|
return filename
|
639
664
|
|
640
|
-
def verbose(self):
|
665
|
+
def verbose(self) -> str:
|
641
666
|
"""
|
642
|
-
|
667
|
+
Return a log string for each task in the results, detailing detection and classification outcomes.
|
643
668
|
|
644
669
|
This method generates a human-readable string summarizing the detection and classification results. It includes
|
645
670
|
the number of detections for each class and the top probabilities for classification tasks.
|
@@ -669,7 +694,7 @@ class Results(SimpleClass, DataExportMixin):
|
|
669
694
|
counts = boxes.cls.int().bincount()
|
670
695
|
return "".join(f"{n} {self.names[i]}{'s' * (n > 1)}, " for i, n in enumerate(counts) if n > 0)
|
671
696
|
|
672
|
-
def save_txt(self, txt_file, save_conf=False):
|
697
|
+
def save_txt(self, txt_file: Union[str, Path], save_conf: bool = False) -> str:
|
673
698
|
"""
|
674
699
|
Save detection results to a text file.
|
675
700
|
|
@@ -724,16 +749,18 @@ class Results(SimpleClass, DataExportMixin):
|
|
724
749
|
with open(txt_file, "a", encoding="utf-8") as f:
|
725
750
|
f.writelines(text + "\n" for text in texts)
|
726
751
|
|
727
|
-
|
752
|
+
return str(txt_file)
|
753
|
+
|
754
|
+
def save_crop(self, save_dir: Union[str, Path], file_name: Union[str, Path] = Path("im.jpg")):
|
728
755
|
"""
|
729
|
-
|
756
|
+
Save cropped detection images to specified directory.
|
730
757
|
|
731
758
|
This method saves cropped images of detected objects to a specified directory. Each crop is saved in a
|
732
759
|
subdirectory named after the object's class, with the filename based on the input file_name.
|
733
760
|
|
734
761
|
Args:
|
735
762
|
save_dir (str | Path): Directory path where cropped images will be saved.
|
736
|
-
file_name (str | Path): Base filename for the saved cropped images.
|
763
|
+
file_name (str | Path): Base filename for the saved cropped images.
|
737
764
|
|
738
765
|
Notes:
|
739
766
|
- This method does not support Classify or Oriented Bounding Box (OBB) tasks.
|
@@ -760,9 +787,9 @@ class Results(SimpleClass, DataExportMixin):
|
|
760
787
|
BGR=True,
|
761
788
|
)
|
762
789
|
|
763
|
-
def summary(self, normalize=False, decimals=5):
|
790
|
+
def summary(self, normalize: bool = False, decimals: int = 5) -> List[Dict[str, Any]]:
|
764
791
|
"""
|
765
|
-
|
792
|
+
Convert inference results to a summarized dictionary with optional normalization for box coordinates.
|
766
793
|
|
767
794
|
This method creates a list of detection dictionaries, each containing information about a single
|
768
795
|
detection or classification result. For classification tasks, it returns the top class and its
|
@@ -831,9 +858,9 @@ class Boxes(BaseTensor):
|
|
831
858
|
"""
|
832
859
|
A class for managing and manipulating detection boxes.
|
833
860
|
|
834
|
-
This class provides functionality for handling detection boxes, including their coordinates,
|
835
|
-
class labels, and optional tracking IDs. It supports various box formats and offers
|
836
|
-
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.
|
837
864
|
|
838
865
|
Attributes:
|
839
866
|
data (torch.Tensor | numpy.ndarray): The raw tensor containing detection boxes and associated data.
|
@@ -848,10 +875,10 @@ class Boxes(BaseTensor):
|
|
848
875
|
xywhn (torch.Tensor | numpy.ndarray): Normalized [x, y, width, height] boxes relative to orig_shape.
|
849
876
|
|
850
877
|
Methods:
|
851
|
-
cpu
|
852
|
-
numpy
|
853
|
-
cuda
|
854
|
-
to
|
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.
|
855
882
|
|
856
883
|
Examples:
|
857
884
|
>>> import torch
|
@@ -864,7 +891,7 @@ class Boxes(BaseTensor):
|
|
864
891
|
>>> print(boxes.xywhn)
|
865
892
|
"""
|
866
893
|
|
867
|
-
def __init__(self, boxes, orig_shape) -> None:
|
894
|
+
def __init__(self, boxes: Union[torch.Tensor, np.ndarray], orig_shape: Tuple[int, int]) -> None:
|
868
895
|
"""
|
869
896
|
Initialize the Boxes class with detection box data and the original image shape.
|
870
897
|
|
@@ -900,9 +927,9 @@ class Boxes(BaseTensor):
|
|
900
927
|
self.orig_shape = orig_shape
|
901
928
|
|
902
929
|
@property
|
903
|
-
def xyxy(self):
|
930
|
+
def xyxy(self) -> Union[torch.Tensor, np.ndarray]:
|
904
931
|
"""
|
905
|
-
|
932
|
+
Return bounding boxes in [x1, y1, x2, y2] format.
|
906
933
|
|
907
934
|
Returns:
|
908
935
|
(torch.Tensor | numpy.ndarray): A tensor or numpy array of shape (n, 4) containing bounding box
|
@@ -917,9 +944,9 @@ class Boxes(BaseTensor):
|
|
917
944
|
return self.data[:, :4]
|
918
945
|
|
919
946
|
@property
|
920
|
-
def conf(self):
|
947
|
+
def conf(self) -> Union[torch.Tensor, np.ndarray]:
|
921
948
|
"""
|
922
|
-
|
949
|
+
Return the confidence scores for each detection box.
|
923
950
|
|
924
951
|
Returns:
|
925
952
|
(torch.Tensor | numpy.ndarray): A 1D tensor or array containing confidence scores for each detection,
|
@@ -934,9 +961,9 @@ class Boxes(BaseTensor):
|
|
934
961
|
return self.data[:, -2]
|
935
962
|
|
936
963
|
@property
|
937
|
-
def cls(self):
|
964
|
+
def cls(self) -> Union[torch.Tensor, np.ndarray]:
|
938
965
|
"""
|
939
|
-
|
966
|
+
Return the class ID tensor representing category predictions for each bounding box.
|
940
967
|
|
941
968
|
Returns:
|
942
969
|
(torch.Tensor | numpy.ndarray): A tensor or numpy array containing the class IDs for each detection box.
|
@@ -951,9 +978,9 @@ class Boxes(BaseTensor):
|
|
951
978
|
return self.data[:, -1]
|
952
979
|
|
953
980
|
@property
|
954
|
-
def id(self):
|
981
|
+
def id(self) -> Optional[Union[torch.Tensor, np.ndarray]]:
|
955
982
|
"""
|
956
|
-
|
983
|
+
Return the tracking IDs for each detection box if available.
|
957
984
|
|
958
985
|
Returns:
|
959
986
|
(torch.Tensor | None): A tensor containing tracking IDs for each box if tracking is enabled,
|
@@ -976,15 +1003,16 @@ class Boxes(BaseTensor):
|
|
976
1003
|
return self.data[:, -3] if self.is_track else None
|
977
1004
|
|
978
1005
|
@property
|
979
|
-
@lru_cache(maxsize=2)
|
980
|
-
def xywh(self):
|
1006
|
+
@lru_cache(maxsize=2)
|
1007
|
+
def xywh(self) -> Union[torch.Tensor, np.ndarray]:
|
981
1008
|
"""
|
982
1009
|
Convert bounding boxes from [x1, y1, x2, y2] format to [x, y, width, height] format.
|
983
1010
|
|
984
1011
|
Returns:
|
985
|
-
(torch.Tensor | numpy.ndarray): Boxes in [x_center, y_center, width, height] format, where x_center,
|
986
|
-
the center point of the bounding box, width, height are the
|
987
|
-
shape of the returned tensor is (N, 4), where N is the
|
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.
|
988
1016
|
|
989
1017
|
Examples:
|
990
1018
|
>>> boxes = Boxes(torch.tensor([[100, 50, 150, 100], [200, 150, 300, 250]]), orig_shape=(480, 640))
|
@@ -997,9 +1025,9 @@ class Boxes(BaseTensor):
|
|
997
1025
|
|
998
1026
|
@property
|
999
1027
|
@lru_cache(maxsize=2)
|
1000
|
-
def xyxyn(self):
|
1028
|
+
def xyxyn(self) -> Union[torch.Tensor, np.ndarray]:
|
1001
1029
|
"""
|
1002
|
-
|
1030
|
+
Return normalized bounding box coordinates relative to the original image size.
|
1003
1031
|
|
1004
1032
|
This property calculates and returns the bounding box coordinates in [x1, y1, x2, y2] format,
|
1005
1033
|
normalized to the range [0, 1] based on the original image dimensions.
|
@@ -1021,9 +1049,9 @@ class Boxes(BaseTensor):
|
|
1021
1049
|
|
1022
1050
|
@property
|
1023
1051
|
@lru_cache(maxsize=2)
|
1024
|
-
def xywhn(self):
|
1052
|
+
def xywhn(self) -> Union[torch.Tensor, np.ndarray]:
|
1025
1053
|
"""
|
1026
|
-
|
1054
|
+
Return normalized bounding boxes in [x, y, width, height] format.
|
1027
1055
|
|
1028
1056
|
This property calculates and returns the normalized bounding box coordinates in the format
|
1029
1057
|
[x_center, y_center, width, height], where all values are relative to the original image dimensions.
|
@@ -1059,10 +1087,10 @@ class Masks(BaseTensor):
|
|
1059
1087
|
xyn (List[numpy.ndarray]): A list of normalized segments.
|
1060
1088
|
|
1061
1089
|
Methods:
|
1062
|
-
cpu
|
1063
|
-
numpy
|
1064
|
-
cuda
|
1065
|
-
to
|
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.
|
1066
1094
|
|
1067
1095
|
Examples:
|
1068
1096
|
>>> masks_data = torch.rand(1, 160, 160)
|
@@ -1072,7 +1100,7 @@ class Masks(BaseTensor):
|
|
1072
1100
|
>>> normalized_coords = masks.xyn
|
1073
1101
|
"""
|
1074
1102
|
|
1075
|
-
def __init__(self, masks, orig_shape) -> None:
|
1103
|
+
def __init__(self, masks: Union[torch.Tensor, np.ndarray], orig_shape: Tuple[int, int]) -> None:
|
1076
1104
|
"""
|
1077
1105
|
Initialize the Masks class with detection mask data and the original image shape.
|
1078
1106
|
|
@@ -1093,9 +1121,9 @@ class Masks(BaseTensor):
|
|
1093
1121
|
|
1094
1122
|
@property
|
1095
1123
|
@lru_cache(maxsize=1)
|
1096
|
-
def xyn(self):
|
1124
|
+
def xyn(self) -> List[np.ndarray]:
|
1097
1125
|
"""
|
1098
|
-
|
1126
|
+
Return normalized xy-coordinates of the segmentation masks.
|
1099
1127
|
|
1100
1128
|
This property calculates and caches the normalized xy-coordinates of the segmentation masks. The coordinates
|
1101
1129
|
are normalized relative to the original image shape.
|
@@ -1118,9 +1146,9 @@ class Masks(BaseTensor):
|
|
1118
1146
|
|
1119
1147
|
@property
|
1120
1148
|
@lru_cache(maxsize=1)
|
1121
|
-
def xy(self):
|
1149
|
+
def xy(self) -> List[np.ndarray]:
|
1122
1150
|
"""
|
1123
|
-
|
1151
|
+
Return the [x, y] pixel coordinates for each segment in the mask tensor.
|
1124
1152
|
|
1125
1153
|
This property calculates and returns a list of pixel coordinates for each segmentation mask in the
|
1126
1154
|
Masks object. The coordinates are scaled to match the original image dimensions.
|
@@ -1148,7 +1176,8 @@ class Keypoints(BaseTensor):
|
|
1148
1176
|
A class for storing and manipulating detection keypoints.
|
1149
1177
|
|
1150
1178
|
This class encapsulates functionality for handling keypoint data, including coordinate manipulation,
|
1151
|
-
normalization, and confidence values.
|
1179
|
+
normalization, and confidence values. It supports keypoint detection results with optional visibility
|
1180
|
+
information.
|
1152
1181
|
|
1153
1182
|
Attributes:
|
1154
1183
|
data (torch.Tensor): The raw tensor containing keypoint data.
|
@@ -1159,10 +1188,10 @@ class Keypoints(BaseTensor):
|
|
1159
1188
|
conf (torch.Tensor): Confidence values for each keypoint, if available.
|
1160
1189
|
|
1161
1190
|
Methods:
|
1162
|
-
cpu
|
1163
|
-
numpy
|
1164
|
-
cuda
|
1165
|
-
to
|
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.
|
1166
1195
|
|
1167
1196
|
Examples:
|
1168
1197
|
>>> import torch
|
@@ -1176,9 +1205,9 @@ class Keypoints(BaseTensor):
|
|
1176
1205
|
"""
|
1177
1206
|
|
1178
1207
|
@smart_inference_mode() # avoid keypoints < conf in-place error
|
1179
|
-
def __init__(self, keypoints, orig_shape) -> None:
|
1208
|
+
def __init__(self, keypoints: Union[torch.Tensor, np.ndarray], orig_shape: Tuple[int, int]) -> None:
|
1180
1209
|
"""
|
1181
|
-
|
1210
|
+
Initialize the Keypoints object with detection keypoints and original image dimensions.
|
1182
1211
|
|
1183
1212
|
This method processes the input keypoints tensor, handling both 2D and 3D formats. For 3D tensors
|
1184
1213
|
(x, y, confidence), it masks out low-confidence keypoints by setting their coordinates to zero.
|
@@ -1204,9 +1233,9 @@ class Keypoints(BaseTensor):
|
|
1204
1233
|
|
1205
1234
|
@property
|
1206
1235
|
@lru_cache(maxsize=1)
|
1207
|
-
def xy(self):
|
1236
|
+
def xy(self) -> Union[torch.Tensor, np.ndarray]:
|
1208
1237
|
"""
|
1209
|
-
|
1238
|
+
Return x, y coordinates of keypoints.
|
1210
1239
|
|
1211
1240
|
Returns:
|
1212
1241
|
(torch.Tensor): A tensor containing the x, y coordinates of keypoints with shape (N, K, 2), where N is
|
@@ -1228,9 +1257,9 @@ class Keypoints(BaseTensor):
|
|
1228
1257
|
|
1229
1258
|
@property
|
1230
1259
|
@lru_cache(maxsize=1)
|
1231
|
-
def xyn(self):
|
1260
|
+
def xyn(self) -> Union[torch.Tensor, np.ndarray]:
|
1232
1261
|
"""
|
1233
|
-
|
1262
|
+
Return normalized coordinates (x, y) of keypoints relative to the original image size.
|
1234
1263
|
|
1235
1264
|
Returns:
|
1236
1265
|
(torch.Tensor | numpy.ndarray): A tensor or array of shape (N, K, 2) containing normalized keypoint
|
@@ -1250,9 +1279,9 @@ class Keypoints(BaseTensor):
|
|
1250
1279
|
|
1251
1280
|
@property
|
1252
1281
|
@lru_cache(maxsize=1)
|
1253
|
-
def conf(self):
|
1282
|
+
def conf(self) -> Optional[Union[torch.Tensor, np.ndarray]]:
|
1254
1283
|
"""
|
1255
|
-
|
1284
|
+
Return confidence values for each keypoint.
|
1256
1285
|
|
1257
1286
|
Returns:
|
1258
1287
|
(torch.Tensor | None): A tensor containing confidence scores for each keypoint if available,
|
@@ -1283,10 +1312,10 @@ class Probs(BaseTensor):
|
|
1283
1312
|
top5conf (torch.Tensor | numpy.ndarray): Confidence scores of the top 5 classes.
|
1284
1313
|
|
1285
1314
|
Methods:
|
1286
|
-
cpu
|
1287
|
-
numpy
|
1288
|
-
cuda
|
1289
|
-
to
|
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.
|
1290
1319
|
|
1291
1320
|
Examples:
|
1292
1321
|
>>> probs = torch.tensor([0.1, 0.3, 0.6])
|
@@ -1301,7 +1330,7 @@ class Probs(BaseTensor):
|
|
1301
1330
|
tensor([0.6000, 0.3000, 0.1000])
|
1302
1331
|
"""
|
1303
1332
|
|
1304
|
-
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:
|
1305
1334
|
"""
|
1306
1335
|
Initialize the Probs class with classification probabilities.
|
1307
1336
|
|
@@ -1310,8 +1339,8 @@ class Probs(BaseTensor):
|
|
1310
1339
|
|
1311
1340
|
Args:
|
1312
1341
|
probs (torch.Tensor | np.ndarray): A 1D tensor or array of classification probabilities.
|
1313
|
-
orig_shape (tuple | None): The original image shape as (height, width). Not used in this class but kept
|
1314
|
-
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.
|
1315
1344
|
|
1316
1345
|
Attributes:
|
1317
1346
|
data (torch.Tensor | np.ndarray): The raw tensor or array containing classification probabilities.
|
@@ -1335,9 +1364,9 @@ class Probs(BaseTensor):
|
|
1335
1364
|
|
1336
1365
|
@property
|
1337
1366
|
@lru_cache(maxsize=1)
|
1338
|
-
def top1(self):
|
1367
|
+
def top1(self) -> int:
|
1339
1368
|
"""
|
1340
|
-
|
1369
|
+
Return the index of the class with the highest probability.
|
1341
1370
|
|
1342
1371
|
Returns:
|
1343
1372
|
(int): Index of the class with the highest probability.
|
@@ -1351,9 +1380,9 @@ class Probs(BaseTensor):
|
|
1351
1380
|
|
1352
1381
|
@property
|
1353
1382
|
@lru_cache(maxsize=1)
|
1354
|
-
def top5(self):
|
1383
|
+
def top5(self) -> List[int]:
|
1355
1384
|
"""
|
1356
|
-
|
1385
|
+
Return the indices of the top 5 class probabilities.
|
1357
1386
|
|
1358
1387
|
Returns:
|
1359
1388
|
(List[int]): A list containing the indices of the top 5 class probabilities, sorted in descending order.
|
@@ -1367,9 +1396,9 @@ class Probs(BaseTensor):
|
|
1367
1396
|
|
1368
1397
|
@property
|
1369
1398
|
@lru_cache(maxsize=1)
|
1370
|
-
def top1conf(self):
|
1399
|
+
def top1conf(self) -> Union[torch.Tensor, np.ndarray]:
|
1371
1400
|
"""
|
1372
|
-
|
1401
|
+
Return the confidence score of the highest probability class.
|
1373
1402
|
|
1374
1403
|
This property retrieves the confidence score (probability) of the class with the highest predicted probability
|
1375
1404
|
from the classification results.
|
@@ -1387,9 +1416,9 @@ class Probs(BaseTensor):
|
|
1387
1416
|
|
1388
1417
|
@property
|
1389
1418
|
@lru_cache(maxsize=1)
|
1390
|
-
def top5conf(self):
|
1419
|
+
def top5conf(self) -> Union[torch.Tensor, np.ndarray]:
|
1391
1420
|
"""
|
1392
|
-
|
1421
|
+
Return confidence scores for the top 5 classification predictions.
|
1393
1422
|
|
1394
1423
|
This property retrieves the confidence scores corresponding to the top 5 class probabilities
|
1395
1424
|
predicted by the model. It provides a quick way to access the most likely class predictions
|
@@ -1413,7 +1442,8 @@ class OBB(BaseTensor):
|
|
1413
1442
|
A class for storing and manipulating Oriented Bounding Boxes (OBB).
|
1414
1443
|
|
1415
1444
|
This class provides functionality to handle oriented bounding boxes, including conversion between
|
1416
|
-
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.
|
1417
1447
|
|
1418
1448
|
Attributes:
|
1419
1449
|
data (torch.Tensor): The raw OBB tensor containing box coordinates and associated data.
|
@@ -1428,10 +1458,10 @@ class OBB(BaseTensor):
|
|
1428
1458
|
xyxy (torch.Tensor | numpy.ndarray): Axis-aligned bounding boxes in [x1, y1, x2, y2] format.
|
1429
1459
|
|
1430
1460
|
Methods:
|
1431
|
-
cpu
|
1432
|
-
numpy
|
1433
|
-
cuda
|
1434
|
-
to
|
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.
|
1435
1465
|
|
1436
1466
|
Examples:
|
1437
1467
|
>>> boxes = torch.tensor([[100, 50, 150, 100, 30, 0.9, 0]]) # xywhr, conf, cls
|
@@ -1441,7 +1471,7 @@ class OBB(BaseTensor):
|
|
1441
1471
|
>>> print(obb.cls)
|
1442
1472
|
"""
|
1443
1473
|
|
1444
|
-
def __init__(self, boxes, orig_shape) -> None:
|
1474
|
+
def __init__(self, boxes: Union[torch.Tensor, np.ndarray], orig_shape: Tuple[int, int]) -> None:
|
1445
1475
|
"""
|
1446
1476
|
Initialize an OBB (Oriented Bounding Box) instance with oriented bounding box data and original image shape.
|
1447
1477
|
|
@@ -1478,9 +1508,9 @@ class OBB(BaseTensor):
|
|
1478
1508
|
self.orig_shape = orig_shape
|
1479
1509
|
|
1480
1510
|
@property
|
1481
|
-
def xywhr(self):
|
1511
|
+
def xywhr(self) -> Union[torch.Tensor, np.ndarray]:
|
1482
1512
|
"""
|
1483
|
-
|
1513
|
+
Return boxes in [x_center, y_center, width, height, rotation] format.
|
1484
1514
|
|
1485
1515
|
Returns:
|
1486
1516
|
(torch.Tensor | numpy.ndarray): A tensor or numpy array containing the oriented bounding boxes with format
|
@@ -1496,9 +1526,9 @@ class OBB(BaseTensor):
|
|
1496
1526
|
return self.data[:, :5]
|
1497
1527
|
|
1498
1528
|
@property
|
1499
|
-
def conf(self):
|
1529
|
+
def conf(self) -> Union[torch.Tensor, np.ndarray]:
|
1500
1530
|
"""
|
1501
|
-
|
1531
|
+
Return the confidence scores for Oriented Bounding Boxes (OBBs).
|
1502
1532
|
|
1503
1533
|
This property retrieves the confidence values associated with each OBB detection. The confidence score
|
1504
1534
|
represents the model's certainty in the detection.
|
@@ -1516,9 +1546,9 @@ class OBB(BaseTensor):
|
|
1516
1546
|
return self.data[:, -2]
|
1517
1547
|
|
1518
1548
|
@property
|
1519
|
-
def cls(self):
|
1549
|
+
def cls(self) -> Union[torch.Tensor, np.ndarray]:
|
1520
1550
|
"""
|
1521
|
-
|
1551
|
+
Return the class values of the oriented bounding boxes.
|
1522
1552
|
|
1523
1553
|
Returns:
|
1524
1554
|
(torch.Tensor | numpy.ndarray): A tensor or numpy array containing the class values for each oriented
|
@@ -1534,9 +1564,9 @@ class OBB(BaseTensor):
|
|
1534
1564
|
return self.data[:, -1]
|
1535
1565
|
|
1536
1566
|
@property
|
1537
|
-
def id(self):
|
1567
|
+
def id(self) -> Optional[Union[torch.Tensor, np.ndarray]]:
|
1538
1568
|
"""
|
1539
|
-
|
1569
|
+
Return the tracking IDs of the oriented bounding boxes (if available).
|
1540
1570
|
|
1541
1571
|
Returns:
|
1542
1572
|
(torch.Tensor | numpy.ndarray | None): A tensor or numpy array containing the tracking IDs for each
|
@@ -1554,9 +1584,9 @@ class OBB(BaseTensor):
|
|
1554
1584
|
|
1555
1585
|
@property
|
1556
1586
|
@lru_cache(maxsize=2)
|
1557
|
-
def xyxyxyxy(self):
|
1587
|
+
def xyxyxyxy(self) -> Union[torch.Tensor, np.ndarray]:
|
1558
1588
|
"""
|
1559
|
-
|
1589
|
+
Convert OBB format to 8-point (xyxyxyxy) coordinate format for rotated bounding boxes.
|
1560
1590
|
|
1561
1591
|
Returns:
|
1562
1592
|
(torch.Tensor | numpy.ndarray): Rotated bounding boxes in xyxyxyxy format with shape (N, 4, 2), where N is
|
@@ -1573,9 +1603,9 @@ class OBB(BaseTensor):
|
|
1573
1603
|
|
1574
1604
|
@property
|
1575
1605
|
@lru_cache(maxsize=2)
|
1576
|
-
def xyxyxyxyn(self):
|
1606
|
+
def xyxyxyxyn(self) -> Union[torch.Tensor, np.ndarray]:
|
1577
1607
|
"""
|
1578
|
-
|
1608
|
+
Convert rotated bounding boxes to normalized xyxyxyxy format.
|
1579
1609
|
|
1580
1610
|
Returns:
|
1581
1611
|
(torch.Tensor | numpy.ndarray): Normalized rotated bounding boxes in xyxyxyxy format with shape (N, 4, 2),
|
@@ -1595,9 +1625,9 @@ class OBB(BaseTensor):
|
|
1595
1625
|
|
1596
1626
|
@property
|
1597
1627
|
@lru_cache(maxsize=2)
|
1598
|
-
def xyxy(self):
|
1628
|
+
def xyxy(self) -> Union[torch.Tensor, np.ndarray]:
|
1599
1629
|
"""
|
1600
|
-
|
1630
|
+
Convert oriented bounding boxes (OBB) to axis-aligned bounding boxes in xyxy format.
|
1601
1631
|
|
1602
1632
|
This property calculates the minimal enclosing rectangle for each oriented bounding box and returns it in
|
1603
1633
|
xyxy format (x1, y1, x2, y2). This is useful for operations that require axis-aligned bounding boxes, such
|