dgenerate-ultralytics-headless 8.3.193__py3-none-any.whl → 8.3.195__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.193.dist-info → dgenerate_ultralytics_headless-8.3.195.dist-info}/METADATA +1 -2
- {dgenerate_ultralytics_headless-8.3.193.dist-info → dgenerate_ultralytics_headless-8.3.195.dist-info}/RECORD +104 -102
- tests/test_exports.py +8 -5
- tests/test_python.py +2 -2
- ultralytics/__init__.py +1 -1
- ultralytics/cfg/__init__.py +8 -8
- ultralytics/data/annotator.py +1 -1
- ultralytics/data/augment.py +75 -75
- ultralytics/data/base.py +12 -12
- ultralytics/data/converter.py +4 -4
- ultralytics/data/dataset.py +7 -7
- ultralytics/data/loaders.py +15 -15
- ultralytics/data/split_dota.py +10 -10
- ultralytics/data/utils.py +12 -12
- ultralytics/engine/exporter.py +4 -4
- ultralytics/engine/model.py +13 -13
- ultralytics/engine/predictor.py +13 -13
- ultralytics/engine/results.py +21 -21
- ultralytics/hub/__init__.py +1 -2
- ultralytics/hub/google/__init__.py +2 -2
- ultralytics/hub/session.py +7 -7
- ultralytics/hub/utils.py +0 -101
- ultralytics/models/fastsam/model.py +5 -5
- ultralytics/models/fastsam/predict.py +11 -11
- ultralytics/models/nas/model.py +1 -1
- ultralytics/models/rtdetr/predict.py +2 -2
- ultralytics/models/rtdetr/val.py +4 -4
- ultralytics/models/sam/amg.py +6 -6
- ultralytics/models/sam/build.py +9 -9
- ultralytics/models/sam/model.py +7 -7
- ultralytics/models/sam/modules/blocks.py +6 -6
- ultralytics/models/sam/modules/decoders.py +1 -1
- ultralytics/models/sam/modules/encoders.py +27 -27
- ultralytics/models/sam/modules/sam.py +4 -4
- ultralytics/models/sam/modules/tiny_encoder.py +18 -18
- ultralytics/models/sam/modules/utils.py +8 -8
- ultralytics/models/sam/predict.py +66 -66
- ultralytics/models/utils/loss.py +22 -22
- ultralytics/models/utils/ops.py +8 -8
- ultralytics/models/yolo/classify/predict.py +2 -2
- ultralytics/models/yolo/classify/train.py +8 -8
- ultralytics/models/yolo/classify/val.py +4 -4
- ultralytics/models/yolo/detect/predict.py +3 -3
- ultralytics/models/yolo/detect/train.py +6 -6
- ultralytics/models/yolo/detect/val.py +32 -32
- ultralytics/models/yolo/model.py +6 -6
- ultralytics/models/yolo/obb/train.py +1 -1
- ultralytics/models/yolo/obb/val.py +13 -13
- ultralytics/models/yolo/pose/val.py +11 -11
- ultralytics/models/yolo/segment/predict.py +4 -4
- ultralytics/models/yolo/segment/train.py +1 -1
- ultralytics/models/yolo/segment/val.py +14 -14
- ultralytics/models/yolo/world/train.py +9 -9
- ultralytics/models/yolo/world/train_world.py +1 -1
- ultralytics/models/yolo/yoloe/predict.py +4 -4
- ultralytics/models/yolo/yoloe/train.py +4 -4
- ultralytics/nn/autobackend.py +10 -13
- ultralytics/nn/modules/block.py +6 -6
- ultralytics/nn/modules/conv.py +2 -2
- ultralytics/nn/modules/head.py +4 -4
- ultralytics/nn/tasks.py +13 -13
- ultralytics/nn/text_model.py +3 -3
- ultralytics/solutions/ai_gym.py +2 -2
- ultralytics/solutions/analytics.py +3 -3
- ultralytics/solutions/config.py +5 -5
- ultralytics/solutions/distance_calculation.py +2 -2
- ultralytics/solutions/heatmap.py +1 -1
- ultralytics/solutions/instance_segmentation.py +4 -4
- ultralytics/solutions/object_counter.py +4 -4
- ultralytics/solutions/parking_management.py +7 -7
- ultralytics/solutions/queue_management.py +3 -3
- ultralytics/solutions/region_counter.py +4 -4
- ultralytics/solutions/similarity_search.py +2 -2
- ultralytics/solutions/solutions.py +48 -48
- ultralytics/solutions/streamlit_inference.py +1 -1
- ultralytics/solutions/trackzone.py +4 -4
- ultralytics/solutions/vision_eye.py +1 -1
- ultralytics/trackers/byte_tracker.py +11 -11
- ultralytics/trackers/utils/gmc.py +3 -3
- ultralytics/trackers/utils/matching.py +5 -5
- ultralytics/utils/__init__.py +1 -2
- ultralytics/utils/autodevice.py +2 -2
- ultralytics/utils/benchmarks.py +10 -10
- ultralytics/utils/callbacks/clearml.py +1 -1
- ultralytics/utils/callbacks/comet.py +5 -5
- ultralytics/utils/callbacks/hub.py +2 -1
- ultralytics/utils/checks.py +5 -5
- ultralytics/utils/cpu.py +90 -0
- ultralytics/utils/dist.py +1 -1
- ultralytics/utils/downloads.py +2 -2
- ultralytics/utils/events.py +115 -0
- ultralytics/utils/export.py +5 -5
- ultralytics/utils/instance.py +2 -2
- ultralytics/utils/metrics.py +35 -35
- ultralytics/utils/nms.py +4 -4
- ultralytics/utils/ops.py +4 -2
- ultralytics/utils/patches.py +2 -2
- ultralytics/utils/plotting.py +9 -9
- ultralytics/utils/torch_utils.py +2 -6
- ultralytics/utils/triton.py +5 -5
- {dgenerate_ultralytics_headless-8.3.193.dist-info → dgenerate_ultralytics_headless-8.3.195.dist-info}/WHEEL +0 -0
- {dgenerate_ultralytics_headless-8.3.193.dist-info → dgenerate_ultralytics_headless-8.3.195.dist-info}/entry_points.txt +0 -0
- {dgenerate_ultralytics_headless-8.3.193.dist-info → dgenerate_ultralytics_headless-8.3.195.dist-info}/licenses/LICENSE +0 -0
- {dgenerate_ultralytics_headless-8.3.193.dist-info → dgenerate_ultralytics_headless-8.3.195.dist-info}/top_level.txt +0 -0
ultralytics/utils/cpu.py
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
|
2
|
+
|
3
|
+
from __future__ import annotations
|
4
|
+
|
5
|
+
import platform
|
6
|
+
import re
|
7
|
+
import subprocess
|
8
|
+
import sys
|
9
|
+
from pathlib import Path
|
10
|
+
|
11
|
+
|
12
|
+
class CPUInfo:
|
13
|
+
"""
|
14
|
+
Provide cross-platform CPU brand and model information.
|
15
|
+
|
16
|
+
Query platform-specific sources to retrieve a human-readable CPU descriptor and normalize it for consistent
|
17
|
+
presentation across macOS, Linux, and Windows. If platform-specific probing fails, generic platform identifiers are
|
18
|
+
used to ensure a stable string is always returned.
|
19
|
+
|
20
|
+
Methods:
|
21
|
+
name: Return the normalized CPU name using platform-specific sources with robust fallbacks.
|
22
|
+
_clean: Normalize and prettify common vendor brand strings and frequency patterns.
|
23
|
+
__str__: Return the normalized CPU name for string contexts.
|
24
|
+
|
25
|
+
Examples:
|
26
|
+
>>> CPUInfo.name()
|
27
|
+
'Apple M4 Pro'
|
28
|
+
>>> str(CPUInfo())
|
29
|
+
'Intel Core i7-9750H 2.60GHz'
|
30
|
+
"""
|
31
|
+
|
32
|
+
@staticmethod
|
33
|
+
def name() -> str:
|
34
|
+
"""Return a normalized CPU model string from platform-specific sources."""
|
35
|
+
try:
|
36
|
+
if sys.platform == "darwin":
|
37
|
+
# Query macOS sysctl for the CPU brand string
|
38
|
+
s = subprocess.run(
|
39
|
+
["sysctl", "-n", "machdep.cpu.brand_string"], capture_output=True, text=True
|
40
|
+
).stdout.strip()
|
41
|
+
if s:
|
42
|
+
return CPUInfo._clean(s)
|
43
|
+
elif sys.platform.startswith("linux"):
|
44
|
+
# Parse /proc/cpuinfo for the first "model name" entry
|
45
|
+
p = Path("/proc/cpuinfo")
|
46
|
+
if p.exists():
|
47
|
+
for line in p.read_text(errors="ignore").splitlines():
|
48
|
+
if "model name" in line:
|
49
|
+
return CPUInfo._clean(line.split(":", 1)[1])
|
50
|
+
elif sys.platform.startswith("win"):
|
51
|
+
try:
|
52
|
+
import winreg as wr
|
53
|
+
|
54
|
+
with wr.OpenKey(wr.HKEY_LOCAL_MACHINE, r"HARDWARE\DESCRIPTION\System\CentralProcessor\0") as k:
|
55
|
+
val, _ = wr.QueryValueEx(k, "ProcessorNameString")
|
56
|
+
if val:
|
57
|
+
return CPUInfo._clean(val)
|
58
|
+
except Exception:
|
59
|
+
# Fall through to generic platform fallbacks on Windows registry access failure
|
60
|
+
pass
|
61
|
+
# Generic platform fallbacks
|
62
|
+
s = platform.processor() or getattr(platform.uname(), "processor", "") or platform.machine()
|
63
|
+
return CPUInfo._clean(s or "Unknown CPU")
|
64
|
+
except Exception:
|
65
|
+
# Ensure a string is always returned even on unexpected failures
|
66
|
+
s = platform.processor() or platform.machine() or ""
|
67
|
+
return CPUInfo._clean(s or "Unknown CPU")
|
68
|
+
|
69
|
+
@staticmethod
|
70
|
+
def _clean(s: str) -> str:
|
71
|
+
"""Normalize and prettify a raw CPU descriptor string."""
|
72
|
+
s = re.sub(r"\s+", " ", s.strip())
|
73
|
+
s = s.replace("(TM)", "").replace("(tm)", "").replace("(R)", "").replace("(r)", "").strip()
|
74
|
+
# Normalize common Intel pattern to 'Model Freq'
|
75
|
+
m = re.search(r"(Intel.*?i\d[\w-]*) CPU @ ([\d.]+GHz)", s, re.I)
|
76
|
+
if m:
|
77
|
+
return f"{m.group(1)} {m.group(2)}"
|
78
|
+
# Normalize common AMD Ryzen pattern to 'Model Freq'
|
79
|
+
m = re.search(r"(AMD.*?Ryzen.*?[\w-]*) CPU @ ([\d.]+GHz)", s, re.I)
|
80
|
+
if m:
|
81
|
+
return f"{m.group(1)} {m.group(2)}"
|
82
|
+
return s
|
83
|
+
|
84
|
+
def __str__(self) -> str:
|
85
|
+
"""Return the normalized CPU name."""
|
86
|
+
return self.name()
|
87
|
+
|
88
|
+
|
89
|
+
if __name__ == "__main__":
|
90
|
+
print(CPUInfo.name())
|
ultralytics/utils/dist.py
CHANGED
@@ -85,7 +85,7 @@ def generate_ddp_command(world_size: int, trainer):
|
|
85
85
|
trainer (ultralytics.engine.trainer.BaseTrainer): The trainer containing configuration for distributed training.
|
86
86
|
|
87
87
|
Returns:
|
88
|
-
cmd (
|
88
|
+
cmd (list[str]): The command to execute for distributed training.
|
89
89
|
file (str): Path to the temporary file created for DDP training.
|
90
90
|
"""
|
91
91
|
import __main__ # noqa local import to avoid https://github.com/Lightning-AI/pytorch-lightning/issues/15218
|
ultralytics/utils/downloads.py
CHANGED
@@ -411,7 +411,7 @@ def get_github_assets(
|
|
411
411
|
|
412
412
|
Returns:
|
413
413
|
tag (str): The release tag.
|
414
|
-
assets (
|
414
|
+
assets (list[str]): A list of asset names.
|
415
415
|
|
416
416
|
Examples:
|
417
417
|
>>> tag, assets = get_github_assets(repo="ultralytics/assets", version="latest")
|
@@ -503,7 +503,7 @@ def download(
|
|
503
503
|
Supports concurrent downloads if multiple threads are specified.
|
504
504
|
|
505
505
|
Args:
|
506
|
-
url (str |
|
506
|
+
url (str | list[str]): The URL or list of URLs of the files to be downloaded.
|
507
507
|
dir (Path, optional): The directory where the files will be saved.
|
508
508
|
unzip (bool, optional): Flag to unzip the files after downloading.
|
509
509
|
delete (bool, optional): Flag to delete the zip files after extraction.
|
@@ -0,0 +1,115 @@
|
|
1
|
+
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
|
2
|
+
|
3
|
+
import json
|
4
|
+
import random
|
5
|
+
import time
|
6
|
+
from pathlib import Path
|
7
|
+
from threading import Thread
|
8
|
+
from urllib.request import Request, urlopen
|
9
|
+
|
10
|
+
from ultralytics import SETTINGS, __version__
|
11
|
+
from ultralytics.utils import ARGV, ENVIRONMENT, GIT, IS_PIP_PACKAGE, ONLINE, PYTHON_VERSION, RANK, TESTS_RUNNING
|
12
|
+
from ultralytics.utils.downloads import GITHUB_ASSETS_NAMES
|
13
|
+
from ultralytics.utils.torch_utils import get_cpu_info
|
14
|
+
|
15
|
+
|
16
|
+
def _post(url: str, data: dict, timeout: float = 5.0) -> None:
|
17
|
+
"""Send a one-shot JSON POST request."""
|
18
|
+
try:
|
19
|
+
body = json.dumps(data, separators=(",", ":")).encode() # compact JSON
|
20
|
+
req = Request(url, data=body, headers={"Content-Type": "application/json"})
|
21
|
+
urlopen(req, timeout=timeout).close()
|
22
|
+
except Exception:
|
23
|
+
pass
|
24
|
+
|
25
|
+
|
26
|
+
class Events:
|
27
|
+
"""
|
28
|
+
Collect and send anonymous usage analytics with rate-limiting.
|
29
|
+
|
30
|
+
Event collection and transmission are enabled when sync is enabled in settings, the current process is rank -1 or 0,
|
31
|
+
tests are not running, the environment is online, and the installation source is either pip or the official
|
32
|
+
Ultralytics GitHub repository.
|
33
|
+
|
34
|
+
Attributes:
|
35
|
+
url (str): Measurement Protocol endpoint for receiving anonymous events.
|
36
|
+
events (list[dict]): In-memory queue of event payloads awaiting transmission.
|
37
|
+
rate_limit (float): Minimum time in seconds between POST requests.
|
38
|
+
t (float): Timestamp of the last transmission in seconds since the epoch.
|
39
|
+
metadata (dict): Static metadata describing runtime, installation source, and environment.
|
40
|
+
enabled (bool): Flag indicating whether analytics collection is active.
|
41
|
+
|
42
|
+
Methods:
|
43
|
+
__init__: Initialize the event queue, rate limiter, and runtime metadata.
|
44
|
+
__call__: Queue an event and trigger a non-blocking send when the rate limit elapses.
|
45
|
+
"""
|
46
|
+
|
47
|
+
url = "https://www.google-analytics.com/mp/collect?measurement_id=G-X8NCJYTQXM&api_secret=QLQrATrNSwGRFRLE-cbHJw"
|
48
|
+
|
49
|
+
def __init__(self) -> None:
|
50
|
+
"""Initialize the Events instance with queue, rate limiter, and environment metadata."""
|
51
|
+
self.events = [] # pending events
|
52
|
+
self.rate_limit = 30.0 # rate limit (seconds)
|
53
|
+
self.t = 0.0 # last send timestamp (seconds)
|
54
|
+
self.metadata = {
|
55
|
+
"cli": Path(ARGV[0]).name == "yolo",
|
56
|
+
"install": "git" if GIT.is_repo else "pip" if IS_PIP_PACKAGE else "other",
|
57
|
+
"python": PYTHON_VERSION.rsplit(".", 1)[0], # i.e. 3.13
|
58
|
+
"CPU": get_cpu_info(),
|
59
|
+
# "GPU": get_gpu_info(index=0) if cuda else None,
|
60
|
+
"version": __version__,
|
61
|
+
"env": ENVIRONMENT,
|
62
|
+
"session_id": round(random.random() * 1e15),
|
63
|
+
"engagement_time_msec": 1000,
|
64
|
+
}
|
65
|
+
self.enabled = (
|
66
|
+
SETTINGS["sync"]
|
67
|
+
and RANK in {-1, 0}
|
68
|
+
and not TESTS_RUNNING
|
69
|
+
and ONLINE
|
70
|
+
and (IS_PIP_PACKAGE or GIT.origin == "https://github.com/ultralytics/ultralytics.git")
|
71
|
+
)
|
72
|
+
|
73
|
+
def __call__(self, cfg, device=None) -> None:
|
74
|
+
"""
|
75
|
+
Queue an event and flush the queue asynchronously when the rate limit elapses.
|
76
|
+
|
77
|
+
Args:
|
78
|
+
cfg (IterableSimpleNamespace): The configuration object containing mode and task information.
|
79
|
+
device (torch.device | str, optional): The device type (e.g., 'cpu', 'cuda').
|
80
|
+
"""
|
81
|
+
if not self.enabled:
|
82
|
+
# Events disabled, do nothing
|
83
|
+
return
|
84
|
+
|
85
|
+
# Attempt to enqueue a new event
|
86
|
+
if len(self.events) < 25: # Queue limited to 25 events to bound memory and traffic
|
87
|
+
params = {
|
88
|
+
**self.metadata,
|
89
|
+
"task": cfg.task,
|
90
|
+
"model": cfg.model if cfg.model in GITHUB_ASSETS_NAMES else "custom",
|
91
|
+
"device": str(device),
|
92
|
+
}
|
93
|
+
if cfg.mode == "export":
|
94
|
+
params["format"] = cfg.format
|
95
|
+
self.events.append({"name": cfg.mode, "params": params})
|
96
|
+
|
97
|
+
# Check rate limit and return early if under limit
|
98
|
+
t = time.time()
|
99
|
+
if (t - self.t) < self.rate_limit:
|
100
|
+
return
|
101
|
+
|
102
|
+
# Overrate limit: send a snapshot of queued events in a background thread
|
103
|
+
payload_events = list(self.events) # snapshot to avoid race with queue reset
|
104
|
+
Thread(
|
105
|
+
target=_post,
|
106
|
+
args=(self.url, {"client_id": SETTINGS["uuid"], "events": payload_events}), # SHA-256 anonymized
|
107
|
+
daemon=True,
|
108
|
+
).start()
|
109
|
+
|
110
|
+
# Reset queue and rate limit timer
|
111
|
+
self.events = []
|
112
|
+
self.t = t
|
113
|
+
|
114
|
+
|
115
|
+
events = Events()
|
ultralytics/utils/export.py
CHANGED
@@ -27,9 +27,9 @@ def export_onnx(
|
|
27
27
|
im (torch.Tensor): Example input tensor for the model.
|
28
28
|
onnx_file (str): Path to save the exported ONNX file.
|
29
29
|
opset (int): ONNX opset version to use for export.
|
30
|
-
input_names (
|
31
|
-
output_names (
|
32
|
-
dynamic (bool |
|
30
|
+
input_names (list[str]): List of input tensor names.
|
31
|
+
output_names (list[str]): List of output tensor names.
|
32
|
+
dynamic (bool | dict, optional): Whether to enable dynamic axes.
|
33
33
|
|
34
34
|
Notes:
|
35
35
|
Setting `do_constant_folding=True` may cause issues with DNN inference for torch>=1.12.
|
@@ -71,10 +71,10 @@ def export_engine(
|
|
71
71
|
half (bool, optional): Enable FP16 precision.
|
72
72
|
int8 (bool, optional): Enable INT8 precision.
|
73
73
|
dynamic (bool, optional): Enable dynamic input shapes.
|
74
|
-
shape (
|
74
|
+
shape (tuple[int, int, int, int], optional): Input shape (batch, channels, height, width).
|
75
75
|
dla (int, optional): DLA core to use (Jetson devices only).
|
76
76
|
dataset (ultralytics.data.build.InfiniteDataLoader, optional): Dataset for INT8 calibration.
|
77
|
-
metadata (
|
77
|
+
metadata (dict, optional): Metadata to include in the engine file.
|
78
78
|
verbose (bool, optional): Enable verbose logging.
|
79
79
|
prefix (str, optional): Prefix for log messages.
|
80
80
|
|
ultralytics/utils/instance.py
CHANGED
@@ -146,7 +146,7 @@ class Bboxes:
|
|
146
146
|
Concatenate a list of Bboxes objects into a single Bboxes object.
|
147
147
|
|
148
148
|
Args:
|
149
|
-
boxes_list (
|
149
|
+
boxes_list (list[Bboxes]): A list of Bboxes objects to concatenate.
|
150
150
|
axis (int, optional): The axis along which to concatenate the bounding boxes.
|
151
151
|
|
152
152
|
Returns:
|
@@ -458,7 +458,7 @@ class Instances:
|
|
458
458
|
Concatenate a list of Instances objects into a single Instances object.
|
459
459
|
|
460
460
|
Args:
|
461
|
-
instances_list (
|
461
|
+
instances_list (list[Instances]): A list of Instances objects to concatenate.
|
462
462
|
axis (int, optional): The axis along which the arrays will be concatenated.
|
463
463
|
|
464
464
|
Returns:
|
ultralytics/utils/metrics.py
CHANGED
@@ -318,7 +318,7 @@ class ConfusionMatrix(DataExportMixin):
|
|
318
318
|
task (str): The type of task, either 'detect' or 'classify'.
|
319
319
|
matrix (np.ndarray): The confusion matrix, with dimensions depending on the task.
|
320
320
|
nc (int): The number of category.
|
321
|
-
names (
|
321
|
+
names (list[str]): The names of the classes, used as labels on the plot.
|
322
322
|
matches (dict): Contains the indices of ground truths and predictions categorized into TP, FP and FN.
|
323
323
|
"""
|
324
324
|
|
@@ -327,7 +327,7 @@ class ConfusionMatrix(DataExportMixin):
|
|
327
327
|
Initialize a ConfusionMatrix instance.
|
328
328
|
|
329
329
|
Args:
|
330
|
-
names (
|
330
|
+
names (dict[int, str], optional): Names of classes, used as labels on the plot.
|
331
331
|
task (str, optional): Type of task, either 'detect' or 'classify'.
|
332
332
|
save_matches (bool, optional): Save the indices of GTs, TPs, FPs, FNs for visualization.
|
333
333
|
"""
|
@@ -346,7 +346,7 @@ class ConfusionMatrix(DataExportMixin):
|
|
346
346
|
|
347
347
|
Args:
|
348
348
|
mtype (str): Match type identifier ('TP', 'FP', 'FN' or 'GT').
|
349
|
-
batch (
|
349
|
+
batch (dict[str, Any]): Batch data containing detection results with keys
|
350
350
|
like 'bboxes', 'cls', 'conf', 'keypoints', 'masks'.
|
351
351
|
idx (int): Index of the specific detection to append from the batch.
|
352
352
|
|
@@ -368,8 +368,8 @@ class ConfusionMatrix(DataExportMixin):
|
|
368
368
|
Update confusion matrix for classification task.
|
369
369
|
|
370
370
|
Args:
|
371
|
-
preds (
|
372
|
-
targets (
|
371
|
+
preds (list[N, min(nc,5)]): Predicted class labels.
|
372
|
+
targets (list[N, 1]): Ground truth class labels.
|
373
373
|
"""
|
374
374
|
preds, targets = torch.cat(preds)[:, 0], torch.cat(targets)
|
375
375
|
for p, t in zip(preds.cpu().numpy(), targets.cpu().numpy()):
|
@@ -386,10 +386,10 @@ class ConfusionMatrix(DataExportMixin):
|
|
386
386
|
Update confusion matrix for object detection task.
|
387
387
|
|
388
388
|
Args:
|
389
|
-
detections (
|
389
|
+
detections (dict[str, torch.Tensor]): Dictionary containing detected bounding boxes and their associated information.
|
390
390
|
Should contain 'cls', 'conf', and 'bboxes' keys, where 'bboxes' can be
|
391
391
|
Array[N, 4] for regular boxes or Array[N, 5] for OBB with angle.
|
392
|
-
batch (
|
392
|
+
batch (dict[str, Any]): Batch dictionary containing ground truth data with 'bboxes' (Array[M, 4]| Array[M, 5]) and
|
393
393
|
'cls' (Array[M]) keys, where M is the number of ground truth objects.
|
394
394
|
conf (float, optional): Confidence threshold for detections.
|
395
395
|
iou_thres (float, optional): IoU threshold for matching detections to ground truth.
|
@@ -599,7 +599,7 @@ class ConfusionMatrix(DataExportMixin):
|
|
599
599
|
decimals (int): Number of decimal places to round the output values to.
|
600
600
|
|
601
601
|
Returns:
|
602
|
-
(
|
602
|
+
(list[dict[str, float]]): A list of dictionaries, each representing one predicted class with corresponding values for all actual classes.
|
603
603
|
|
604
604
|
Examples:
|
605
605
|
>>> results = model.val(data="coco8.yaml", plots=True)
|
@@ -651,7 +651,7 @@ def plot_pr_curve(
|
|
651
651
|
py (np.ndarray): Y values for the PR curve.
|
652
652
|
ap (np.ndarray): Average precision values.
|
653
653
|
save_dir (Path, optional): Path to save the plot.
|
654
|
-
names (
|
654
|
+
names (dict[int, str], optional): Dictionary mapping class indices to class names.
|
655
655
|
on_plot (callable, optional): Function to call after plot is saved.
|
656
656
|
"""
|
657
657
|
import matplotlib.pyplot as plt # scope for faster 'import ultralytics'
|
@@ -695,7 +695,7 @@ def plot_mc_curve(
|
|
695
695
|
px (np.ndarray): X values for the metric-confidence curve.
|
696
696
|
py (np.ndarray): Y values for the metric-confidence curve.
|
697
697
|
save_dir (Path, optional): Path to save the plot.
|
698
|
-
names (
|
698
|
+
names (dict[int, str], optional): Dictionary mapping class indices to class names.
|
699
699
|
xlabel (str, optional): X-axis label.
|
700
700
|
ylabel (str, optional): Y-axis label.
|
701
701
|
on_plot (callable, optional): Function to call after plot is saved.
|
@@ -780,7 +780,7 @@ def ap_per_class(
|
|
780
780
|
plot (bool, optional): Whether to plot PR curves or not.
|
781
781
|
on_plot (callable, optional): A callback to pass plots path and data when they are rendered.
|
782
782
|
save_dir (Path, optional): Directory to save the PR curves.
|
783
|
-
names (
|
783
|
+
names (dict[int, str], optional): Dictionary of class names to plot PR curves.
|
784
784
|
eps (float, optional): A small value to avoid division by zero.
|
785
785
|
prefix (str, optional): A prefix string for saving the plot files.
|
786
786
|
|
@@ -1034,11 +1034,11 @@ class DetMetrics(SimpleClass, DataExportMixin):
|
|
1034
1034
|
Utility class for computing detection metrics such as precision, recall, and mean average precision (mAP).
|
1035
1035
|
|
1036
1036
|
Attributes:
|
1037
|
-
names (
|
1037
|
+
names (dict[int, str]): A dictionary of class names.
|
1038
1038
|
box (Metric): An instance of the Metric class for storing detection results.
|
1039
|
-
speed (
|
1039
|
+
speed (dict[str, float]): A dictionary for storing execution times of different parts of the detection process.
|
1040
1040
|
task (str): The task type, set to 'detect'.
|
1041
|
-
stats (
|
1041
|
+
stats (dict[str, list]): A dictionary containing lists for true positives, confidence scores, predicted classes, target classes, and target images.
|
1042
1042
|
nt_per_class: Number of targets per class.
|
1043
1043
|
nt_per_image: Number of targets per image.
|
1044
1044
|
|
@@ -1063,7 +1063,7 @@ class DetMetrics(SimpleClass, DataExportMixin):
|
|
1063
1063
|
Initialize a DetMetrics instance with a save directory, plot flag, and class names.
|
1064
1064
|
|
1065
1065
|
Args:
|
1066
|
-
names (
|
1066
|
+
names (dict[int, str], optional): Dictionary of class names.
|
1067
1067
|
"""
|
1068
1068
|
self.names = names
|
1069
1069
|
self.box = Metric()
|
@@ -1078,7 +1078,7 @@ class DetMetrics(SimpleClass, DataExportMixin):
|
|
1078
1078
|
Update statistics by appending new values to existing stat collections.
|
1079
1079
|
|
1080
1080
|
Args:
|
1081
|
-
stat (
|
1081
|
+
stat (dict[str, any]): Dictionary containing new statistical values to append.
|
1082
1082
|
Keys should match existing keys in self.stats.
|
1083
1083
|
"""
|
1084
1084
|
for k in self.stats.keys():
|
@@ -1094,7 +1094,7 @@ class DetMetrics(SimpleClass, DataExportMixin):
|
|
1094
1094
|
on_plot (callable, optional): Function to call after plots are generated. Defaults to None.
|
1095
1095
|
|
1096
1096
|
Returns:
|
1097
|
-
(
|
1097
|
+
(dict[str, np.ndarray]): Dictionary containing concatenated statistics arrays.
|
1098
1098
|
"""
|
1099
1099
|
stats = {k: np.concatenate(v, 0) for k, v in self.stats.items()} # to numpy
|
1100
1100
|
if not stats:
|
@@ -1176,7 +1176,7 @@ class DetMetrics(SimpleClass, DataExportMixin):
|
|
1176
1176
|
decimals (int): Number of decimal places to round the metrics values to.
|
1177
1177
|
|
1178
1178
|
Returns:
|
1179
|
-
(
|
1179
|
+
(list[dict[str, Any]]): A list of dictionaries, each representing one class with corresponding metric values.
|
1180
1180
|
|
1181
1181
|
Examples:
|
1182
1182
|
>>> results = model.val(data="coco8.yaml")
|
@@ -1206,12 +1206,12 @@ class SegmentMetrics(DetMetrics):
|
|
1206
1206
|
Calculate and aggregate detection and segmentation metrics over a given set of classes.
|
1207
1207
|
|
1208
1208
|
Attributes:
|
1209
|
-
names (
|
1209
|
+
names (dict[int, str]): Dictionary of class names.
|
1210
1210
|
box (Metric): An instance of the Metric class for storing detection results.
|
1211
1211
|
seg (Metric): An instance of the Metric class to calculate mask segmentation metrics.
|
1212
|
-
speed (
|
1212
|
+
speed (dict[str, float]): A dictionary for storing execution times of different parts of the detection process.
|
1213
1213
|
task (str): The task type, set to 'segment'.
|
1214
|
-
stats (
|
1214
|
+
stats (dict[str, list]): A dictionary containing lists for true positives, confidence scores, predicted classes, target classes, and target images.
|
1215
1215
|
nt_per_class: Number of targets per class.
|
1216
1216
|
nt_per_image: Number of targets per image.
|
1217
1217
|
|
@@ -1232,7 +1232,7 @@ class SegmentMetrics(DetMetrics):
|
|
1232
1232
|
Initialize a SegmentMetrics instance with a save directory, plot flag, and class names.
|
1233
1233
|
|
1234
1234
|
Args:
|
1235
|
-
names (
|
1235
|
+
names (dict[int, str], optional): Dictionary of class names.
|
1236
1236
|
"""
|
1237
1237
|
DetMetrics.__init__(self, names)
|
1238
1238
|
self.seg = Metric()
|
@@ -1249,7 +1249,7 @@ class SegmentMetrics(DetMetrics):
|
|
1249
1249
|
on_plot (callable, optional): Function to call after plots are generated. Defaults to None.
|
1250
1250
|
|
1251
1251
|
Returns:
|
1252
|
-
(
|
1252
|
+
(dict[str, np.ndarray]): Dictionary containing concatenated statistics arrays.
|
1253
1253
|
"""
|
1254
1254
|
stats = DetMetrics.process(self, save_dir, plot, on_plot=on_plot) # process box stats
|
1255
1255
|
results_mask = ap_per_class(
|
@@ -1320,7 +1320,7 @@ class SegmentMetrics(DetMetrics):
|
|
1320
1320
|
decimals (int): Number of decimal places to round the metrics values to.
|
1321
1321
|
|
1322
1322
|
Returns:
|
1323
|
-
(
|
1323
|
+
(list[dict[str, Any]]): A list of dictionaries, each representing one class with corresponding metric values.
|
1324
1324
|
|
1325
1325
|
Examples:
|
1326
1326
|
>>> results = model.val(data="coco8-seg.yaml")
|
@@ -1343,12 +1343,12 @@ class PoseMetrics(DetMetrics):
|
|
1343
1343
|
Calculate and aggregate detection and pose metrics over a given set of classes.
|
1344
1344
|
|
1345
1345
|
Attributes:
|
1346
|
-
names (
|
1346
|
+
names (dict[int, str]): Dictionary of class names.
|
1347
1347
|
pose (Metric): An instance of the Metric class to calculate pose metrics.
|
1348
1348
|
box (Metric): An instance of the Metric class for storing detection results.
|
1349
|
-
speed (
|
1349
|
+
speed (dict[str, float]): A dictionary for storing execution times of different parts of the detection process.
|
1350
1350
|
task (str): The task type, set to 'pose'.
|
1351
|
-
stats (
|
1351
|
+
stats (dict[str, list]): A dictionary containing lists for true positives, confidence scores, predicted classes, target classes, and target images.
|
1352
1352
|
nt_per_class: Number of targets per class.
|
1353
1353
|
nt_per_image: Number of targets per image.
|
1354
1354
|
|
@@ -1369,7 +1369,7 @@ class PoseMetrics(DetMetrics):
|
|
1369
1369
|
Initialize the PoseMetrics class with directory path, class names, and plotting options.
|
1370
1370
|
|
1371
1371
|
Args:
|
1372
|
-
names (
|
1372
|
+
names (dict[int, str], optional): Dictionary of class names.
|
1373
1373
|
"""
|
1374
1374
|
super().__init__(names)
|
1375
1375
|
self.pose = Metric()
|
@@ -1386,7 +1386,7 @@ class PoseMetrics(DetMetrics):
|
|
1386
1386
|
on_plot (callable, optional): Function to call after plots are generated.
|
1387
1387
|
|
1388
1388
|
Returns:
|
1389
|
-
(
|
1389
|
+
(dict[str, np.ndarray]): Dictionary containing concatenated statistics arrays.
|
1390
1390
|
"""
|
1391
1391
|
stats = DetMetrics.process(self, save_dir, plot, on_plot=on_plot) # process box stats
|
1392
1392
|
results_pose = ap_per_class(
|
@@ -1461,7 +1461,7 @@ class PoseMetrics(DetMetrics):
|
|
1461
1461
|
decimals (int): Number of decimal places to round the metrics values to.
|
1462
1462
|
|
1463
1463
|
Returns:
|
1464
|
-
(
|
1464
|
+
(list[dict[str, Any]]): A list of dictionaries, each representing one class with corresponding metric values.
|
1465
1465
|
|
1466
1466
|
Examples:
|
1467
1467
|
>>> results = model.val(data="coco8-pose.yaml")
|
@@ -1553,7 +1553,7 @@ class ClassifyMetrics(SimpleClass, DataExportMixin):
|
|
1553
1553
|
decimals (int): Number of decimal places to round the metrics values to.
|
1554
1554
|
|
1555
1555
|
Returns:
|
1556
|
-
(
|
1556
|
+
(list[dict[str, float]]): A list with one dictionary containing Top-1 and Top-5 classification accuracy.
|
1557
1557
|
|
1558
1558
|
Examples:
|
1559
1559
|
>>> results = model.val(data="imagenet10")
|
@@ -1568,11 +1568,11 @@ class OBBMetrics(DetMetrics):
|
|
1568
1568
|
Metrics for evaluating oriented bounding box (OBB) detection.
|
1569
1569
|
|
1570
1570
|
Attributes:
|
1571
|
-
names (
|
1571
|
+
names (dict[int, str]): Dictionary of class names.
|
1572
1572
|
box (Metric): An instance of the Metric class for storing detection results.
|
1573
|
-
speed (
|
1573
|
+
speed (dict[str, float]): A dictionary for storing execution times of different parts of the detection process.
|
1574
1574
|
task (str): The task type, set to 'obb'.
|
1575
|
-
stats (
|
1575
|
+
stats (dict[str, list]): A dictionary containing lists for true positives, confidence scores, predicted classes, target classes, and target images.
|
1576
1576
|
nt_per_class: Number of targets per class.
|
1577
1577
|
nt_per_image: Number of targets per image.
|
1578
1578
|
|
@@ -1585,7 +1585,7 @@ class OBBMetrics(DetMetrics):
|
|
1585
1585
|
Initialize an OBBMetrics instance with directory, plotting, and class names.
|
1586
1586
|
|
1587
1587
|
Args:
|
1588
|
-
names (
|
1588
|
+
names (dict[int, str], optional): Dictionary of class names.
|
1589
1589
|
"""
|
1590
1590
|
DetMetrics.__init__(self, names)
|
1591
1591
|
# TODO: probably remove task as well
|
ultralytics/utils/nms.py
CHANGED
@@ -38,10 +38,10 @@ def non_max_suppression(
|
|
38
38
|
containing boxes, classes, and optional masks.
|
39
39
|
conf_thres (float): Confidence threshold for filtering detections. Valid values are between 0.0 and 1.0.
|
40
40
|
iou_thres (float): IoU threshold for NMS filtering. Valid values are between 0.0 and 1.0.
|
41
|
-
classes (
|
41
|
+
classes (list[int], optional): List of class indices to consider. If None, all classes are considered.
|
42
42
|
agnostic (bool): Whether to perform class-agnostic NMS.
|
43
43
|
multi_label (bool): Whether each box can have multiple labels.
|
44
|
-
labels (
|
44
|
+
labels (list[list[Union[int, float, torch.Tensor]]]): A priori labels for each image.
|
45
45
|
max_det (int): Maximum number of detections to keep per image.
|
46
46
|
nc (int): Number of classes. Indices after this are considered masks.
|
47
47
|
max_time_img (float): Maximum time in seconds for processing one image.
|
@@ -52,9 +52,9 @@ def non_max_suppression(
|
|
52
52
|
return_idxs (bool): Whether to return the indices of kept detections.
|
53
53
|
|
54
54
|
Returns:
|
55
|
-
output (
|
55
|
+
output (list[torch.Tensor]): List of detections per image with shape (num_boxes, 6 + num_masks)
|
56
56
|
containing (x1, y1, x2, y2, confidence, class, mask1, mask2, ...).
|
57
|
-
keepi (
|
57
|
+
keepi (list[torch.Tensor]): Indices of kept detections if return_idxs=True.
|
58
58
|
"""
|
59
59
|
# Checks
|
60
60
|
assert 0 <= conf_thres <= 1, f"Invalid Confidence threshold {conf_thres}, valid values are between 0.0 and 1.0"
|
ultralytics/utils/ops.py
CHANGED
@@ -135,7 +135,7 @@ def scale_boxes(img1_shape, boxes, img0_shape, ratio_pad=None, padding: bool = T
|
|
135
135
|
boxes[..., 2] -= pad_x # x padding
|
136
136
|
boxes[..., 3] -= pad_y # y padding
|
137
137
|
boxes[..., :4] /= gain
|
138
|
-
return clip_boxes(boxes, img0_shape)
|
138
|
+
return boxes if xywh else clip_boxes(boxes, img0_shape)
|
139
139
|
|
140
140
|
|
141
141
|
def make_divisible(x: int, divisor):
|
@@ -244,7 +244,9 @@ def scale_image(masks, im0_shape, ratio_pad=None):
|
|
244
244
|
if len(masks.shape) < 2:
|
245
245
|
raise ValueError(f'"len of masks shape" should be 2 or 3, but got {len(masks.shape)}')
|
246
246
|
masks = masks[top:bottom, left:right]
|
247
|
-
|
247
|
+
# handle the cv2.resize 512 channels limitation: https://github.com/ultralytics/ultralytics/pull/21947
|
248
|
+
masks = [cv2.resize(array, (im0_w, im0_h)) for array in np.array_split(masks, masks.shape[-1] // 512 + 1, axis=-1)]
|
249
|
+
masks = np.concatenate(masks, axis=-1) if len(masks) > 1 else masks[0]
|
248
250
|
if len(masks.shape) == 2:
|
249
251
|
masks = masks[:, :, None]
|
250
252
|
|
ultralytics/utils/patches.py
CHANGED
@@ -51,7 +51,7 @@ def imwrite(filename: str, img: np.ndarray, params: list[int] | None = None) ->
|
|
51
51
|
Args:
|
52
52
|
filename (str): Path to the file to write.
|
53
53
|
img (np.ndarray): Image to write.
|
54
|
-
params (
|
54
|
+
params (list[int], optional): Additional parameters for image encoding.
|
55
55
|
|
56
56
|
Returns:
|
57
57
|
(bool): True if the file was written successfully, False otherwise.
|
@@ -172,7 +172,7 @@ def override_configs(args, overrides: dict[str, Any] | None = None):
|
|
172
172
|
|
173
173
|
Args:
|
174
174
|
args (IterableSimpleNamespace): Original configuration arguments.
|
175
|
-
overrides (
|
175
|
+
overrides (dict[str, Any]): Dictionary of overrides to apply.
|
176
176
|
|
177
177
|
Yields:
|
178
178
|
(IterableSimpleNamespace): Configuration arguments with overrides applied.
|
ultralytics/utils/plotting.py
CHANGED
@@ -26,7 +26,7 @@ class Colors:
|
|
26
26
|
RGB values and accessing predefined color schemes for object detection and pose estimation.
|
27
27
|
|
28
28
|
Attributes:
|
29
|
-
palette (
|
29
|
+
palette (list[tuple]): List of RGB color tuples for general use.
|
30
30
|
n (int): The number of colors in the palette.
|
31
31
|
pose_palette (np.ndarray): A specific color palette array for pose estimation with dtype np.uint8.
|
32
32
|
|
@@ -176,9 +176,9 @@ class Annotator:
|
|
176
176
|
pil (bool): Whether to use PIL or cv2 for drawing annotations.
|
177
177
|
font (ImageFont.truetype | ImageFont.load_default): Font used for text annotations.
|
178
178
|
lw (float): Line width for drawing.
|
179
|
-
skeleton (
|
180
|
-
limb_color (
|
181
|
-
kpt_color (
|
179
|
+
skeleton (list[list[int]]): Skeleton structure for keypoints.
|
180
|
+
limb_color (list[int]): Color palette for limbs.
|
181
|
+
kpt_color (list[int]): Color palette for keypoints.
|
182
182
|
dark_colors (set): Set of colors considered dark for text contrast.
|
183
183
|
light_colors (set): Set of colors considered light for text contrast.
|
184
184
|
|
@@ -369,7 +369,7 @@ class Annotator:
|
|
369
369
|
|
370
370
|
Args:
|
371
371
|
masks (torch.Tensor | np.ndarray): Predicted masks with shape: [n, h, w]
|
372
|
-
colors (
|
372
|
+
colors (list[list[int]]): Colors for predicted masks, [[r, g, b] * n]
|
373
373
|
im_gpu (torch.Tensor | None): Image is in cuda, shape: [3, h, w], range: [0, 1]
|
374
374
|
alpha (float, optional): Mask transparency: 0.0 fully transparent, 1.0 opaque.
|
375
375
|
retina_masks (bool, optional): Whether to use high resolution masks or not.
|
@@ -484,7 +484,7 @@ class Annotator:
|
|
484
484
|
Add text to an image using PIL or cv2.
|
485
485
|
|
486
486
|
Args:
|
487
|
-
xy (
|
487
|
+
xy (list[int]): Top-left coordinates for text placement.
|
488
488
|
text (str): Text to be drawn.
|
489
489
|
txt_color (tuple, optional): Text color (R, G, B).
|
490
490
|
anchor (str, optional): Text anchor position ('top' or 'bottom').
|
@@ -695,11 +695,11 @@ def plot_images(
|
|
695
695
|
Plot image grid with labels, bounding boxes, masks, and keypoints.
|
696
696
|
|
697
697
|
Args:
|
698
|
-
labels (
|
698
|
+
labels (dict[str, Any]): Dictionary containing detection data with keys like 'cls', 'bboxes', 'conf', 'masks', 'keypoints', 'batch_idx', 'img'.
|
699
699
|
images (torch.Tensor | np.ndarray]): Batch of images to plot. Shape: (batch_size, channels, height, width).
|
700
|
-
paths (Optional[
|
700
|
+
paths (Optional[list[str]]): List of file paths for each image in the batch.
|
701
701
|
fname (str): Output filename for the plotted image grid.
|
702
|
-
names (Optional[
|
702
|
+
names (Optional[dict[int, str]]): Dictionary mapping class indices to class names.
|
703
703
|
on_plot (Optional[Callable]): Optional callback function to be called after saving the plot.
|
704
704
|
max_size (int): Maximum size of the output image grid.
|
705
705
|
max_subplots (int): Maximum number of subplots in the image grid.
|