dgenerate-ultralytics-headless 8.3.222__py3-none-any.whl → 8.3.225__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dgenerate_ultralytics_headless-8.3.222.dist-info → dgenerate_ultralytics_headless-8.3.225.dist-info}/METADATA +2 -2
- dgenerate_ultralytics_headless-8.3.225.dist-info/RECORD +286 -0
- tests/conftest.py +5 -8
- tests/test_cli.py +1 -8
- tests/test_python.py +1 -2
- ultralytics/__init__.py +1 -1
- ultralytics/cfg/__init__.py +34 -49
- ultralytics/cfg/datasets/ImageNet.yaml +1 -1
- ultralytics/cfg/datasets/kitti.yaml +27 -0
- ultralytics/cfg/datasets/lvis.yaml +5 -5
- ultralytics/cfg/datasets/open-images-v7.yaml +1 -1
- ultralytics/data/annotator.py +3 -4
- ultralytics/data/augment.py +244 -323
- ultralytics/data/base.py +12 -22
- ultralytics/data/build.py +47 -40
- ultralytics/data/converter.py +32 -42
- ultralytics/data/dataset.py +43 -71
- ultralytics/data/loaders.py +22 -34
- ultralytics/data/split.py +5 -6
- ultralytics/data/split_dota.py +8 -15
- ultralytics/data/utils.py +27 -36
- ultralytics/engine/exporter.py +49 -116
- ultralytics/engine/model.py +144 -180
- ultralytics/engine/predictor.py +18 -29
- ultralytics/engine/results.py +165 -231
- ultralytics/engine/trainer.py +11 -19
- ultralytics/engine/tuner.py +13 -23
- ultralytics/engine/validator.py +6 -10
- ultralytics/hub/__init__.py +7 -12
- ultralytics/hub/auth.py +6 -12
- ultralytics/hub/google/__init__.py +7 -10
- ultralytics/hub/session.py +15 -25
- ultralytics/hub/utils.py +3 -6
- ultralytics/models/fastsam/model.py +6 -8
- ultralytics/models/fastsam/predict.py +5 -10
- ultralytics/models/fastsam/utils.py +1 -2
- ultralytics/models/fastsam/val.py +2 -4
- ultralytics/models/nas/model.py +5 -8
- ultralytics/models/nas/predict.py +7 -9
- ultralytics/models/nas/val.py +1 -2
- ultralytics/models/rtdetr/model.py +5 -8
- ultralytics/models/rtdetr/predict.py +15 -18
- ultralytics/models/rtdetr/train.py +10 -13
- ultralytics/models/rtdetr/val.py +13 -20
- ultralytics/models/sam/amg.py +12 -18
- ultralytics/models/sam/build.py +6 -9
- ultralytics/models/sam/model.py +16 -23
- ultralytics/models/sam/modules/blocks.py +62 -84
- ultralytics/models/sam/modules/decoders.py +17 -24
- ultralytics/models/sam/modules/encoders.py +40 -56
- ultralytics/models/sam/modules/memory_attention.py +10 -16
- ultralytics/models/sam/modules/sam.py +41 -47
- ultralytics/models/sam/modules/tiny_encoder.py +64 -83
- ultralytics/models/sam/modules/transformer.py +17 -27
- ultralytics/models/sam/modules/utils.py +31 -42
- ultralytics/models/sam/predict.py +172 -209
- ultralytics/models/utils/loss.py +14 -26
- ultralytics/models/utils/ops.py +13 -17
- ultralytics/models/yolo/classify/predict.py +8 -11
- ultralytics/models/yolo/classify/train.py +8 -16
- ultralytics/models/yolo/classify/val.py +13 -20
- ultralytics/models/yolo/detect/predict.py +4 -8
- ultralytics/models/yolo/detect/train.py +11 -20
- ultralytics/models/yolo/detect/val.py +38 -48
- ultralytics/models/yolo/model.py +35 -47
- ultralytics/models/yolo/obb/predict.py +5 -8
- ultralytics/models/yolo/obb/train.py +11 -14
- ultralytics/models/yolo/obb/val.py +20 -28
- ultralytics/models/yolo/pose/predict.py +5 -8
- ultralytics/models/yolo/pose/train.py +4 -8
- ultralytics/models/yolo/pose/val.py +31 -39
- ultralytics/models/yolo/segment/predict.py +9 -14
- ultralytics/models/yolo/segment/train.py +3 -6
- ultralytics/models/yolo/segment/val.py +16 -26
- ultralytics/models/yolo/world/train.py +8 -14
- ultralytics/models/yolo/world/train_world.py +11 -16
- ultralytics/models/yolo/yoloe/predict.py +16 -23
- ultralytics/models/yolo/yoloe/train.py +30 -43
- ultralytics/models/yolo/yoloe/train_seg.py +5 -10
- ultralytics/models/yolo/yoloe/val.py +15 -20
- ultralytics/nn/autobackend.py +10 -18
- ultralytics/nn/modules/activation.py +4 -6
- ultralytics/nn/modules/block.py +99 -185
- ultralytics/nn/modules/conv.py +45 -90
- ultralytics/nn/modules/head.py +44 -98
- ultralytics/nn/modules/transformer.py +44 -76
- ultralytics/nn/modules/utils.py +14 -19
- ultralytics/nn/tasks.py +86 -146
- ultralytics/nn/text_model.py +25 -40
- ultralytics/solutions/ai_gym.py +10 -16
- ultralytics/solutions/analytics.py +7 -10
- ultralytics/solutions/config.py +4 -5
- ultralytics/solutions/distance_calculation.py +9 -12
- ultralytics/solutions/heatmap.py +7 -13
- ultralytics/solutions/instance_segmentation.py +5 -8
- ultralytics/solutions/object_blurrer.py +7 -10
- ultralytics/solutions/object_counter.py +8 -12
- ultralytics/solutions/object_cropper.py +5 -8
- ultralytics/solutions/parking_management.py +12 -14
- ultralytics/solutions/queue_management.py +4 -6
- ultralytics/solutions/region_counter.py +7 -10
- ultralytics/solutions/security_alarm.py +14 -19
- ultralytics/solutions/similarity_search.py +7 -12
- ultralytics/solutions/solutions.py +31 -53
- ultralytics/solutions/speed_estimation.py +6 -9
- ultralytics/solutions/streamlit_inference.py +2 -4
- ultralytics/solutions/trackzone.py +7 -10
- ultralytics/solutions/vision_eye.py +5 -8
- ultralytics/trackers/basetrack.py +2 -4
- ultralytics/trackers/bot_sort.py +6 -11
- ultralytics/trackers/byte_tracker.py +10 -15
- ultralytics/trackers/track.py +3 -6
- ultralytics/trackers/utils/gmc.py +6 -12
- ultralytics/trackers/utils/kalman_filter.py +35 -43
- ultralytics/trackers/utils/matching.py +6 -10
- ultralytics/utils/__init__.py +61 -100
- ultralytics/utils/autobatch.py +2 -4
- ultralytics/utils/autodevice.py +11 -13
- ultralytics/utils/benchmarks.py +25 -35
- ultralytics/utils/callbacks/base.py +8 -10
- ultralytics/utils/callbacks/clearml.py +2 -4
- ultralytics/utils/callbacks/comet.py +30 -44
- ultralytics/utils/callbacks/dvc.py +13 -18
- ultralytics/utils/callbacks/mlflow.py +4 -5
- ultralytics/utils/callbacks/neptune.py +4 -6
- ultralytics/utils/callbacks/raytune.py +3 -4
- ultralytics/utils/callbacks/tensorboard.py +4 -6
- ultralytics/utils/callbacks/wb.py +10 -13
- ultralytics/utils/checks.py +29 -56
- ultralytics/utils/cpu.py +1 -2
- ultralytics/utils/dist.py +8 -12
- ultralytics/utils/downloads.py +17 -27
- ultralytics/utils/errors.py +6 -8
- ultralytics/utils/events.py +2 -4
- ultralytics/utils/export/__init__.py +4 -239
- ultralytics/utils/export/engine.py +237 -0
- ultralytics/utils/export/imx.py +11 -17
- ultralytics/utils/export/tensorflow.py +217 -0
- ultralytics/utils/files.py +10 -15
- ultralytics/utils/git.py +5 -7
- ultralytics/utils/instance.py +30 -51
- ultralytics/utils/logger.py +11 -15
- ultralytics/utils/loss.py +8 -14
- ultralytics/utils/metrics.py +98 -138
- ultralytics/utils/nms.py +13 -16
- ultralytics/utils/ops.py +47 -74
- ultralytics/utils/patches.py +11 -18
- ultralytics/utils/plotting.py +29 -42
- ultralytics/utils/tal.py +25 -39
- ultralytics/utils/torch_utils.py +45 -73
- ultralytics/utils/tqdm.py +6 -8
- ultralytics/utils/triton.py +9 -12
- ultralytics/utils/tuner.py +1 -2
- dgenerate_ultralytics_headless-8.3.222.dist-info/RECORD +0 -283
- {dgenerate_ultralytics_headless-8.3.222.dist-info → dgenerate_ultralytics_headless-8.3.225.dist-info}/WHEEL +0 -0
- {dgenerate_ultralytics_headless-8.3.222.dist-info → dgenerate_ultralytics_headless-8.3.225.dist-info}/entry_points.txt +0 -0
- {dgenerate_ultralytics_headless-8.3.222.dist-info → dgenerate_ultralytics_headless-8.3.225.dist-info}/licenses/LICENSE +0 -0
- {dgenerate_ultralytics_headless-8.3.222.dist-info → dgenerate_ultralytics_headless-8.3.225.dist-info}/top_level.txt +0 -0
ultralytics/engine/results.py
CHANGED
|
@@ -21,12 +21,11 @@ from ultralytics.utils.plotting import Annotator, colors, save_one_box
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
class BaseTensor(SimpleClass):
|
|
24
|
-
"""
|
|
25
|
-
Base tensor class with additional methods for easy manipulation and device handling.
|
|
24
|
+
"""Base tensor class with additional methods for easy manipulation and device handling.
|
|
26
25
|
|
|
27
|
-
This class provides a foundation for tensor-like objects with device management capabilities,
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
This class provides a foundation for tensor-like objects with device management capabilities, supporting both
|
|
27
|
+
PyTorch tensors and NumPy arrays. It includes methods for moving data between devices and converting between tensor
|
|
28
|
+
types.
|
|
30
29
|
|
|
31
30
|
Attributes:
|
|
32
31
|
data (torch.Tensor | np.ndarray): Prediction data such as bounding boxes, masks, or keypoints.
|
|
@@ -49,8 +48,7 @@ class BaseTensor(SimpleClass):
|
|
|
49
48
|
"""
|
|
50
49
|
|
|
51
50
|
def __init__(self, data: torch.Tensor | np.ndarray, orig_shape: tuple[int, int]) -> None:
|
|
52
|
-
"""
|
|
53
|
-
Initialize BaseTensor with prediction data and the original shape of the image.
|
|
51
|
+
"""Initialize BaseTensor with prediction data and the original shape of the image.
|
|
54
52
|
|
|
55
53
|
Args:
|
|
56
54
|
data (torch.Tensor | np.ndarray): Prediction data such as bounding boxes, masks, or keypoints.
|
|
@@ -68,8 +66,7 @@ class BaseTensor(SimpleClass):
|
|
|
68
66
|
|
|
69
67
|
@property
|
|
70
68
|
def shape(self) -> tuple[int, ...]:
|
|
71
|
-
"""
|
|
72
|
-
Return the shape of the underlying data tensor.
|
|
69
|
+
"""Return the shape of the underlying data tensor.
|
|
73
70
|
|
|
74
71
|
Returns:
|
|
75
72
|
(tuple[int, ...]): The shape of the data tensor.
|
|
@@ -83,8 +80,7 @@ class BaseTensor(SimpleClass):
|
|
|
83
80
|
return self.data.shape
|
|
84
81
|
|
|
85
82
|
def cpu(self):
|
|
86
|
-
"""
|
|
87
|
-
Return a copy of the tensor stored in CPU memory.
|
|
83
|
+
"""Return a copy of the tensor stored in CPU memory.
|
|
88
84
|
|
|
89
85
|
Returns:
|
|
90
86
|
(BaseTensor): A new BaseTensor object with the data tensor moved to CPU memory.
|
|
@@ -101,8 +97,7 @@ class BaseTensor(SimpleClass):
|
|
|
101
97
|
return self if isinstance(self.data, np.ndarray) else self.__class__(self.data.cpu(), self.orig_shape)
|
|
102
98
|
|
|
103
99
|
def numpy(self):
|
|
104
|
-
"""
|
|
105
|
-
Return a copy of the tensor as a numpy array.
|
|
100
|
+
"""Return a copy of the tensor as a numpy array.
|
|
106
101
|
|
|
107
102
|
Returns:
|
|
108
103
|
(np.ndarray): A numpy array containing the same data as the original tensor.
|
|
@@ -118,12 +113,11 @@ class BaseTensor(SimpleClass):
|
|
|
118
113
|
return self if isinstance(self.data, np.ndarray) else self.__class__(self.data.numpy(), self.orig_shape)
|
|
119
114
|
|
|
120
115
|
def cuda(self):
|
|
121
|
-
"""
|
|
122
|
-
Move the tensor to GPU memory.
|
|
116
|
+
"""Move the tensor to GPU memory.
|
|
123
117
|
|
|
124
118
|
Returns:
|
|
125
|
-
(BaseTensor): A new BaseTensor instance with the data moved to GPU memory if it's not already a
|
|
126
|
-
|
|
119
|
+
(BaseTensor): A new BaseTensor instance with the data moved to GPU memory if it's not already a numpy array,
|
|
120
|
+
otherwise returns self.
|
|
127
121
|
|
|
128
122
|
Examples:
|
|
129
123
|
>>> import torch
|
|
@@ -137,8 +131,7 @@ class BaseTensor(SimpleClass):
|
|
|
137
131
|
return self.__class__(torch.as_tensor(self.data).cuda(), self.orig_shape)
|
|
138
132
|
|
|
139
133
|
def to(self, *args, **kwargs):
|
|
140
|
-
"""
|
|
141
|
-
Return a copy of the tensor with the specified device and dtype.
|
|
134
|
+
"""Return a copy of the tensor with the specified device and dtype.
|
|
142
135
|
|
|
143
136
|
Args:
|
|
144
137
|
*args (Any): Variable length argument list to be passed to torch.Tensor.to().
|
|
@@ -155,8 +148,7 @@ class BaseTensor(SimpleClass):
|
|
|
155
148
|
return self.__class__(torch.as_tensor(self.data).to(*args, **kwargs), self.orig_shape)
|
|
156
149
|
|
|
157
150
|
def __len__(self) -> int:
|
|
158
|
-
"""
|
|
159
|
-
Return the length of the underlying data tensor.
|
|
151
|
+
"""Return the length of the underlying data tensor.
|
|
160
152
|
|
|
161
153
|
Returns:
|
|
162
154
|
(int): The number of elements in the first dimension of the data tensor.
|
|
@@ -170,8 +162,7 @@ class BaseTensor(SimpleClass):
|
|
|
170
162
|
return len(self.data)
|
|
171
163
|
|
|
172
164
|
def __getitem__(self, idx):
|
|
173
|
-
"""
|
|
174
|
-
Return a new BaseTensor instance containing the specified indexed elements of the data tensor.
|
|
165
|
+
"""Return a new BaseTensor instance containing the specified indexed elements of the data tensor.
|
|
175
166
|
|
|
176
167
|
Args:
|
|
177
168
|
idx (int | list[int] | torch.Tensor): Index or indices to select from the data tensor.
|
|
@@ -190,12 +181,11 @@ class BaseTensor(SimpleClass):
|
|
|
190
181
|
|
|
191
182
|
|
|
192
183
|
class Results(SimpleClass, DataExportMixin):
|
|
193
|
-
"""
|
|
194
|
-
A class for storing and manipulating inference results.
|
|
184
|
+
"""A class for storing and manipulating inference results.
|
|
195
185
|
|
|
196
|
-
This class provides comprehensive functionality for handling inference results from various
|
|
197
|
-
|
|
198
|
-
|
|
186
|
+
This class provides comprehensive functionality for handling inference results from various Ultralytics models,
|
|
187
|
+
including detection, segmentation, classification, and pose estimation. It supports visualization, data export, and
|
|
188
|
+
various coordinate transformations.
|
|
199
189
|
|
|
200
190
|
Attributes:
|
|
201
191
|
orig_img (np.ndarray): The original image as a numpy array.
|
|
@@ -249,8 +239,7 @@ class Results(SimpleClass, DataExportMixin):
|
|
|
249
239
|
obb: torch.Tensor | None = None,
|
|
250
240
|
speed: dict[str, float] | None = None,
|
|
251
241
|
) -> None:
|
|
252
|
-
"""
|
|
253
|
-
Initialize the Results class for storing and manipulating inference results.
|
|
242
|
+
"""Initialize the Results class for storing and manipulating inference results.
|
|
254
243
|
|
|
255
244
|
Args:
|
|
256
245
|
orig_img (np.ndarray): The original image as a numpy array.
|
|
@@ -290,8 +279,7 @@ class Results(SimpleClass, DataExportMixin):
|
|
|
290
279
|
self._keys = "boxes", "masks", "probs", "keypoints", "obb"
|
|
291
280
|
|
|
292
281
|
def __getitem__(self, idx):
|
|
293
|
-
"""
|
|
294
|
-
Return a Results object for a specific index of inference results.
|
|
282
|
+
"""Return a Results object for a specific index of inference results.
|
|
295
283
|
|
|
296
284
|
Args:
|
|
297
285
|
idx (int | slice): Index or slice to retrieve from the Results object.
|
|
@@ -307,12 +295,11 @@ class Results(SimpleClass, DataExportMixin):
|
|
|
307
295
|
return self._apply("__getitem__", idx)
|
|
308
296
|
|
|
309
297
|
def __len__(self) -> int:
|
|
310
|
-
"""
|
|
311
|
-
Return the number of detections in the Results object.
|
|
298
|
+
"""Return the number of detections in the Results object.
|
|
312
299
|
|
|
313
300
|
Returns:
|
|
314
|
-
(int): The number of detections, determined by the length of the first non-empty
|
|
315
|
-
|
|
301
|
+
(int): The number of detections, determined by the length of the first non-empty attribute in (masks, probs,
|
|
302
|
+
keypoints, or obb).
|
|
316
303
|
|
|
317
304
|
Examples:
|
|
318
305
|
>>> results = Results(orig_img, path, names, boxes=torch.rand(5, 4))
|
|
@@ -332,15 +319,14 @@ class Results(SimpleClass, DataExportMixin):
|
|
|
332
319
|
obb: torch.Tensor | None = None,
|
|
333
320
|
keypoints: torch.Tensor | None = None,
|
|
334
321
|
):
|
|
335
|
-
"""
|
|
336
|
-
Update the Results object with new detection data.
|
|
322
|
+
"""Update the Results object with new detection data.
|
|
337
323
|
|
|
338
|
-
This method allows updating the boxes, masks, probabilities, and oriented bounding boxes (OBB) of the
|
|
339
|
-
|
|
324
|
+
This method allows updating the boxes, masks, probabilities, and oriented bounding boxes (OBB) of the Results
|
|
325
|
+
object. It ensures that boxes are clipped to the original image shape.
|
|
340
326
|
|
|
341
327
|
Args:
|
|
342
|
-
boxes (torch.Tensor | None): A tensor of shape (N, 6) containing bounding box coordinates and
|
|
343
|
-
|
|
328
|
+
boxes (torch.Tensor | None): A tensor of shape (N, 6) containing bounding box coordinates and confidence
|
|
329
|
+
scores. The format is (x1, y1, x2, y2, conf, class).
|
|
344
330
|
masks (torch.Tensor | None): A tensor of shape (N, H, W) containing segmentation masks.
|
|
345
331
|
probs (torch.Tensor | None): A tensor of shape (num_classes,) containing class probabilities.
|
|
346
332
|
obb (torch.Tensor | None): A tensor of shape (N, 5) containing oriented bounding box coordinates.
|
|
@@ -363,8 +349,7 @@ class Results(SimpleClass, DataExportMixin):
|
|
|
363
349
|
self.keypoints = Keypoints(keypoints, self.orig_shape)
|
|
364
350
|
|
|
365
351
|
def _apply(self, fn: str, *args, **kwargs):
|
|
366
|
-
"""
|
|
367
|
-
Apply a function to all non-empty attributes and return a new Results object with modified attributes.
|
|
352
|
+
"""Apply a function to all non-empty attributes and return a new Results object with modified attributes.
|
|
368
353
|
|
|
369
354
|
This method is internally called by methods like .to(), .cuda(), .cpu(), etc.
|
|
370
355
|
|
|
@@ -390,8 +375,7 @@ class Results(SimpleClass, DataExportMixin):
|
|
|
390
375
|
return r
|
|
391
376
|
|
|
392
377
|
def cpu(self):
|
|
393
|
-
"""
|
|
394
|
-
Return a copy of the Results object with all its tensors moved to CPU memory.
|
|
378
|
+
"""Return a copy of the Results object with all its tensors moved to CPU memory.
|
|
395
379
|
|
|
396
380
|
This method creates a new Results object with all tensor attributes (boxes, masks, probs, keypoints, obb)
|
|
397
381
|
transferred to CPU memory. It's useful for moving data from GPU to CPU for further processing or saving.
|
|
@@ -407,8 +391,7 @@ class Results(SimpleClass, DataExportMixin):
|
|
|
407
391
|
return self._apply("cpu")
|
|
408
392
|
|
|
409
393
|
def numpy(self):
|
|
410
|
-
"""
|
|
411
|
-
Convert all tensors in the Results object to numpy arrays.
|
|
394
|
+
"""Convert all tensors in the Results object to numpy arrays.
|
|
412
395
|
|
|
413
396
|
Returns:
|
|
414
397
|
(Results): A new Results object with all tensors converted to numpy arrays.
|
|
@@ -426,8 +409,7 @@ class Results(SimpleClass, DataExportMixin):
|
|
|
426
409
|
return self._apply("numpy")
|
|
427
410
|
|
|
428
411
|
def cuda(self):
|
|
429
|
-
"""
|
|
430
|
-
Move all tensors in the Results object to GPU memory.
|
|
412
|
+
"""Move all tensors in the Results object to GPU memory.
|
|
431
413
|
|
|
432
414
|
Returns:
|
|
433
415
|
(Results): A new Results object with all tensors moved to CUDA device.
|
|
@@ -441,8 +423,7 @@ class Results(SimpleClass, DataExportMixin):
|
|
|
441
423
|
return self._apply("cuda")
|
|
442
424
|
|
|
443
425
|
def to(self, *args, **kwargs):
|
|
444
|
-
"""
|
|
445
|
-
Move all tensors in the Results object to the specified device and dtype.
|
|
426
|
+
"""Move all tensors in the Results object to the specified device and dtype.
|
|
446
427
|
|
|
447
428
|
Args:
|
|
448
429
|
*args (Any): Variable length argument list to be passed to torch.Tensor.to().
|
|
@@ -460,8 +441,7 @@ class Results(SimpleClass, DataExportMixin):
|
|
|
460
441
|
return self._apply("to", *args, **kwargs)
|
|
461
442
|
|
|
462
443
|
def new(self):
|
|
463
|
-
"""
|
|
464
|
-
Create a new Results object with the same image, path, names, and speed attributes.
|
|
444
|
+
"""Create a new Results object with the same image, path, names, and speed attributes.
|
|
465
445
|
|
|
466
446
|
Returns:
|
|
467
447
|
(Results): A new Results object with copied attributes from the original instance.
|
|
@@ -493,8 +473,7 @@ class Results(SimpleClass, DataExportMixin):
|
|
|
493
473
|
color_mode: str = "class",
|
|
494
474
|
txt_color: tuple[int, int, int] = (255, 255, 255),
|
|
495
475
|
) -> np.ndarray:
|
|
496
|
-
"""
|
|
497
|
-
Plot detection results on an input RGB image.
|
|
476
|
+
"""Plot detection results on an input RGB image.
|
|
498
477
|
|
|
499
478
|
Args:
|
|
500
479
|
conf (bool): Whether to plot detection confidence scores.
|
|
@@ -613,8 +592,7 @@ class Results(SimpleClass, DataExportMixin):
|
|
|
613
592
|
return annotator.im if pil else annotator.result()
|
|
614
593
|
|
|
615
594
|
def show(self, *args, **kwargs):
|
|
616
|
-
"""
|
|
617
|
-
Display the image with annotated inference results.
|
|
595
|
+
"""Display the image with annotated inference results.
|
|
618
596
|
|
|
619
597
|
This method plots the detection results on the original image and displays it. It's a convenient way to
|
|
620
598
|
visualize the model's predictions directly.
|
|
@@ -632,15 +610,14 @@ class Results(SimpleClass, DataExportMixin):
|
|
|
632
610
|
self.plot(show=True, *args, **kwargs)
|
|
633
611
|
|
|
634
612
|
def save(self, filename: str | None = None, *args, **kwargs) -> str:
|
|
635
|
-
"""
|
|
636
|
-
Save annotated inference results image to file.
|
|
613
|
+
"""Save annotated inference results image to file.
|
|
637
614
|
|
|
638
615
|
This method plots the detection results on the original image and saves the annotated image to a file. It
|
|
639
616
|
utilizes the `plot` method to generate the annotated image and then saves it to the specified filename.
|
|
640
617
|
|
|
641
618
|
Args:
|
|
642
|
-
filename (str | Path | None): The filename to save the annotated image. If None, a default filename
|
|
643
|
-
|
|
619
|
+
filename (str | Path | None): The filename to save the annotated image. If None, a default filename is
|
|
620
|
+
generated based on the original image path.
|
|
644
621
|
*args (Any): Variable length argument list to be passed to the `plot` method.
|
|
645
622
|
**kwargs (Any): Arbitrary keyword arguments to be passed to the `plot` method.
|
|
646
623
|
|
|
@@ -661,15 +638,14 @@ class Results(SimpleClass, DataExportMixin):
|
|
|
661
638
|
return filename
|
|
662
639
|
|
|
663
640
|
def verbose(self) -> str:
|
|
664
|
-
"""
|
|
665
|
-
Return a log string for each task in the results, detailing detection and classification outcomes.
|
|
641
|
+
"""Return a log string for each task in the results, detailing detection and classification outcomes.
|
|
666
642
|
|
|
667
643
|
This method generates a human-readable string summarizing the detection and classification results. It includes
|
|
668
644
|
the number of detections for each class and the top probabilities for classification tasks.
|
|
669
645
|
|
|
670
646
|
Returns:
|
|
671
|
-
(str): A formatted string containing a summary of the results. For detection tasks, it includes the
|
|
672
|
-
|
|
647
|
+
(str): A formatted string containing a summary of the results. For detection tasks, it includes the number
|
|
648
|
+
of detections per class. For classification tasks, it includes the top 5 class probabilities.
|
|
673
649
|
|
|
674
650
|
Examples:
|
|
675
651
|
>>> results = model("path/to/image.jpg")
|
|
@@ -693,8 +669,7 @@ class Results(SimpleClass, DataExportMixin):
|
|
|
693
669
|
return "".join(f"{n} {self.names[i]}{'s' * (n > 1)}, " for i, n in enumerate(counts) if n > 0)
|
|
694
670
|
|
|
695
671
|
def save_txt(self, txt_file: str | Path, save_conf: bool = False) -> str:
|
|
696
|
-
"""
|
|
697
|
-
Save detection results to a text file.
|
|
672
|
+
"""Save detection results to a text file.
|
|
698
673
|
|
|
699
674
|
Args:
|
|
700
675
|
txt_file (str | Path): Path to the output text file.
|
|
@@ -750,8 +725,7 @@ class Results(SimpleClass, DataExportMixin):
|
|
|
750
725
|
return str(txt_file)
|
|
751
726
|
|
|
752
727
|
def save_crop(self, save_dir: str | Path, file_name: str | Path = Path("im.jpg")):
|
|
753
|
-
"""
|
|
754
|
-
Save cropped detection images to specified directory.
|
|
728
|
+
"""Save cropped detection images to specified directory.
|
|
755
729
|
|
|
756
730
|
This method saves cropped images of detected objects to a specified directory. Each crop is saved in a
|
|
757
731
|
subdirectory named after the object's class, with the filename based on the input file_name.
|
|
@@ -760,16 +734,16 @@ class Results(SimpleClass, DataExportMixin):
|
|
|
760
734
|
save_dir (str | Path): Directory path where cropped images will be saved.
|
|
761
735
|
file_name (str | Path): Base filename for the saved cropped images.
|
|
762
736
|
|
|
737
|
+
Examples:
|
|
738
|
+
>>> results = model("path/to/image.jpg")
|
|
739
|
+
>>> for result in results:
|
|
740
|
+
>>> result.save_crop(save_dir="path/to/crops", file_name="detection")
|
|
741
|
+
|
|
763
742
|
Notes:
|
|
764
743
|
- This method does not support Classify or Oriented Bounding Box (OBB) tasks.
|
|
765
744
|
- Crops are saved as 'save_dir/class_name/file_name.jpg'.
|
|
766
745
|
- The method will create necessary subdirectories if they don't exist.
|
|
767
746
|
- Original image is copied before cropping to avoid modifying the original.
|
|
768
|
-
|
|
769
|
-
Examples:
|
|
770
|
-
>>> results = model("path/to/image.jpg")
|
|
771
|
-
>>> for result in results:
|
|
772
|
-
>>> result.save_crop(save_dir="path/to/crops", file_name="detection")
|
|
773
747
|
"""
|
|
774
748
|
if self.probs is not None:
|
|
775
749
|
LOGGER.warning("Classify task do not support `save_crop`.")
|
|
@@ -786,11 +760,10 @@ class Results(SimpleClass, DataExportMixin):
|
|
|
786
760
|
)
|
|
787
761
|
|
|
788
762
|
def summary(self, normalize: bool = False, decimals: int = 5) -> list[dict[str, Any]]:
|
|
789
|
-
"""
|
|
790
|
-
Convert inference results to a summarized dictionary with optional normalization for box coordinates.
|
|
763
|
+
"""Convert inference results to a summarized dictionary with optional normalization for box coordinates.
|
|
791
764
|
|
|
792
|
-
This method creates a list of detection dictionaries, each containing information about a single
|
|
793
|
-
|
|
765
|
+
This method creates a list of detection dictionaries, each containing information about a single detection or
|
|
766
|
+
classification result. For classification tasks, it returns the top class and its
|
|
794
767
|
confidence. For detection tasks, it includes class information, bounding box coordinates, and
|
|
795
768
|
optionally mask segments and keypoints.
|
|
796
769
|
|
|
@@ -799,8 +772,8 @@ class Results(SimpleClass, DataExportMixin):
|
|
|
799
772
|
decimals (int): Number of decimal places to round the output values to.
|
|
800
773
|
|
|
801
774
|
Returns:
|
|
802
|
-
(list[dict[str, Any]]): A list of dictionaries, each containing summarized information for a single
|
|
803
|
-
or classification result. The structure of each dictionary varies based on the task type
|
|
775
|
+
(list[dict[str, Any]]): A list of dictionaries, each containing summarized information for a single
|
|
776
|
+
detection or classification result. The structure of each dictionary varies based on the task type
|
|
804
777
|
(classification or detection) and available information (boxes, masks, keypoints).
|
|
805
778
|
|
|
806
779
|
Examples:
|
|
@@ -853,12 +826,11 @@ class Results(SimpleClass, DataExportMixin):
|
|
|
853
826
|
|
|
854
827
|
|
|
855
828
|
class Boxes(BaseTensor):
|
|
856
|
-
"""
|
|
857
|
-
A class for managing and manipulating detection boxes.
|
|
829
|
+
"""A class for managing and manipulating detection boxes.
|
|
858
830
|
|
|
859
831
|
This class provides comprehensive functionality for handling detection boxes, including their coordinates,
|
|
860
|
-
confidence scores, class labels, and optional tracking IDs. It supports various box formats and offers
|
|
861
|
-
|
|
832
|
+
confidence scores, class labels, and optional tracking IDs. It supports various box formats and offers methods for
|
|
833
|
+
easy manipulation and conversion between different coordinate systems.
|
|
862
834
|
|
|
863
835
|
Attributes:
|
|
864
836
|
data (torch.Tensor | np.ndarray): The raw tensor containing detection boxes and associated data.
|
|
@@ -890,17 +862,15 @@ class Boxes(BaseTensor):
|
|
|
890
862
|
"""
|
|
891
863
|
|
|
892
864
|
def __init__(self, boxes: torch.Tensor | np.ndarray, orig_shape: tuple[int, int]) -> None:
|
|
893
|
-
"""
|
|
894
|
-
Initialize the Boxes class with detection box data and the original image shape.
|
|
865
|
+
"""Initialize the Boxes class with detection box data and the original image shape.
|
|
895
866
|
|
|
896
|
-
This class manages detection boxes, providing easy access and manipulation of box coordinates,
|
|
897
|
-
|
|
898
|
-
|
|
867
|
+
This class manages detection boxes, providing easy access and manipulation of box coordinates, confidence
|
|
868
|
+
scores, class identifiers, and optional tracking IDs. It supports multiple formats for box coordinates,
|
|
869
|
+
including both absolute and normalized forms.
|
|
899
870
|
|
|
900
871
|
Args:
|
|
901
|
-
boxes (torch.Tensor | np.ndarray): A tensor or numpy array with detection boxes of shape
|
|
902
|
-
(num_boxes,
|
|
903
|
-
[x1, y1, x2, y2, (optional) track_id, confidence, class].
|
|
872
|
+
boxes (torch.Tensor | np.ndarray): A tensor or numpy array with detection boxes of shape (num_boxes, 6) or
|
|
873
|
+
(num_boxes, 7). Columns should contain [x1, y1, x2, y2, (optional) track_id, confidence, class].
|
|
904
874
|
orig_shape (tuple[int, int]): The original image shape as (height, width). Used for normalization.
|
|
905
875
|
|
|
906
876
|
Attributes:
|
|
@@ -926,12 +896,11 @@ class Boxes(BaseTensor):
|
|
|
926
896
|
|
|
927
897
|
@property
|
|
928
898
|
def xyxy(self) -> torch.Tensor | np.ndarray:
|
|
929
|
-
"""
|
|
930
|
-
Return bounding boxes in [x1, y1, x2, y2] format.
|
|
899
|
+
"""Return bounding boxes in [x1, y1, x2, y2] format.
|
|
931
900
|
|
|
932
901
|
Returns:
|
|
933
|
-
(torch.Tensor | np.ndarray): A tensor or numpy array of shape (n, 4) containing bounding box
|
|
934
|
-
|
|
902
|
+
(torch.Tensor | np.ndarray): A tensor or numpy array of shape (n, 4) containing bounding box coordinates in
|
|
903
|
+
[x1, y1, x2, y2] format, where n is the number of boxes.
|
|
935
904
|
|
|
936
905
|
Examples:
|
|
937
906
|
>>> results = model("image.jpg")
|
|
@@ -943,12 +912,11 @@ class Boxes(BaseTensor):
|
|
|
943
912
|
|
|
944
913
|
@property
|
|
945
914
|
def conf(self) -> torch.Tensor | np.ndarray:
|
|
946
|
-
"""
|
|
947
|
-
Return the confidence scores for each detection box.
|
|
915
|
+
"""Return the confidence scores for each detection box.
|
|
948
916
|
|
|
949
917
|
Returns:
|
|
950
|
-
(torch.Tensor | np.ndarray): A 1D tensor or array containing confidence scores for each detection,
|
|
951
|
-
|
|
918
|
+
(torch.Tensor | np.ndarray): A 1D tensor or array containing confidence scores for each detection, with
|
|
919
|
+
shape (N,) where N is the number of detections.
|
|
952
920
|
|
|
953
921
|
Examples:
|
|
954
922
|
>>> boxes = Boxes(torch.tensor([[10, 20, 30, 40, 0.9, 0]]), orig_shape=(100, 100))
|
|
@@ -960,12 +928,11 @@ class Boxes(BaseTensor):
|
|
|
960
928
|
|
|
961
929
|
@property
|
|
962
930
|
def cls(self) -> torch.Tensor | np.ndarray:
|
|
963
|
-
"""
|
|
964
|
-
Return the class ID tensor representing category predictions for each bounding box.
|
|
931
|
+
"""Return the class ID tensor representing category predictions for each bounding box.
|
|
965
932
|
|
|
966
933
|
Returns:
|
|
967
|
-
(torch.Tensor | np.ndarray): A tensor or numpy array containing the class IDs for each detection box.
|
|
968
|
-
|
|
934
|
+
(torch.Tensor | np.ndarray): A tensor or numpy array containing the class IDs for each detection box. The
|
|
935
|
+
shape is (N,), where N is the number of boxes.
|
|
969
936
|
|
|
970
937
|
Examples:
|
|
971
938
|
>>> results = model("image.jpg")
|
|
@@ -977,12 +944,11 @@ class Boxes(BaseTensor):
|
|
|
977
944
|
|
|
978
945
|
@property
|
|
979
946
|
def id(self) -> torch.Tensor | np.ndarray | None:
|
|
980
|
-
"""
|
|
981
|
-
Return the tracking IDs for each detection box if available.
|
|
947
|
+
"""Return the tracking IDs for each detection box if available.
|
|
982
948
|
|
|
983
949
|
Returns:
|
|
984
|
-
(torch.Tensor | None): A tensor containing tracking IDs for each box if tracking is enabled,
|
|
985
|
-
|
|
950
|
+
(torch.Tensor | None): A tensor containing tracking IDs for each box if tracking is enabled, otherwise None.
|
|
951
|
+
Shape is (N,) where N is the number of boxes.
|
|
986
952
|
|
|
987
953
|
Examples:
|
|
988
954
|
>>> results = model.track("path/to/video.mp4")
|
|
@@ -1003,14 +969,12 @@ class Boxes(BaseTensor):
|
|
|
1003
969
|
@property
|
|
1004
970
|
@lru_cache(maxsize=2)
|
|
1005
971
|
def xywh(self) -> torch.Tensor | np.ndarray:
|
|
1006
|
-
"""
|
|
1007
|
-
Convert bounding boxes from [x1, y1, x2, y2] format to [x, y, width, height] format.
|
|
972
|
+
"""Convert bounding boxes from [x1, y1, x2, y2] format to [x, y, width, height] format.
|
|
1008
973
|
|
|
1009
974
|
Returns:
|
|
1010
|
-
(torch.Tensor | np.ndarray): Boxes in [x_center, y_center, width, height] format, where x_center,
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
number of boxes.
|
|
975
|
+
(torch.Tensor | np.ndarray): Boxes in [x_center, y_center, width, height] format, where x_center, y_center
|
|
976
|
+
are the coordinates of the center point of the bounding box, width, height are the dimensions of the
|
|
977
|
+
bounding box and the shape of the returned tensor is (N, 4), where N is the number of boxes.
|
|
1014
978
|
|
|
1015
979
|
Examples:
|
|
1016
980
|
>>> boxes = Boxes(torch.tensor([[100, 50, 150, 100], [200, 150, 300, 250]]), orig_shape=(480, 640))
|
|
@@ -1024,15 +988,14 @@ class Boxes(BaseTensor):
|
|
|
1024
988
|
@property
|
|
1025
989
|
@lru_cache(maxsize=2)
|
|
1026
990
|
def xyxyn(self) -> torch.Tensor | np.ndarray:
|
|
1027
|
-
"""
|
|
1028
|
-
Return normalized bounding box coordinates relative to the original image size.
|
|
991
|
+
"""Return normalized bounding box coordinates relative to the original image size.
|
|
1029
992
|
|
|
1030
|
-
This property calculates and returns the bounding box coordinates in [x1, y1, x2, y2] format,
|
|
1031
|
-
|
|
993
|
+
This property calculates and returns the bounding box coordinates in [x1, y1, x2, y2] format, normalized to the
|
|
994
|
+
range [0, 1] based on the original image dimensions.
|
|
1032
995
|
|
|
1033
996
|
Returns:
|
|
1034
|
-
(torch.Tensor | np.ndarray): Normalized bounding box coordinates with shape (N, 4), where N is
|
|
1035
|
-
|
|
997
|
+
(torch.Tensor | np.ndarray): Normalized bounding box coordinates with shape (N, 4), where N is the number of
|
|
998
|
+
boxes. Each row contains [x1, y1, x2, y2] values normalized to [0, 1].
|
|
1036
999
|
|
|
1037
1000
|
Examples:
|
|
1038
1001
|
>>> boxes = Boxes(torch.tensor([[100, 50, 300, 400, 0.9, 0]]), orig_shape=(480, 640))
|
|
@@ -1048,16 +1011,15 @@ class Boxes(BaseTensor):
|
|
|
1048
1011
|
@property
|
|
1049
1012
|
@lru_cache(maxsize=2)
|
|
1050
1013
|
def xywhn(self) -> torch.Tensor | np.ndarray:
|
|
1051
|
-
"""
|
|
1052
|
-
Return normalized bounding boxes in [x, y, width, height] format.
|
|
1014
|
+
"""Return normalized bounding boxes in [x, y, width, height] format.
|
|
1053
1015
|
|
|
1054
|
-
This property calculates and returns the normalized bounding box coordinates in the format
|
|
1055
|
-
|
|
1016
|
+
This property calculates and returns the normalized bounding box coordinates in the format [x_center, y_center,
|
|
1017
|
+
width, height], where all values are relative to the original image dimensions.
|
|
1056
1018
|
|
|
1057
1019
|
Returns:
|
|
1058
|
-
(torch.Tensor | np.ndarray): Normalized bounding boxes with shape (N, 4), where N is the
|
|
1059
|
-
|
|
1060
|
-
|
|
1020
|
+
(torch.Tensor | np.ndarray): Normalized bounding boxes with shape (N, 4), where N is the number of boxes.
|
|
1021
|
+
Each row contains [x_center, y_center, width, height] values normalized to [0, 1] based on the original
|
|
1022
|
+
image dimensions.
|
|
1061
1023
|
|
|
1062
1024
|
Examples:
|
|
1063
1025
|
>>> boxes = Boxes(torch.tensor([[100, 50, 150, 100, 0.9, 0]]), orig_shape=(480, 640))
|
|
@@ -1072,11 +1034,10 @@ class Boxes(BaseTensor):
|
|
|
1072
1034
|
|
|
1073
1035
|
|
|
1074
1036
|
class Masks(BaseTensor):
|
|
1075
|
-
"""
|
|
1076
|
-
A class for storing and manipulating detection masks.
|
|
1037
|
+
"""A class for storing and manipulating detection masks.
|
|
1077
1038
|
|
|
1078
|
-
This class extends BaseTensor and provides functionality for handling segmentation masks,
|
|
1079
|
-
|
|
1039
|
+
This class extends BaseTensor and provides functionality for handling segmentation masks, including methods for
|
|
1040
|
+
converting between pixel and normalized coordinates.
|
|
1080
1041
|
|
|
1081
1042
|
Attributes:
|
|
1082
1043
|
data (torch.Tensor | np.ndarray): The raw tensor or array containing mask data.
|
|
@@ -1099,8 +1060,7 @@ class Masks(BaseTensor):
|
|
|
1099
1060
|
"""
|
|
1100
1061
|
|
|
1101
1062
|
def __init__(self, masks: torch.Tensor | np.ndarray, orig_shape: tuple[int, int]) -> None:
|
|
1102
|
-
"""
|
|
1103
|
-
Initialize the Masks class with detection mask data and the original image shape.
|
|
1063
|
+
"""Initialize the Masks class with detection mask data and the original image shape.
|
|
1104
1064
|
|
|
1105
1065
|
Args:
|
|
1106
1066
|
masks (torch.Tensor | np.ndarray): Detection masks with shape (num_masks, height, width).
|
|
@@ -1120,15 +1080,14 @@ class Masks(BaseTensor):
|
|
|
1120
1080
|
@property
|
|
1121
1081
|
@lru_cache(maxsize=1)
|
|
1122
1082
|
def xyn(self) -> list[np.ndarray]:
|
|
1123
|
-
"""
|
|
1124
|
-
Return normalized xy-coordinates of the segmentation masks.
|
|
1083
|
+
"""Return normalized xy-coordinates of the segmentation masks.
|
|
1125
1084
|
|
|
1126
|
-
This property calculates and caches the normalized xy-coordinates of the segmentation masks. The coordinates
|
|
1127
|
-
|
|
1085
|
+
This property calculates and caches the normalized xy-coordinates of the segmentation masks. The coordinates are
|
|
1086
|
+
normalized relative to the original image shape.
|
|
1128
1087
|
|
|
1129
1088
|
Returns:
|
|
1130
|
-
(list[np.ndarray]): A list of numpy arrays, where each array contains the normalized xy-coordinates
|
|
1131
|
-
|
|
1089
|
+
(list[np.ndarray]): A list of numpy arrays, where each array contains the normalized xy-coordinates of a
|
|
1090
|
+
single segmentation mask. Each array has shape (N, 2), where N is the number of points in the
|
|
1132
1091
|
mask contour.
|
|
1133
1092
|
|
|
1134
1093
|
Examples:
|
|
@@ -1145,16 +1104,14 @@ class Masks(BaseTensor):
|
|
|
1145
1104
|
@property
|
|
1146
1105
|
@lru_cache(maxsize=1)
|
|
1147
1106
|
def xy(self) -> list[np.ndarray]:
|
|
1148
|
-
"""
|
|
1149
|
-
Return the [x, y] pixel coordinates for each segment in the mask tensor.
|
|
1107
|
+
"""Return the [x, y] pixel coordinates for each segment in the mask tensor.
|
|
1150
1108
|
|
|
1151
|
-
This property calculates and returns a list of pixel coordinates for each segmentation mask in the
|
|
1152
|
-
|
|
1109
|
+
This property calculates and returns a list of pixel coordinates for each segmentation mask in the Masks object.
|
|
1110
|
+
The coordinates are scaled to match the original image dimensions.
|
|
1153
1111
|
|
|
1154
1112
|
Returns:
|
|
1155
|
-
(list[np.ndarray]): A list of numpy arrays, where each array contains the [x, y] pixel
|
|
1156
|
-
|
|
1157
|
-
number of points in the segment.
|
|
1113
|
+
(list[np.ndarray]): A list of numpy arrays, where each array contains the [x, y] pixel coordinates for a
|
|
1114
|
+
single segmentation mask. Each array has shape (N, 2), where N is the number of points in the segment.
|
|
1158
1115
|
|
|
1159
1116
|
Examples:
|
|
1160
1117
|
>>> results = model("image.jpg")
|
|
@@ -1170,12 +1127,10 @@ class Masks(BaseTensor):
|
|
|
1170
1127
|
|
|
1171
1128
|
|
|
1172
1129
|
class Keypoints(BaseTensor):
|
|
1173
|
-
"""
|
|
1174
|
-
A class for storing and manipulating detection keypoints.
|
|
1130
|
+
"""A class for storing and manipulating detection keypoints.
|
|
1175
1131
|
|
|
1176
|
-
This class encapsulates functionality for handling keypoint data, including coordinate manipulation,
|
|
1177
|
-
|
|
1178
|
-
information.
|
|
1132
|
+
This class encapsulates functionality for handling keypoint data, including coordinate manipulation, normalization,
|
|
1133
|
+
and confidence values. It supports keypoint detection results with optional visibility information.
|
|
1179
1134
|
|
|
1180
1135
|
Attributes:
|
|
1181
1136
|
data (torch.Tensor): The raw tensor containing keypoint data.
|
|
@@ -1203,11 +1158,10 @@ class Keypoints(BaseTensor):
|
|
|
1203
1158
|
"""
|
|
1204
1159
|
|
|
1205
1160
|
def __init__(self, keypoints: torch.Tensor | np.ndarray, orig_shape: tuple[int, int]) -> None:
|
|
1206
|
-
"""
|
|
1207
|
-
Initialize the Keypoints object with detection keypoints and original image dimensions.
|
|
1161
|
+
"""Initialize the Keypoints object with detection keypoints and original image dimensions.
|
|
1208
1162
|
|
|
1209
|
-
This method processes the input keypoints tensor, handling both 2D and 3D formats. For 3D tensors
|
|
1210
|
-
|
|
1163
|
+
This method processes the input keypoints tensor, handling both 2D and 3D formats. For 3D tensors (x, y,
|
|
1164
|
+
confidence), it masks out low-confidence keypoints by setting their coordinates to zero.
|
|
1211
1165
|
|
|
1212
1166
|
Args:
|
|
1213
1167
|
keypoints (torch.Tensor): A tensor containing keypoint data. Shape can be either:
|
|
@@ -1228,12 +1182,11 @@ class Keypoints(BaseTensor):
|
|
|
1228
1182
|
@property
|
|
1229
1183
|
@lru_cache(maxsize=1)
|
|
1230
1184
|
def xy(self) -> torch.Tensor | np.ndarray:
|
|
1231
|
-
"""
|
|
1232
|
-
Return x, y coordinates of keypoints.
|
|
1185
|
+
"""Return x, y coordinates of keypoints.
|
|
1233
1186
|
|
|
1234
1187
|
Returns:
|
|
1235
|
-
(torch.Tensor): A tensor containing the x, y coordinates of keypoints with shape (N, K, 2), where N is
|
|
1236
|
-
|
|
1188
|
+
(torch.Tensor): A tensor containing the x, y coordinates of keypoints with shape (N, K, 2), where N is the
|
|
1189
|
+
number of detections and K is the number of keypoints per detection.
|
|
1237
1190
|
|
|
1238
1191
|
Examples:
|
|
1239
1192
|
>>> results = model("image.jpg")
|
|
@@ -1252,13 +1205,12 @@ class Keypoints(BaseTensor):
|
|
|
1252
1205
|
@property
|
|
1253
1206
|
@lru_cache(maxsize=1)
|
|
1254
1207
|
def xyn(self) -> torch.Tensor | np.ndarray:
|
|
1255
|
-
"""
|
|
1256
|
-
Return normalized coordinates (x, y) of keypoints relative to the original image size.
|
|
1208
|
+
"""Return normalized coordinates (x, y) of keypoints relative to the original image size.
|
|
1257
1209
|
|
|
1258
1210
|
Returns:
|
|
1259
1211
|
(torch.Tensor | np.ndarray): A tensor or array of shape (N, K, 2) containing normalized keypoint
|
|
1260
|
-
coordinates, where N is the number of instances, K is the number of keypoints, and the last
|
|
1261
|
-
|
|
1212
|
+
coordinates, where N is the number of instances, K is the number of keypoints, and the last dimension
|
|
1213
|
+
contains [x, y] values in the range [0, 1].
|
|
1262
1214
|
|
|
1263
1215
|
Examples:
|
|
1264
1216
|
>>> keypoints = Keypoints(torch.rand(1, 17, 2), orig_shape=(480, 640))
|
|
@@ -1274,13 +1226,11 @@ class Keypoints(BaseTensor):
|
|
|
1274
1226
|
@property
|
|
1275
1227
|
@lru_cache(maxsize=1)
|
|
1276
1228
|
def conf(self) -> torch.Tensor | np.ndarray | None:
|
|
1277
|
-
"""
|
|
1278
|
-
Return confidence values for each keypoint.
|
|
1229
|
+
"""Return confidence values for each keypoint.
|
|
1279
1230
|
|
|
1280
1231
|
Returns:
|
|
1281
|
-
(torch.Tensor | None): A tensor containing confidence scores for each keypoint if available,
|
|
1282
|
-
|
|
1283
|
-
for single detection.
|
|
1232
|
+
(torch.Tensor | None): A tensor containing confidence scores for each keypoint if available, otherwise None.
|
|
1233
|
+
Shape is (num_detections, num_keypoints) for batched data or (num_keypoints,) for single detection.
|
|
1284
1234
|
|
|
1285
1235
|
Examples:
|
|
1286
1236
|
>>> keypoints = Keypoints(torch.rand(1, 17, 3), orig_shape=(640, 640)) # 1 detection, 17 keypoints
|
|
@@ -1291,11 +1241,10 @@ class Keypoints(BaseTensor):
|
|
|
1291
1241
|
|
|
1292
1242
|
|
|
1293
1243
|
class Probs(BaseTensor):
|
|
1294
|
-
"""
|
|
1295
|
-
A class for storing and manipulating classification probabilities.
|
|
1244
|
+
"""A class for storing and manipulating classification probabilities.
|
|
1296
1245
|
|
|
1297
|
-
This class extends BaseTensor and provides methods for accessing and manipulating
|
|
1298
|
-
|
|
1246
|
+
This class extends BaseTensor and provides methods for accessing and manipulating classification probabilities,
|
|
1247
|
+
including top-1 and top-5 predictions.
|
|
1299
1248
|
|
|
1300
1249
|
Attributes:
|
|
1301
1250
|
data (torch.Tensor | np.ndarray): The raw tensor or array containing classification probabilities.
|
|
@@ -1325,16 +1274,15 @@ class Probs(BaseTensor):
|
|
|
1325
1274
|
"""
|
|
1326
1275
|
|
|
1327
1276
|
def __init__(self, probs: torch.Tensor | np.ndarray, orig_shape: tuple[int, int] | None = None) -> None:
|
|
1328
|
-
"""
|
|
1329
|
-
Initialize the Probs class with classification probabilities.
|
|
1277
|
+
"""Initialize the Probs class with classification probabilities.
|
|
1330
1278
|
|
|
1331
1279
|
This class stores and manages classification probabilities, providing easy access to top predictions and their
|
|
1332
1280
|
confidences.
|
|
1333
1281
|
|
|
1334
1282
|
Args:
|
|
1335
1283
|
probs (torch.Tensor | np.ndarray): A 1D tensor or array of classification probabilities.
|
|
1336
|
-
orig_shape (tuple | None): The original image shape as (height, width). Not used in this class but kept
|
|
1337
|
-
|
|
1284
|
+
orig_shape (tuple | None): The original image shape as (height, width). Not used in this class but kept for
|
|
1285
|
+
consistency with other result classes.
|
|
1338
1286
|
|
|
1339
1287
|
Attributes:
|
|
1340
1288
|
data (torch.Tensor | np.ndarray): The raw tensor or array containing classification probabilities.
|
|
@@ -1359,8 +1307,7 @@ class Probs(BaseTensor):
|
|
|
1359
1307
|
@property
|
|
1360
1308
|
@lru_cache(maxsize=1)
|
|
1361
1309
|
def top1(self) -> int:
|
|
1362
|
-
"""
|
|
1363
|
-
Return the index of the class with the highest probability.
|
|
1310
|
+
"""Return the index of the class with the highest probability.
|
|
1364
1311
|
|
|
1365
1312
|
Returns:
|
|
1366
1313
|
(int): Index of the class with the highest probability.
|
|
@@ -1375,8 +1322,7 @@ class Probs(BaseTensor):
|
|
|
1375
1322
|
@property
|
|
1376
1323
|
@lru_cache(maxsize=1)
|
|
1377
1324
|
def top5(self) -> list[int]:
|
|
1378
|
-
"""
|
|
1379
|
-
Return the indices of the top 5 class probabilities.
|
|
1325
|
+
"""Return the indices of the top 5 class probabilities.
|
|
1380
1326
|
|
|
1381
1327
|
Returns:
|
|
1382
1328
|
(list[int]): A list containing the indices of the top 5 class probabilities, sorted in descending order.
|
|
@@ -1391,8 +1337,7 @@ class Probs(BaseTensor):
|
|
|
1391
1337
|
@property
|
|
1392
1338
|
@lru_cache(maxsize=1)
|
|
1393
1339
|
def top1conf(self) -> torch.Tensor | np.ndarray:
|
|
1394
|
-
"""
|
|
1395
|
-
Return the confidence score of the highest probability class.
|
|
1340
|
+
"""Return the confidence score of the highest probability class.
|
|
1396
1341
|
|
|
1397
1342
|
This property retrieves the confidence score (probability) of the class with the highest predicted probability
|
|
1398
1343
|
from the classification results.
|
|
@@ -1411,16 +1356,15 @@ class Probs(BaseTensor):
|
|
|
1411
1356
|
@property
|
|
1412
1357
|
@lru_cache(maxsize=1)
|
|
1413
1358
|
def top5conf(self) -> torch.Tensor | np.ndarray:
|
|
1414
|
-
"""
|
|
1415
|
-
Return confidence scores for the top 5 classification predictions.
|
|
1359
|
+
"""Return confidence scores for the top 5 classification predictions.
|
|
1416
1360
|
|
|
1417
|
-
This property retrieves the confidence scores corresponding to the top 5 class probabilities
|
|
1418
|
-
|
|
1419
|
-
|
|
1361
|
+
This property retrieves the confidence scores corresponding to the top 5 class probabilities predicted by the
|
|
1362
|
+
model. It provides a quick way to access the most likely class predictions along with their associated
|
|
1363
|
+
confidence levels.
|
|
1420
1364
|
|
|
1421
1365
|
Returns:
|
|
1422
|
-
(torch.Tensor | np.ndarray): A tensor or array containing the confidence scores for the
|
|
1423
|
-
|
|
1366
|
+
(torch.Tensor | np.ndarray): A tensor or array containing the confidence scores for the top 5 predicted
|
|
1367
|
+
classes, sorted in descending order of probability.
|
|
1424
1368
|
|
|
1425
1369
|
Examples:
|
|
1426
1370
|
>>> results = model("image.jpg")
|
|
@@ -1432,12 +1376,10 @@ class Probs(BaseTensor):
|
|
|
1432
1376
|
|
|
1433
1377
|
|
|
1434
1378
|
class OBB(BaseTensor):
|
|
1435
|
-
"""
|
|
1436
|
-
A class for storing and manipulating Oriented Bounding Boxes (OBB).
|
|
1379
|
+
"""A class for storing and manipulating Oriented Bounding Boxes (OBB).
|
|
1437
1380
|
|
|
1438
|
-
This class provides functionality to handle oriented bounding boxes, including conversion between
|
|
1439
|
-
|
|
1440
|
-
both tracking and non-tracking scenarios.
|
|
1381
|
+
This class provides functionality to handle oriented bounding boxes, including conversion between different formats,
|
|
1382
|
+
normalization, and access to various properties of the boxes. It supports both tracking and non-tracking scenarios.
|
|
1441
1383
|
|
|
1442
1384
|
Attributes:
|
|
1443
1385
|
data (torch.Tensor): The raw OBB tensor containing box coordinates and associated data.
|
|
@@ -1466,16 +1408,15 @@ class OBB(BaseTensor):
|
|
|
1466
1408
|
"""
|
|
1467
1409
|
|
|
1468
1410
|
def __init__(self, boxes: torch.Tensor | np.ndarray, orig_shape: tuple[int, int]) -> None:
|
|
1469
|
-
"""
|
|
1470
|
-
Initialize an OBB (Oriented Bounding Box) instance with oriented bounding box data and original image shape.
|
|
1411
|
+
"""Initialize an OBB (Oriented Bounding Box) instance with oriented bounding box data and original image shape.
|
|
1471
1412
|
|
|
1472
|
-
This class stores and manipulates Oriented Bounding Boxes (OBB) for object detection tasks. It provides
|
|
1473
|
-
|
|
1413
|
+
This class stores and manipulates Oriented Bounding Boxes (OBB) for object detection tasks. It provides various
|
|
1414
|
+
properties and methods to access and transform the OBB data.
|
|
1474
1415
|
|
|
1475
1416
|
Args:
|
|
1476
|
-
boxes (torch.Tensor | np.ndarray): A tensor or numpy array containing the detection boxes,
|
|
1477
|
-
|
|
1478
|
-
|
|
1417
|
+
boxes (torch.Tensor | np.ndarray): A tensor or numpy array containing the detection boxes, with shape
|
|
1418
|
+
(num_boxes, 7) or (num_boxes, 8). The last two columns contain confidence and class values. If present,
|
|
1419
|
+
the third last column contains track IDs, and the fifth column contains rotation.
|
|
1479
1420
|
orig_shape (tuple[int, int]): Original image size, in the format (height, width).
|
|
1480
1421
|
|
|
1481
1422
|
Attributes:
|
|
@@ -1503,8 +1444,7 @@ class OBB(BaseTensor):
|
|
|
1503
1444
|
|
|
1504
1445
|
@property
|
|
1505
1446
|
def xywhr(self) -> torch.Tensor | np.ndarray:
|
|
1506
|
-
"""
|
|
1507
|
-
Return boxes in [x_center, y_center, width, height, rotation] format.
|
|
1447
|
+
"""Return boxes in [x_center, y_center, width, height, rotation] format.
|
|
1508
1448
|
|
|
1509
1449
|
Returns:
|
|
1510
1450
|
(torch.Tensor | np.ndarray): A tensor or numpy array containing the oriented bounding boxes with format
|
|
@@ -1521,15 +1461,14 @@ class OBB(BaseTensor):
|
|
|
1521
1461
|
|
|
1522
1462
|
@property
|
|
1523
1463
|
def conf(self) -> torch.Tensor | np.ndarray:
|
|
1524
|
-
"""
|
|
1525
|
-
Return the confidence scores for Oriented Bounding Boxes (OBBs).
|
|
1464
|
+
"""Return the confidence scores for Oriented Bounding Boxes (OBBs).
|
|
1526
1465
|
|
|
1527
1466
|
This property retrieves the confidence values associated with each OBB detection. The confidence score
|
|
1528
1467
|
represents the model's certainty in the detection.
|
|
1529
1468
|
|
|
1530
1469
|
Returns:
|
|
1531
|
-
(torch.Tensor | np.ndarray): A tensor or numpy array of shape (N,) containing confidence scores
|
|
1532
|
-
|
|
1470
|
+
(torch.Tensor | np.ndarray): A tensor or numpy array of shape (N,) containing confidence scores for N
|
|
1471
|
+
detections, where each score is in the range [0, 1].
|
|
1533
1472
|
|
|
1534
1473
|
Examples:
|
|
1535
1474
|
>>> results = model("image.jpg")
|
|
@@ -1541,12 +1480,11 @@ class OBB(BaseTensor):
|
|
|
1541
1480
|
|
|
1542
1481
|
@property
|
|
1543
1482
|
def cls(self) -> torch.Tensor | np.ndarray:
|
|
1544
|
-
"""
|
|
1545
|
-
Return the class values of the oriented bounding boxes.
|
|
1483
|
+
"""Return the class values of the oriented bounding boxes.
|
|
1546
1484
|
|
|
1547
1485
|
Returns:
|
|
1548
|
-
(torch.Tensor | np.ndarray): A tensor or numpy array containing the class values for each oriented
|
|
1549
|
-
|
|
1486
|
+
(torch.Tensor | np.ndarray): A tensor or numpy array containing the class values for each oriented bounding
|
|
1487
|
+
box. The shape is (N,), where N is the number of boxes.
|
|
1550
1488
|
|
|
1551
1489
|
Examples:
|
|
1552
1490
|
>>> results = model("image.jpg")
|
|
@@ -1559,12 +1497,11 @@ class OBB(BaseTensor):
|
|
|
1559
1497
|
|
|
1560
1498
|
@property
|
|
1561
1499
|
def id(self) -> torch.Tensor | np.ndarray | None:
|
|
1562
|
-
"""
|
|
1563
|
-
Return the tracking IDs of the oriented bounding boxes (if available).
|
|
1500
|
+
"""Return the tracking IDs of the oriented bounding boxes (if available).
|
|
1564
1501
|
|
|
1565
1502
|
Returns:
|
|
1566
|
-
(torch.Tensor | np.ndarray | None): A tensor or numpy array containing the tracking IDs for each
|
|
1567
|
-
|
|
1503
|
+
(torch.Tensor | np.ndarray | None): A tensor or numpy array containing the tracking IDs for each oriented
|
|
1504
|
+
bounding box. Returns None if tracking IDs are not available.
|
|
1568
1505
|
|
|
1569
1506
|
Examples:
|
|
1570
1507
|
>>> results = model("image.jpg", tracker=True) # Run inference with tracking
|
|
@@ -1579,12 +1516,11 @@ class OBB(BaseTensor):
|
|
|
1579
1516
|
@property
|
|
1580
1517
|
@lru_cache(maxsize=2)
|
|
1581
1518
|
def xyxyxyxy(self) -> torch.Tensor | np.ndarray:
|
|
1582
|
-
"""
|
|
1583
|
-
Convert OBB format to 8-point (xyxyxyxy) coordinate format for rotated bounding boxes.
|
|
1519
|
+
"""Convert OBB format to 8-point (xyxyxyxy) coordinate format for rotated bounding boxes.
|
|
1584
1520
|
|
|
1585
1521
|
Returns:
|
|
1586
|
-
(torch.Tensor | np.ndarray): Rotated bounding boxes in xyxyxyxy format with shape (N, 4, 2), where N is
|
|
1587
|
-
|
|
1522
|
+
(torch.Tensor | np.ndarray): Rotated bounding boxes in xyxyxyxy format with shape (N, 4, 2), where N is the
|
|
1523
|
+
number of boxes. Each box is represented by 4 points (x, y), starting from the top-left corner and
|
|
1588
1524
|
moving clockwise.
|
|
1589
1525
|
|
|
1590
1526
|
Examples:
|
|
@@ -1598,13 +1534,12 @@ class OBB(BaseTensor):
|
|
|
1598
1534
|
@property
|
|
1599
1535
|
@lru_cache(maxsize=2)
|
|
1600
1536
|
def xyxyxyxyn(self) -> torch.Tensor | np.ndarray:
|
|
1601
|
-
"""
|
|
1602
|
-
Convert rotated bounding boxes to normalized xyxyxyxy format.
|
|
1537
|
+
"""Convert rotated bounding boxes to normalized xyxyxyxy format.
|
|
1603
1538
|
|
|
1604
1539
|
Returns:
|
|
1605
1540
|
(torch.Tensor | np.ndarray): Normalized rotated bounding boxes in xyxyxyxy format with shape (N, 4, 2),
|
|
1606
|
-
where N is the number of boxes. Each box is represented by 4 points (x, y), normalized relative to
|
|
1607
|
-
|
|
1541
|
+
where N is the number of boxes. Each box is represented by 4 points (x, y), normalized relative to the
|
|
1542
|
+
original image dimensions.
|
|
1608
1543
|
|
|
1609
1544
|
Examples:
|
|
1610
1545
|
>>> obb = OBB(torch.rand(10, 7), orig_shape=(640, 480)) # 10 random OBBs
|
|
@@ -1620,16 +1555,15 @@ class OBB(BaseTensor):
|
|
|
1620
1555
|
@property
|
|
1621
1556
|
@lru_cache(maxsize=2)
|
|
1622
1557
|
def xyxy(self) -> torch.Tensor | np.ndarray:
|
|
1623
|
-
"""
|
|
1624
|
-
Convert oriented bounding boxes (OBB) to axis-aligned bounding boxes in xyxy format.
|
|
1558
|
+
"""Convert oriented bounding boxes (OBB) to axis-aligned bounding boxes in xyxy format.
|
|
1625
1559
|
|
|
1626
|
-
This property calculates the minimal enclosing rectangle for each oriented bounding box and returns it in
|
|
1627
|
-
|
|
1628
|
-
|
|
1560
|
+
This property calculates the minimal enclosing rectangle for each oriented bounding box and returns it in xyxy
|
|
1561
|
+
format (x1, y1, x2, y2). This is useful for operations that require axis-aligned bounding boxes, such as IoU
|
|
1562
|
+
calculation with non-rotated boxes.
|
|
1629
1563
|
|
|
1630
1564
|
Returns:
|
|
1631
|
-
(torch.Tensor | np.ndarray): Axis-aligned bounding boxes in xyxy format with shape (N, 4), where N
|
|
1632
|
-
|
|
1565
|
+
(torch.Tensor | np.ndarray): Axis-aligned bounding boxes in xyxy format with shape (N, 4), where N is the
|
|
1566
|
+
number of boxes. Each row contains [x1, y1, x2, y2] coordinates.
|
|
1633
1567
|
|
|
1634
1568
|
Examples:
|
|
1635
1569
|
>>> import torch
|