dgenerate-ultralytics-headless 8.3.143__py3-none-any.whl → 8.3.145__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.143.dist-info → dgenerate_ultralytics_headless-8.3.145.dist-info}/METADATA +2 -2
- dgenerate_ultralytics_headless-8.3.145.dist-info/RECORD +272 -0
- 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 +52 -51
- ultralytics/engine/predictor.py +37 -28
- ultralytics/engine/results.py +191 -161
- 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 +4 -6
- ultralytics/solutions/analytics.py +7 -4
- ultralytics/solutions/config.py +10 -10
- ultralytics/solutions/distance_calculation.py +11 -10
- ultralytics/solutions/heatmap.py +2 -2
- ultralytics/solutions/instance_segmentation.py +7 -4
- ultralytics/solutions/object_blurrer.py +3 -3
- ultralytics/solutions/object_counter.py +15 -11
- 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 +189 -79
- 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 +45 -29
- 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
- dgenerate_ultralytics_headless-8.3.143.dist-info/RECORD +0 -272
- {dgenerate_ultralytics_headless-8.3.143.dist-info → dgenerate_ultralytics_headless-8.3.145.dist-info}/WHEEL +0 -0
- {dgenerate_ultralytics_headless-8.3.143.dist-info → dgenerate_ultralytics_headless-8.3.145.dist-info}/entry_points.txt +0 -0
- {dgenerate_ultralytics_headless-8.3.143.dist-info → dgenerate_ultralytics_headless-8.3.145.dist-info}/licenses/LICENSE +0 -0
- {dgenerate_ultralytics_headless-8.3.143.dist-info → dgenerate_ultralytics_headless-8.3.145.dist-info}/top_level.txt +0 -0
ultralytics/engine/predictor.py
CHANGED
@@ -36,6 +36,7 @@ import platform
|
|
36
36
|
import re
|
37
37
|
import threading
|
38
38
|
from pathlib import Path
|
39
|
+
from typing import Any, Dict, List, Optional, Union
|
39
40
|
|
40
41
|
import cv2
|
41
42
|
import numpy as np
|
@@ -78,15 +79,15 @@ class BasePredictor:
|
|
78
79
|
data (dict): Data configuration.
|
79
80
|
device (torch.device): Device used for prediction.
|
80
81
|
dataset (Dataset): Dataset used for prediction.
|
81
|
-
vid_writer (
|
82
|
-
plotted_img (
|
82
|
+
vid_writer (Dict[str, cv2.VideoWriter]): Dictionary of {save_path: video_writer} for saving video output.
|
83
|
+
plotted_img (np.ndarray): Last plotted image.
|
83
84
|
source_type (SimpleNamespace): Type of input source.
|
84
85
|
seen (int): Number of images processed.
|
85
|
-
windows (
|
86
|
+
windows (List[str]): List of window names for visualization.
|
86
87
|
batch (tuple): Current batch data.
|
87
|
-
results (
|
88
|
+
results (List[Any]): Current batch results.
|
88
89
|
transforms (callable): Image transforms for classification.
|
89
|
-
callbacks (
|
90
|
+
callbacks (Dict[str, List[callable]]): Callback functions for different events.
|
90
91
|
txt_path (Path): Path to save text results.
|
91
92
|
_lock (threading.Lock): Lock for thread-safe inference.
|
92
93
|
|
@@ -105,14 +106,19 @@ class BasePredictor:
|
|
105
106
|
add_callback: Register a new callback function.
|
106
107
|
"""
|
107
108
|
|
108
|
-
def __init__(
|
109
|
+
def __init__(
|
110
|
+
self,
|
111
|
+
cfg=DEFAULT_CFG,
|
112
|
+
overrides: Optional[Dict[str, Any]] = None,
|
113
|
+
_callbacks: Optional[Dict[str, List[callable]]] = None,
|
114
|
+
):
|
109
115
|
"""
|
110
116
|
Initialize the BasePredictor class.
|
111
117
|
|
112
118
|
Args:
|
113
119
|
cfg (str | dict): Path to a configuration file or a configuration dictionary.
|
114
|
-
overrides (dict
|
115
|
-
_callbacks (dict
|
120
|
+
overrides (dict, optional): Configuration overrides.
|
121
|
+
_callbacks (dict, optional): Dictionary of callback functions.
|
116
122
|
"""
|
117
123
|
self.args = get_cfg(cfg, overrides)
|
118
124
|
self.save_dir = get_save_dir(self.args)
|
@@ -141,12 +147,15 @@ class BasePredictor:
|
|
141
147
|
self._lock = threading.Lock() # for automatic thread-safe inference
|
142
148
|
callbacks.add_integration_callbacks(self)
|
143
149
|
|
144
|
-
def preprocess(self, im):
|
150
|
+
def preprocess(self, im: Union[torch.Tensor, List[np.ndarray]]) -> torch.Tensor:
|
145
151
|
"""
|
146
|
-
|
152
|
+
Prepare input image before inference.
|
147
153
|
|
148
154
|
Args:
|
149
|
-
im (torch.Tensor | List
|
155
|
+
im (torch.Tensor | List[np.ndarray]): Images of shape (N, 3, H, W) for tensor, [(H, W, 3) x N] for list.
|
156
|
+
|
157
|
+
Returns:
|
158
|
+
(torch.Tensor): Preprocessed image tensor of shape (N, 3, H, W).
|
150
159
|
"""
|
151
160
|
not_tensor = not isinstance(im, torch.Tensor)
|
152
161
|
if not_tensor:
|
@@ -163,7 +172,7 @@ class BasePredictor:
|
|
163
172
|
im /= 255 # 0 - 255 to 0.0 - 1.0
|
164
173
|
return im
|
165
174
|
|
166
|
-
def inference(self, im, *args, **kwargs):
|
175
|
+
def inference(self, im: torch.Tensor, *args, **kwargs):
|
167
176
|
"""Run inference on a given image using the specified model and arguments."""
|
168
177
|
visualize = (
|
169
178
|
increment_path(self.save_dir / Path(self.batch[0][0]).stem, mkdir=True)
|
@@ -172,15 +181,15 @@ class BasePredictor:
|
|
172
181
|
)
|
173
182
|
return self.model(im, augment=self.args.augment, visualize=visualize, embed=self.args.embed, *args, **kwargs)
|
174
183
|
|
175
|
-
def pre_transform(self, im):
|
184
|
+
def pre_transform(self, im: List[np.ndarray]) -> List[np.ndarray]:
|
176
185
|
"""
|
177
186
|
Pre-transform input image before inference.
|
178
187
|
|
179
188
|
Args:
|
180
|
-
im (List[np.ndarray]):
|
189
|
+
im (List[np.ndarray]): List of images with shape [(H, W, 3) x N].
|
181
190
|
|
182
191
|
Returns:
|
183
|
-
(List[np.ndarray]):
|
192
|
+
(List[np.ndarray]): List of transformed images.
|
184
193
|
"""
|
185
194
|
same_shapes = len({x.shape for x in im}) == 1
|
186
195
|
letterbox = LetterBox(
|
@@ -196,14 +205,14 @@ class BasePredictor:
|
|
196
205
|
"""Post-process predictions for an image and return them."""
|
197
206
|
return preds
|
198
207
|
|
199
|
-
def __call__(self, source=None, model=None, stream=False, *args, **kwargs):
|
208
|
+
def __call__(self, source=None, model=None, stream: bool = False, *args, **kwargs):
|
200
209
|
"""
|
201
210
|
Perform inference on an image or stream.
|
202
211
|
|
203
212
|
Args:
|
204
|
-
source (str | Path | List[str] | List[Path] | List[np.ndarray] | np.ndarray | torch.Tensor
|
213
|
+
source (str | Path | List[str] | List[Path] | List[np.ndarray] | np.ndarray | torch.Tensor, optional):
|
205
214
|
Source for inference.
|
206
|
-
model (str | Path | torch.nn.Module
|
215
|
+
model (str | Path | torch.nn.Module, optional): Model for inference.
|
207
216
|
stream (bool): Whether to stream the inference results. If True, returns a generator.
|
208
217
|
*args (Any): Additional arguments for the inference method.
|
209
218
|
**kwargs (Any): Additional keyword arguments for the inference method.
|
@@ -226,9 +235,9 @@ class BasePredictor:
|
|
226
235
|
generator without storing results.
|
227
236
|
|
228
237
|
Args:
|
229
|
-
source (str | Path | List[str] | List[Path] | List[np.ndarray] | np.ndarray | torch.Tensor
|
238
|
+
source (str | Path | List[str] | List[Path] | List[np.ndarray] | np.ndarray | torch.Tensor, optional):
|
230
239
|
Source for inference.
|
231
|
-
model (str | Path | torch.nn.Module
|
240
|
+
model (str | Path | torch.nn.Module, optional): Model for inference.
|
232
241
|
|
233
242
|
Note:
|
234
243
|
Do not modify this function or remove the generator. The generator ensures that no outputs are
|
@@ -270,9 +279,9 @@ class BasePredictor:
|
|
270
279
|
Stream real-time inference on camera feed and save results to file.
|
271
280
|
|
272
281
|
Args:
|
273
|
-
source (str | Path | List[str] | List[Path] | List[np.ndarray] | np.ndarray | torch.Tensor
|
282
|
+
source (str | Path | List[str] | List[Path] | List[np.ndarray] | np.ndarray | torch.Tensor, optional):
|
274
283
|
Source for inference.
|
275
|
-
model (str | Path | torch.nn.Module
|
284
|
+
model (str | Path | torch.nn.Module, optional): Model for inference.
|
276
285
|
*args (Any): Additional arguments for the inference method.
|
277
286
|
**kwargs (Any): Additional keyword arguments for the inference method.
|
278
287
|
|
@@ -365,12 +374,12 @@ class BasePredictor:
|
|
365
374
|
LOGGER.info(f"Results saved to {colorstr('bold', self.save_dir)}{s}")
|
366
375
|
self.run_callbacks("on_predict_end")
|
367
376
|
|
368
|
-
def setup_model(self, model, verbose=True):
|
377
|
+
def setup_model(self, model, verbose: bool = True):
|
369
378
|
"""
|
370
379
|
Initialize YOLO model with given parameters and set it to evaluation mode.
|
371
380
|
|
372
381
|
Args:
|
373
|
-
model (str | Path | torch.nn.Module
|
382
|
+
model (str | Path | torch.nn.Module, optional): Model to load or use.
|
374
383
|
verbose (bool): Whether to print verbose output.
|
375
384
|
"""
|
376
385
|
self.model = AutoBackend(
|
@@ -390,7 +399,7 @@ class BasePredictor:
|
|
390
399
|
self.args.imgsz = self.model.imgsz # reuse imgsz from export metadata
|
391
400
|
self.model.eval()
|
392
401
|
|
393
|
-
def write_results(self, i, p, im, s):
|
402
|
+
def write_results(self, i: int, p: Path, im: torch.Tensor, s: List[str]) -> str:
|
394
403
|
"""
|
395
404
|
Write inference results to a file or directory.
|
396
405
|
|
@@ -441,7 +450,7 @@ class BasePredictor:
|
|
441
450
|
|
442
451
|
return string
|
443
452
|
|
444
|
-
def save_predicted_images(self, save_path="", frame=0):
|
453
|
+
def save_predicted_images(self, save_path: str = "", frame: int = 0):
|
445
454
|
"""
|
446
455
|
Save video predictions as mp4 or images as jpg at specified path.
|
447
456
|
|
@@ -475,7 +484,7 @@ class BasePredictor:
|
|
475
484
|
else:
|
476
485
|
cv2.imwrite(str(Path(save_path).with_suffix(".jpg")), im) # save to JPG for best support
|
477
486
|
|
478
|
-
def show(self, p=""):
|
487
|
+
def show(self, p: str = ""):
|
479
488
|
"""Display an image in a window."""
|
480
489
|
im = self.plotted_img
|
481
490
|
if platform.system() == "Linux" and p not in self.windows:
|
@@ -490,6 +499,6 @@ class BasePredictor:
|
|
490
499
|
for callback in self.callbacks.get(event, []):
|
491
500
|
callback(self)
|
492
501
|
|
493
|
-
def add_callback(self, event: str, func):
|
502
|
+
def add_callback(self, event: str, func: callable):
|
494
503
|
"""Add a callback function for a specific event."""
|
495
504
|
self.callbacks[event].append(func)
|