dgenerate-ultralytics-headless 8.4.1__py3-none-any.whl → 8.4.4__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.4.1.dist-info → dgenerate_ultralytics_headless-8.4.4.dist-info}/METADATA +44 -44
- {dgenerate_ultralytics_headless-8.4.1.dist-info → dgenerate_ultralytics_headless-8.4.4.dist-info}/RECORD +54 -54
- tests/test_exports.py +0 -2
- ultralytics/__init__.py +1 -1
- ultralytics/cfg/__init__.py +20 -22
- ultralytics/data/annotator.py +2 -2
- ultralytics/data/converter.py +57 -38
- ultralytics/engine/exporter.py +23 -24
- ultralytics/engine/model.py +33 -33
- ultralytics/engine/predictor.py +17 -17
- ultralytics/engine/results.py +14 -12
- ultralytics/engine/trainer.py +27 -22
- ultralytics/engine/tuner.py +4 -4
- ultralytics/engine/validator.py +16 -16
- ultralytics/models/yolo/classify/predict.py +1 -1
- ultralytics/models/yolo/classify/train.py +1 -1
- ultralytics/models/yolo/classify/val.py +1 -1
- ultralytics/models/yolo/detect/predict.py +2 -2
- ultralytics/models/yolo/detect/train.py +1 -1
- ultralytics/models/yolo/detect/val.py +1 -1
- ultralytics/models/yolo/model.py +7 -7
- ultralytics/models/yolo/obb/predict.py +1 -1
- ultralytics/models/yolo/obb/train.py +2 -2
- ultralytics/models/yolo/obb/val.py +1 -1
- ultralytics/models/yolo/pose/predict.py +1 -1
- ultralytics/models/yolo/pose/train.py +4 -2
- ultralytics/models/yolo/pose/val.py +1 -1
- ultralytics/models/yolo/segment/predict.py +3 -3
- ultralytics/models/yolo/segment/train.py +3 -3
- ultralytics/models/yolo/segment/val.py +2 -4
- ultralytics/nn/autobackend.py +3 -3
- ultralytics/nn/modules/head.py +1 -1
- ultralytics/nn/tasks.py +12 -12
- ultralytics/solutions/ai_gym.py +3 -3
- ultralytics/solutions/config.py +1 -1
- ultralytics/solutions/heatmap.py +1 -1
- ultralytics/solutions/instance_segmentation.py +2 -2
- ultralytics/solutions/parking_management.py +1 -1
- ultralytics/solutions/solutions.py +2 -2
- ultralytics/trackers/track.py +1 -1
- ultralytics/utils/__init__.py +8 -8
- ultralytics/utils/benchmarks.py +25 -25
- ultralytics/utils/callbacks/platform.py +11 -9
- ultralytics/utils/callbacks/tensorboard.py +2 -0
- ultralytics/utils/checks.py +6 -6
- ultralytics/utils/downloads.py +2 -2
- ultralytics/utils/export/imx.py +24 -17
- ultralytics/utils/files.py +2 -2
- ultralytics/utils/loss.py +3 -3
- ultralytics/utils/tuner.py +2 -2
- {dgenerate_ultralytics_headless-8.4.1.dist-info → dgenerate_ultralytics_headless-8.4.4.dist-info}/WHEEL +0 -0
- {dgenerate_ultralytics_headless-8.4.1.dist-info → dgenerate_ultralytics_headless-8.4.4.dist-info}/entry_points.txt +0 -0
- {dgenerate_ultralytics_headless-8.4.1.dist-info → dgenerate_ultralytics_headless-8.4.4.dist-info}/licenses/LICENSE +0 -0
- {dgenerate_ultralytics_headless-8.4.1.dist-info → dgenerate_ultralytics_headless-8.4.4.dist-info}/top_level.txt +0 -0
ultralytics/data/annotator.py
CHANGED
|
@@ -9,7 +9,7 @@ from ultralytics import SAM, YOLO
|
|
|
9
9
|
|
|
10
10
|
def auto_annotate(
|
|
11
11
|
data: str | Path,
|
|
12
|
-
det_model: str = "
|
|
12
|
+
det_model: str = "yolo26x.pt",
|
|
13
13
|
sam_model: str = "sam_b.pt",
|
|
14
14
|
device: str = "",
|
|
15
15
|
conf: float = 0.25,
|
|
@@ -39,7 +39,7 @@ def auto_annotate(
|
|
|
39
39
|
|
|
40
40
|
Examples:
|
|
41
41
|
>>> from ultralytics.data.annotator import auto_annotate
|
|
42
|
-
>>> auto_annotate(data="ultralytics/assets", det_model="
|
|
42
|
+
>>> auto_annotate(data="ultralytics/assets", det_model="yolo26n.pt", sam_model="mobile_sam.pt")
|
|
43
43
|
"""
|
|
44
44
|
det_model = YOLO(det_model)
|
|
45
45
|
sam_model = SAM(sam_model)
|
ultralytics/data/converter.py
CHANGED
|
@@ -15,7 +15,7 @@ import numpy as np
|
|
|
15
15
|
from PIL import Image
|
|
16
16
|
|
|
17
17
|
from ultralytics.utils import ASSETS_URL, DATASETS_DIR, LOGGER, NUM_THREADS, TQDM, YAML
|
|
18
|
-
from ultralytics.utils.checks import check_file
|
|
18
|
+
from ultralytics.utils.checks import check_file
|
|
19
19
|
from ultralytics.utils.downloads import download, zip_directory
|
|
20
20
|
from ultralytics.utils.files import increment_path
|
|
21
21
|
|
|
@@ -747,14 +747,15 @@ def convert_to_multispectral(path: str | Path, n_channels: int = 10, replace: bo
|
|
|
747
747
|
|
|
748
748
|
|
|
749
749
|
async def convert_ndjson_to_yolo(ndjson_path: str | Path, output_path: str | Path | None = None) -> Path:
|
|
750
|
-
"""Convert NDJSON dataset format to Ultralytics
|
|
750
|
+
"""Convert NDJSON dataset format to Ultralytics YOLO dataset structure.
|
|
751
751
|
|
|
752
|
-
This function converts datasets stored in NDJSON (Newline Delimited JSON) format to the standard YOLO format
|
|
753
|
-
separate directories for images and labels.
|
|
754
|
-
|
|
752
|
+
This function converts datasets stored in NDJSON (Newline Delimited JSON) format to the standard YOLO format. For
|
|
753
|
+
detection/segmentation/pose/obb tasks, it creates separate directories for images and labels. For classification
|
|
754
|
+
tasks, it creates the ImageNet-style {split}/{class_name}/ folder structure. It supports parallel processing for
|
|
755
|
+
efficient conversion of large datasets and can download images from URLs.
|
|
755
756
|
|
|
756
757
|
The NDJSON format consists of:
|
|
757
|
-
- First line: Dataset metadata with class names and configuration
|
|
758
|
+
- First line: Dataset metadata with class names, task type, and configuration
|
|
758
759
|
- Subsequent lines: Individual image records with annotations and optional URLs
|
|
759
760
|
|
|
760
761
|
Args:
|
|
@@ -763,7 +764,7 @@ async def convert_ndjson_to_yolo(ndjson_path: str | Path, output_path: str | Pat
|
|
|
763
764
|
None, uses the parent directory of the NDJSON file. Defaults to None.
|
|
764
765
|
|
|
765
766
|
Returns:
|
|
766
|
-
(Path): Path to the generated data.yaml file
|
|
767
|
+
(Path): Path to the generated data.yaml file (detection) or dataset directory (classification).
|
|
767
768
|
|
|
768
769
|
Examples:
|
|
769
770
|
Convert a local NDJSON file:
|
|
@@ -775,9 +776,11 @@ async def convert_ndjson_to_yolo(ndjson_path: str | Path, output_path: str | Pat
|
|
|
775
776
|
|
|
776
777
|
Use with YOLO training
|
|
777
778
|
>>> from ultralytics import YOLO
|
|
778
|
-
>>> model = YOLO("
|
|
779
|
+
>>> model = YOLO("yolo26n.pt")
|
|
779
780
|
>>> model.train(data="https://github.com/ultralytics/assets/releases/download/v0.0.0/coco8-ndjson.ndjson")
|
|
780
781
|
"""
|
|
782
|
+
from ultralytics.utils.checks import check_requirements
|
|
783
|
+
|
|
781
784
|
check_requirements("aiohttp")
|
|
782
785
|
import aiohttp
|
|
783
786
|
|
|
@@ -790,50 +793,63 @@ async def convert_ndjson_to_yolo(ndjson_path: str | Path, output_path: str | Pat
|
|
|
790
793
|
dataset_dir = output_path / ndjson_path.stem
|
|
791
794
|
splits = {record["split"] for record in image_records}
|
|
792
795
|
|
|
793
|
-
#
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
data_yaml["names"] = {int(k): v for k, v in dataset_record.get("class_names", {}).items()}
|
|
797
|
-
data_yaml.pop("class_names")
|
|
796
|
+
# Check if this is a classification dataset
|
|
797
|
+
is_classification = dataset_record.get("task") == "classify"
|
|
798
|
+
class_names = {int(k): v for k, v in dataset_record.get("class_names", {}).items()}
|
|
798
799
|
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
800
|
+
# Create base directories
|
|
801
|
+
dataset_dir.mkdir(parents=True, exist_ok=True)
|
|
802
|
+
data_yaml = None
|
|
803
|
+
|
|
804
|
+
if not is_classification:
|
|
805
|
+
# Detection/segmentation/pose/obb: prepare YAML and create base structure
|
|
806
|
+
data_yaml = dict(dataset_record)
|
|
807
|
+
data_yaml["names"] = class_names
|
|
808
|
+
data_yaml.pop("class_names", None)
|
|
809
|
+
data_yaml.pop("type", None) # Remove NDJSON-specific fields
|
|
810
|
+
for split in sorted(splits):
|
|
811
|
+
(dataset_dir / "images" / split).mkdir(parents=True, exist_ok=True)
|
|
812
|
+
(dataset_dir / "labels" / split).mkdir(parents=True, exist_ok=True)
|
|
813
|
+
data_yaml[split] = f"images/{split}"
|
|
803
814
|
|
|
804
815
|
async def process_record(session, semaphore, record):
|
|
805
816
|
"""Process single image record with async session."""
|
|
806
817
|
async with semaphore:
|
|
807
818
|
split, original_name = record["split"], record["file"]
|
|
808
|
-
label_path = dataset_dir / "labels" / split / f"{Path(original_name).stem}.txt"
|
|
809
|
-
image_path = dataset_dir / "images" / split / original_name
|
|
810
|
-
|
|
811
819
|
annotations = record.get("annotations", {})
|
|
812
|
-
lines_to_write = []
|
|
813
|
-
for key in annotations.keys():
|
|
814
|
-
lines_to_write = [" ".join(map(str, item)) for item in annotations[key]]
|
|
815
|
-
break
|
|
816
|
-
if "classification" in annotations:
|
|
817
|
-
lines_to_write = [str(cls) for cls in annotations["classification"]]
|
|
818
|
-
|
|
819
|
-
label_path.write_text("\n".join(lines_to_write) + "\n" if lines_to_write else "")
|
|
820
820
|
|
|
821
|
+
if is_classification:
|
|
822
|
+
# Classification: place image in {split}/{class_name}/ folder
|
|
823
|
+
class_ids = annotations.get("classification", [])
|
|
824
|
+
class_id = class_ids[0] if class_ids else 0
|
|
825
|
+
class_name = class_names.get(class_id, str(class_id))
|
|
826
|
+
image_path = dataset_dir / split / class_name / original_name
|
|
827
|
+
else:
|
|
828
|
+
# Detection: write label file and place image in images/{split}/
|
|
829
|
+
image_path = dataset_dir / "images" / split / original_name
|
|
830
|
+
label_path = dataset_dir / "labels" / split / f"{Path(original_name).stem}.txt"
|
|
831
|
+
lines_to_write = []
|
|
832
|
+
for key in annotations.keys():
|
|
833
|
+
lines_to_write = [" ".join(map(str, item)) for item in annotations[key]]
|
|
834
|
+
break
|
|
835
|
+
label_path.write_text("\n".join(lines_to_write) + "\n" if lines_to_write else "")
|
|
836
|
+
|
|
837
|
+
# Download image if URL provided and file doesn't exist
|
|
821
838
|
if http_url := record.get("url"):
|
|
822
839
|
if not image_path.exists():
|
|
840
|
+
image_path.parent.mkdir(parents=True, exist_ok=True)
|
|
823
841
|
try:
|
|
824
842
|
async with session.get(http_url, timeout=aiohttp.ClientTimeout(total=30)) as response:
|
|
825
843
|
response.raise_for_status()
|
|
826
|
-
|
|
827
|
-
async for chunk in response.content.iter_chunked(8192):
|
|
828
|
-
f.write(chunk)
|
|
844
|
+
image_path.write_bytes(await response.read())
|
|
829
845
|
return True
|
|
830
846
|
except Exception as e:
|
|
831
847
|
LOGGER.warning(f"Failed to download {http_url}: {e}")
|
|
832
848
|
return False
|
|
833
849
|
return True
|
|
834
850
|
|
|
835
|
-
# Process all images with async downloads
|
|
836
|
-
semaphore = asyncio.Semaphore(
|
|
851
|
+
# Process all images with async downloads (limit connections for small datasets)
|
|
852
|
+
semaphore = asyncio.Semaphore(min(128, len(image_records)))
|
|
837
853
|
async with aiohttp.ClientSession() as session:
|
|
838
854
|
pbar = TQDM(
|
|
839
855
|
total=len(image_records),
|
|
@@ -848,8 +864,11 @@ async def convert_ndjson_to_yolo(ndjson_path: str | Path, output_path: str | Pat
|
|
|
848
864
|
await asyncio.gather(*[tracked_process(record) for record in image_records])
|
|
849
865
|
pbar.close()
|
|
850
866
|
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
867
|
+
if is_classification:
|
|
868
|
+
# Classification: return dataset directory (check_cls_dataset expects a directory path)
|
|
869
|
+
return dataset_dir
|
|
870
|
+
else:
|
|
871
|
+
# Detection: write data.yaml and return its path
|
|
872
|
+
yaml_path = dataset_dir / "data.yaml"
|
|
873
|
+
YAML.save(yaml_path, data_yaml)
|
|
874
|
+
return yaml_path
|
ultralytics/engine/exporter.py
CHANGED
|
@@ -4,38 +4,38 @@ Export a YOLO PyTorch model to other formats. TensorFlow exports authored by htt
|
|
|
4
4
|
|
|
5
5
|
Format | `format=argument` | Model
|
|
6
6
|
--- | --- | ---
|
|
7
|
-
PyTorch | - |
|
|
8
|
-
TorchScript | `torchscript` |
|
|
9
|
-
ONNX | `onnx` |
|
|
10
|
-
OpenVINO | `openvino` |
|
|
11
|
-
TensorRT | `engine` |
|
|
12
|
-
CoreML | `coreml` |
|
|
13
|
-
TensorFlow SavedModel | `saved_model` |
|
|
14
|
-
TensorFlow GraphDef | `pb` |
|
|
15
|
-
TensorFlow Lite | `tflite` |
|
|
16
|
-
TensorFlow Edge TPU | `edgetpu` |
|
|
17
|
-
TensorFlow.js | `tfjs` |
|
|
18
|
-
PaddlePaddle | `paddle` |
|
|
19
|
-
MNN | `mnn` |
|
|
20
|
-
NCNN | `ncnn` |
|
|
21
|
-
IMX | `imx` |
|
|
22
|
-
RKNN | `rknn` |
|
|
23
|
-
ExecuTorch | `executorch` |
|
|
24
|
-
Axelera | `axelera` |
|
|
7
|
+
PyTorch | - | yolo26n.pt
|
|
8
|
+
TorchScript | `torchscript` | yolo26n.torchscript
|
|
9
|
+
ONNX | `onnx` | yolo26n.onnx
|
|
10
|
+
OpenVINO | `openvino` | yolo26n_openvino_model/
|
|
11
|
+
TensorRT | `engine` | yolo26n.engine
|
|
12
|
+
CoreML | `coreml` | yolo26n.mlpackage
|
|
13
|
+
TensorFlow SavedModel | `saved_model` | yolo26n_saved_model/
|
|
14
|
+
TensorFlow GraphDef | `pb` | yolo26n.pb
|
|
15
|
+
TensorFlow Lite | `tflite` | yolo26n.tflite
|
|
16
|
+
TensorFlow Edge TPU | `edgetpu` | yolo26n_edgetpu.tflite
|
|
17
|
+
TensorFlow.js | `tfjs` | yolo26n_web_model/
|
|
18
|
+
PaddlePaddle | `paddle` | yolo26n_paddle_model/
|
|
19
|
+
MNN | `mnn` | yolo26n.mnn
|
|
20
|
+
NCNN | `ncnn` | yolo26n_ncnn_model/
|
|
21
|
+
IMX | `imx` | yolo26n_imx_model/
|
|
22
|
+
RKNN | `rknn` | yolo26n_rknn_model/
|
|
23
|
+
ExecuTorch | `executorch` | yolo26n_executorch_model/
|
|
24
|
+
Axelera | `axelera` | yolo26n_axelera_model/
|
|
25
25
|
|
|
26
26
|
Requirements:
|
|
27
27
|
$ pip install "ultralytics[export]"
|
|
28
28
|
|
|
29
29
|
Python:
|
|
30
30
|
from ultralytics import YOLO
|
|
31
|
-
model = YOLO('
|
|
31
|
+
model = YOLO('yolo26n.pt')
|
|
32
32
|
results = model.export(format='onnx')
|
|
33
33
|
|
|
34
34
|
CLI:
|
|
35
|
-
$ yolo mode=export model=
|
|
35
|
+
$ yolo mode=export model=yolo26n.pt format=onnx
|
|
36
36
|
|
|
37
37
|
Inference:
|
|
38
|
-
$ yolo predict model=
|
|
38
|
+
$ yolo predict model=yolo26n.pt # PyTorch
|
|
39
39
|
yolo11n.torchscript # TorchScript
|
|
40
40
|
yolo11n.onnx # ONNX Runtime or OpenCV DNN with dnn=True
|
|
41
41
|
yolo11n_openvino_model # OpenVINO
|
|
@@ -614,12 +614,11 @@ class Exporter:
|
|
|
614
614
|
f"work. Use export 'imgsz={max(self.imgsz)}' if val is required."
|
|
615
615
|
)
|
|
616
616
|
imgsz = self.imgsz[0] if square else str(self.imgsz)[1:-1].replace(" ", "")
|
|
617
|
-
predict_data = f"data={data}" if model.task == "segment" and pb else ""
|
|
618
617
|
q = "int8" if self.args.int8 else "half" if self.args.half else "" # quantization
|
|
619
618
|
LOGGER.info(
|
|
620
619
|
f"\nExport complete ({time.time() - t:.1f}s)"
|
|
621
620
|
f"\nResults saved to {colorstr('bold', file.parent.resolve())}"
|
|
622
|
-
f"\nPredict: yolo predict task={model.task} model={f} imgsz={imgsz} {q}
|
|
621
|
+
f"\nPredict: yolo predict task={model.task} model={f} imgsz={imgsz} {q}"
|
|
623
622
|
f"\nValidate: yolo val task={model.task} model={f} imgsz={imgsz} data={data} {q} {s}"
|
|
624
623
|
f"\nVisualize: https://netron.app"
|
|
625
624
|
)
|
|
@@ -930,7 +929,7 @@ class Exporter:
|
|
|
930
929
|
model = IOSDetectModel(self.model, self.im, mlprogram=not mlmodel) if self.args.nms else self.model
|
|
931
930
|
else:
|
|
932
931
|
if self.args.nms:
|
|
933
|
-
LOGGER.warning(f"{prefix} 'nms=True' is only available for Detect models like '
|
|
932
|
+
LOGGER.warning(f"{prefix} 'nms=True' is only available for Detect models like 'yolo26n.pt'.")
|
|
934
933
|
# TODO CoreML Segment and Pose model pipelining
|
|
935
934
|
model = self.model
|
|
936
935
|
ts = torch.jit.trace(model.eval(), self.im, strict=False) # TorchScript model
|
ultralytics/engine/model.py
CHANGED
|
@@ -71,7 +71,7 @@ class Model(torch.nn.Module):
|
|
|
71
71
|
|
|
72
72
|
Examples:
|
|
73
73
|
>>> from ultralytics import YOLO
|
|
74
|
-
>>> model = YOLO("
|
|
74
|
+
>>> model = YOLO("yolo26n.pt")
|
|
75
75
|
>>> results = model.predict("image.jpg")
|
|
76
76
|
>>> model.train(data="coco8.yaml", epochs=3)
|
|
77
77
|
>>> metrics = model.val()
|
|
@@ -80,7 +80,7 @@ class Model(torch.nn.Module):
|
|
|
80
80
|
|
|
81
81
|
def __init__(
|
|
82
82
|
self,
|
|
83
|
-
model: str | Path | Model = "
|
|
83
|
+
model: str | Path | Model = "yolo26n.pt",
|
|
84
84
|
task: str | None = None,
|
|
85
85
|
verbose: bool = False,
|
|
86
86
|
) -> None:
|
|
@@ -169,7 +169,7 @@ class Model(torch.nn.Module):
|
|
|
169
169
|
object.
|
|
170
170
|
|
|
171
171
|
Examples:
|
|
172
|
-
>>> model = YOLO("
|
|
172
|
+
>>> model = YOLO("yolo26n.pt")
|
|
173
173
|
>>> results = model("https://ultralytics.com/images/bus.jpg")
|
|
174
174
|
>>> for r in results:
|
|
175
175
|
... print(f"Detected {len(r)} objects in image")
|
|
@@ -192,7 +192,7 @@ class Model(torch.nn.Module):
|
|
|
192
192
|
Examples:
|
|
193
193
|
>>> Model.is_triton_model("http://localhost:8000/v2/models/yolo11n")
|
|
194
194
|
True
|
|
195
|
-
>>> Model.is_triton_model("
|
|
195
|
+
>>> Model.is_triton_model("yolo26n.pt")
|
|
196
196
|
False
|
|
197
197
|
"""
|
|
198
198
|
from urllib.parse import urlsplit
|
|
@@ -216,7 +216,7 @@ class Model(torch.nn.Module):
|
|
|
216
216
|
Examples:
|
|
217
217
|
>>> Model.is_hub_model("https://hub.ultralytics.com/models/MODEL")
|
|
218
218
|
True
|
|
219
|
-
>>> Model.is_hub_model("
|
|
219
|
+
>>> Model.is_hub_model("yolo26n.pt")
|
|
220
220
|
False
|
|
221
221
|
"""
|
|
222
222
|
from ultralytics.hub import HUB_WEB_ROOT
|
|
@@ -242,7 +242,7 @@ class Model(torch.nn.Module):
|
|
|
242
242
|
|
|
243
243
|
Examples:
|
|
244
244
|
>>> model = Model()
|
|
245
|
-
>>> model._new("
|
|
245
|
+
>>> model._new("yolo26n.yaml", task="detect", verbose=True)
|
|
246
246
|
"""
|
|
247
247
|
cfg_dict = yaml_model_load(cfg)
|
|
248
248
|
self.cfg = cfg
|
|
@@ -272,12 +272,12 @@ class Model(torch.nn.Module):
|
|
|
272
272
|
|
|
273
273
|
Examples:
|
|
274
274
|
>>> model = Model()
|
|
275
|
-
>>> model._load("
|
|
275
|
+
>>> model._load("yolo26n.pt")
|
|
276
276
|
>>> model._load("path/to/weights.pth", task="detect")
|
|
277
277
|
"""
|
|
278
278
|
if weights.lower().startswith(("https://", "http://", "rtsp://", "rtmp://", "tcp://", "ul://")):
|
|
279
279
|
weights = checks.check_file(weights, download_dir=SETTINGS["weights_dir"]) # download and return local file
|
|
280
|
-
weights = checks.check_model_file_from_stem(weights) # add suffix, i.e.
|
|
280
|
+
weights = checks.check_model_file_from_stem(weights) # add suffix, i.e. yolo26 -> yolo26n.pt
|
|
281
281
|
|
|
282
282
|
if str(weights).rpartition(".")[-1] == "pt":
|
|
283
283
|
self.model, self.ckpt = load_checkpoint(weights)
|
|
@@ -304,7 +304,7 @@ class Model(torch.nn.Module):
|
|
|
304
304
|
information about supported model formats and operations.
|
|
305
305
|
|
|
306
306
|
Examples:
|
|
307
|
-
>>> model = Model("
|
|
307
|
+
>>> model = Model("yolo26n.pt")
|
|
308
308
|
>>> model._check_is_pytorch_model() # No error raised
|
|
309
309
|
>>> model = Model("yolo11n.onnx")
|
|
310
310
|
>>> model._check_is_pytorch_model() # Raises TypeError
|
|
@@ -334,7 +334,7 @@ class Model(torch.nn.Module):
|
|
|
334
334
|
AssertionError: If the model is not a PyTorch model.
|
|
335
335
|
|
|
336
336
|
Examples:
|
|
337
|
-
>>> model = Model("
|
|
337
|
+
>>> model = Model("yolo26n.pt")
|
|
338
338
|
>>> model.reset_weights()
|
|
339
339
|
"""
|
|
340
340
|
self._check_is_pytorch_model()
|
|
@@ -345,7 +345,7 @@ class Model(torch.nn.Module):
|
|
|
345
345
|
p.requires_grad = True
|
|
346
346
|
return self
|
|
347
347
|
|
|
348
|
-
def load(self, weights: str | Path = "
|
|
348
|
+
def load(self, weights: str | Path = "yolo26n.pt") -> Model:
|
|
349
349
|
"""Load parameters from the specified weights file into the model.
|
|
350
350
|
|
|
351
351
|
This method supports loading weights from a file or directly from a weights object. It matches parameters by
|
|
@@ -362,7 +362,7 @@ class Model(torch.nn.Module):
|
|
|
362
362
|
|
|
363
363
|
Examples:
|
|
364
364
|
>>> model = Model()
|
|
365
|
-
>>> model.load("
|
|
365
|
+
>>> model.load("yolo26n.pt")
|
|
366
366
|
>>> model.load(Path("path/to/weights.pt"))
|
|
367
367
|
"""
|
|
368
368
|
self._check_is_pytorch_model()
|
|
@@ -385,7 +385,7 @@ class Model(torch.nn.Module):
|
|
|
385
385
|
AssertionError: If the model is not a PyTorch model.
|
|
386
386
|
|
|
387
387
|
Examples:
|
|
388
|
-
>>> model = Model("
|
|
388
|
+
>>> model = Model("yolo26n.pt")
|
|
389
389
|
>>> model.save("my_model.pt")
|
|
390
390
|
"""
|
|
391
391
|
self._check_is_pytorch_model()
|
|
@@ -419,7 +419,7 @@ class Model(torch.nn.Module):
|
|
|
419
419
|
summary, layer details, and parameter counts. Empty if verbose is True.
|
|
420
420
|
|
|
421
421
|
Examples:
|
|
422
|
-
>>> model = Model("
|
|
422
|
+
>>> model = Model("yolo26n.pt")
|
|
423
423
|
>>> model.info() # Prints model summary
|
|
424
424
|
>>> info_list = model.info(detailed=True, verbose=False) # Returns detailed info as a list
|
|
425
425
|
"""
|
|
@@ -438,7 +438,7 @@ class Model(torch.nn.Module):
|
|
|
438
438
|
performs both convolution and normalization in one step.
|
|
439
439
|
|
|
440
440
|
Examples:
|
|
441
|
-
>>> model = Model("
|
|
441
|
+
>>> model = Model("yolo26n.pt")
|
|
442
442
|
>>> model.fuse()
|
|
443
443
|
>>> # Model is now fused and ready for optimized inference
|
|
444
444
|
"""
|
|
@@ -466,7 +466,7 @@ class Model(torch.nn.Module):
|
|
|
466
466
|
(list[torch.Tensor]): A list containing the image embeddings.
|
|
467
467
|
|
|
468
468
|
Examples:
|
|
469
|
-
>>> model = YOLO("
|
|
469
|
+
>>> model = YOLO("yolo26n.pt")
|
|
470
470
|
>>> image = "https://ultralytics.com/images/bus.jpg"
|
|
471
471
|
>>> embeddings = model.embed(image)
|
|
472
472
|
>>> print(embeddings[0].shape)
|
|
@@ -502,7 +502,7 @@ class Model(torch.nn.Module):
|
|
|
502
502
|
object.
|
|
503
503
|
|
|
504
504
|
Examples:
|
|
505
|
-
>>> model = YOLO("
|
|
505
|
+
>>> model = YOLO("yolo26n.pt")
|
|
506
506
|
>>> results = model.predict(source="path/to/image.jpg", conf=0.25)
|
|
507
507
|
>>> for r in results:
|
|
508
508
|
... print(r.boxes.data) # print detection bounding boxes
|
|
@@ -559,7 +559,7 @@ class Model(torch.nn.Module):
|
|
|
559
559
|
(list[ultralytics.engine.results.Results]): A list of tracking results, each a Results object.
|
|
560
560
|
|
|
561
561
|
Examples:
|
|
562
|
-
>>> model = YOLO("
|
|
562
|
+
>>> model = YOLO("yolo26n.pt")
|
|
563
563
|
>>> results = model.track(source="path/to/video.mp4", show=True)
|
|
564
564
|
>>> for r in results:
|
|
565
565
|
... print(r.boxes.id) # print tracking IDs
|
|
@@ -601,7 +601,7 @@ class Model(torch.nn.Module):
|
|
|
601
601
|
AssertionError: If the model is not a PyTorch model.
|
|
602
602
|
|
|
603
603
|
Examples:
|
|
604
|
-
>>> model = YOLO("
|
|
604
|
+
>>> model = YOLO("yolo26n.pt")
|
|
605
605
|
>>> results = model.val(data="coco8.yaml", imgsz=640)
|
|
606
606
|
>>> print(results.box.map) # Print mAP50-95
|
|
607
607
|
"""
|
|
@@ -639,7 +639,7 @@ class Model(torch.nn.Module):
|
|
|
639
639
|
AssertionError: If the model is not a PyTorch model.
|
|
640
640
|
|
|
641
641
|
Examples:
|
|
642
|
-
>>> model = YOLO("
|
|
642
|
+
>>> model = YOLO("yolo26n.pt")
|
|
643
643
|
>>> results = model.benchmark(data="coco8.yaml", imgsz=640, half=True)
|
|
644
644
|
>>> print(results)
|
|
645
645
|
"""
|
|
@@ -692,7 +692,7 @@ class Model(torch.nn.Module):
|
|
|
692
692
|
RuntimeError: If the export process fails due to errors.
|
|
693
693
|
|
|
694
694
|
Examples:
|
|
695
|
-
>>> model = YOLO("
|
|
695
|
+
>>> model = YOLO("yolo26n.pt")
|
|
696
696
|
>>> model.export(format="onnx", dynamic=True, simplify=True)
|
|
697
697
|
'path/to/exported/model.onnx'
|
|
698
698
|
"""
|
|
@@ -742,7 +742,7 @@ class Model(torch.nn.Module):
|
|
|
742
742
|
(dict | None): Training metrics if available and training is successful; otherwise, None.
|
|
743
743
|
|
|
744
744
|
Examples:
|
|
745
|
-
>>> model = YOLO("
|
|
745
|
+
>>> model = YOLO("yolo26n.pt")
|
|
746
746
|
>>> results = model.train(data="coco8.yaml", epochs=3)
|
|
747
747
|
"""
|
|
748
748
|
self._check_is_pytorch_model()
|
|
@@ -808,7 +808,7 @@ class Model(torch.nn.Module):
|
|
|
808
808
|
TypeError: If the model is not a PyTorch model.
|
|
809
809
|
|
|
810
810
|
Examples:
|
|
811
|
-
>>> model = YOLO("
|
|
811
|
+
>>> model = YOLO("yolo26n.pt")
|
|
812
812
|
>>> results = model.tune(data="coco8.yaml", iterations=5)
|
|
813
813
|
>>> print(results)
|
|
814
814
|
|
|
@@ -845,7 +845,7 @@ class Model(torch.nn.Module):
|
|
|
845
845
|
AssertionError: If the model is not a PyTorch model.
|
|
846
846
|
|
|
847
847
|
Examples:
|
|
848
|
-
>>> model = Model("
|
|
848
|
+
>>> model = Model("yolo26n.pt")
|
|
849
849
|
>>> model = model._apply(lambda t: t.cuda()) # Move model to GPU
|
|
850
850
|
"""
|
|
851
851
|
self._check_is_pytorch_model()
|
|
@@ -870,7 +870,7 @@ class Model(torch.nn.Module):
|
|
|
870
870
|
AttributeError: If the model or predictor does not have a 'names' attribute.
|
|
871
871
|
|
|
872
872
|
Examples:
|
|
873
|
-
>>> model = YOLO("
|
|
873
|
+
>>> model = YOLO("yolo26n.pt")
|
|
874
874
|
>>> print(model.names)
|
|
875
875
|
{0: 'person', 1: 'bicycle', 2: 'car', ...}
|
|
876
876
|
"""
|
|
@@ -898,7 +898,7 @@ class Model(torch.nn.Module):
|
|
|
898
898
|
AttributeError: If the model is not a torch.nn.Module instance.
|
|
899
899
|
|
|
900
900
|
Examples:
|
|
901
|
-
>>> model = YOLO("
|
|
901
|
+
>>> model = YOLO("yolo26n.pt")
|
|
902
902
|
>>> print(model.device)
|
|
903
903
|
device(type='cuda', index=0) # if CUDA is available
|
|
904
904
|
>>> model = model.to("cpu")
|
|
@@ -919,7 +919,7 @@ class Model(torch.nn.Module):
|
|
|
919
919
|
(object | None): The transform object of the model if available, otherwise None.
|
|
920
920
|
|
|
921
921
|
Examples:
|
|
922
|
-
>>> model = YOLO("
|
|
922
|
+
>>> model = YOLO("yolo26n.pt")
|
|
923
923
|
>>> transforms = model.transforms
|
|
924
924
|
>>> if transforms:
|
|
925
925
|
... print(f"Model transforms: {transforms}")
|
|
@@ -947,7 +947,7 @@ class Model(torch.nn.Module):
|
|
|
947
947
|
Examples:
|
|
948
948
|
>>> def on_train_start(trainer):
|
|
949
949
|
... print("Training is starting!")
|
|
950
|
-
>>> model = YOLO("
|
|
950
|
+
>>> model = YOLO("yolo26n.pt")
|
|
951
951
|
>>> model.add_callback("on_train_start", on_train_start)
|
|
952
952
|
>>> model.train(data="coco8.yaml", epochs=1)
|
|
953
953
|
"""
|
|
@@ -965,7 +965,7 @@ class Model(torch.nn.Module):
|
|
|
965
965
|
recognized by the Ultralytics callback system.
|
|
966
966
|
|
|
967
967
|
Examples:
|
|
968
|
-
>>> model = YOLO("
|
|
968
|
+
>>> model = YOLO("yolo26n.pt")
|
|
969
969
|
>>> model.add_callback("on_train_start", lambda: print("Training started"))
|
|
970
970
|
>>> model.clear_callback("on_train_start")
|
|
971
971
|
>>> # All callbacks for 'on_train_start' are now removed
|
|
@@ -994,7 +994,7 @@ class Model(torch.nn.Module):
|
|
|
994
994
|
modifications, ensuring consistent behavior across different runs or experiments.
|
|
995
995
|
|
|
996
996
|
Examples:
|
|
997
|
-
>>> model = YOLO("
|
|
997
|
+
>>> model = YOLO("yolo26n.pt")
|
|
998
998
|
>>> model.add_callback("on_train_start", custom_function)
|
|
999
999
|
>>> model.reset_callbacks()
|
|
1000
1000
|
# All callbacks are now reset to their default functions
|
|
@@ -1076,7 +1076,7 @@ class Model(torch.nn.Module):
|
|
|
1076
1076
|
implementations for that task.
|
|
1077
1077
|
|
|
1078
1078
|
Examples:
|
|
1079
|
-
>>> model = Model("
|
|
1079
|
+
>>> model = Model("yolo26n.pt")
|
|
1080
1080
|
>>> task_map = model.task_map
|
|
1081
1081
|
>>> detect_predictor = task_map["detect"]["predictor"]
|
|
1082
1082
|
>>> segment_trainer = task_map["segment"]["trainer"]
|
|
@@ -1094,7 +1094,7 @@ class Model(torch.nn.Module):
|
|
|
1094
1094
|
(Model): The model instance with evaluation mode set.
|
|
1095
1095
|
|
|
1096
1096
|
Examples:
|
|
1097
|
-
>>> model = YOLO("
|
|
1097
|
+
>>> model = YOLO("yolo26n.pt")
|
|
1098
1098
|
>>> model.eval()
|
|
1099
1099
|
>>> # Model is now in evaluation mode for inference
|
|
1100
1100
|
"""
|
|
@@ -1118,7 +1118,7 @@ class Model(torch.nn.Module):
|
|
|
1118
1118
|
AttributeError: If the requested attribute does not exist in the model.
|
|
1119
1119
|
|
|
1120
1120
|
Examples:
|
|
1121
|
-
>>> model = YOLO("
|
|
1121
|
+
>>> model = YOLO("yolo26n.pt")
|
|
1122
1122
|
>>> print(model.stride) # Access model.stride attribute
|
|
1123
1123
|
>>> print(model.names) # Access model.names attribute
|
|
1124
1124
|
"""
|
ultralytics/engine/predictor.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Run prediction on images, videos, directories, globs, YouTube, webcam, streams, etc.
|
|
4
4
|
|
|
5
5
|
Usage - sources:
|
|
6
|
-
$ yolo mode=predict model=
|
|
6
|
+
$ yolo mode=predict model=yolo26n.pt source=0 # webcam
|
|
7
7
|
img.jpg # image
|
|
8
8
|
vid.mp4 # video
|
|
9
9
|
screen # screenshot
|
|
@@ -15,22 +15,22 @@ Usage - sources:
|
|
|
15
15
|
'rtsp://example.com/media.mp4' # RTSP, RTMP, HTTP, TCP stream
|
|
16
16
|
|
|
17
17
|
Usage - formats:
|
|
18
|
-
$ yolo mode=predict model=
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
18
|
+
$ yolo mode=predict model=yolo26n.pt # PyTorch
|
|
19
|
+
yolo26n.torchscript # TorchScript
|
|
20
|
+
yolo26n.onnx # ONNX Runtime or OpenCV DNN with dnn=True
|
|
21
|
+
yolo26n_openvino_model # OpenVINO
|
|
22
|
+
yolo26n.engine # TensorRT
|
|
23
|
+
yolo26n.mlpackage # CoreML (macOS-only)
|
|
24
|
+
yolo26n_saved_model # TensorFlow SavedModel
|
|
25
|
+
yolo26n.pb # TensorFlow GraphDef
|
|
26
|
+
yolo26n.tflite # TensorFlow Lite
|
|
27
|
+
yolo26n_edgetpu.tflite # TensorFlow Edge TPU
|
|
28
|
+
yolo26n_paddle_model # PaddlePaddle
|
|
29
|
+
yolo26n.mnn # MNN
|
|
30
|
+
yolo26n_ncnn_model # NCNN
|
|
31
|
+
yolo26n_imx_model # Sony IMX
|
|
32
|
+
yolo26n_rknn_model # Rockchip RKNN
|
|
33
|
+
yolo26n.pte # PyTorch Executorch
|
|
34
34
|
"""
|
|
35
35
|
|
|
36
36
|
from __future__ import annotations
|
ultralytics/engine/results.py
CHANGED
|
@@ -667,7 +667,7 @@ class Results(SimpleClass, DataExportMixin):
|
|
|
667
667
|
|
|
668
668
|
Examples:
|
|
669
669
|
>>> from ultralytics import YOLO
|
|
670
|
-
>>> model = YOLO("
|
|
670
|
+
>>> model = YOLO("yolo26n.pt")
|
|
671
671
|
>>> results = model("path/to/image.jpg")
|
|
672
672
|
>>> for result in results:
|
|
673
673
|
>>> result.save_txt("output.txt")
|
|
@@ -750,8 +750,8 @@ class Results(SimpleClass, DataExportMixin):
|
|
|
750
750
|
"""Convert inference results to a summarized dictionary with optional normalization for box coordinates.
|
|
751
751
|
|
|
752
752
|
This method creates a list of detection dictionaries, each containing information about a single detection or
|
|
753
|
-
classification result. For classification tasks, it returns the top
|
|
754
|
-
|
|
753
|
+
classification result. For classification tasks, it returns the top 5 classes and their
|
|
754
|
+
confidences. For detection tasks, it includes class information, bounding box coordinates, and
|
|
755
755
|
optionally mask segments and keypoints.
|
|
756
756
|
|
|
757
757
|
Args:
|
|
@@ -772,14 +772,16 @@ class Results(SimpleClass, DataExportMixin):
|
|
|
772
772
|
# Create list of detection dictionaries
|
|
773
773
|
results = []
|
|
774
774
|
if self.probs is not None:
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
775
|
+
# Return top 5 classification results
|
|
776
|
+
for class_id, conf in zip(self.probs.top5, self.probs.top5conf.tolist()):
|
|
777
|
+
class_id = int(class_id)
|
|
778
|
+
results.append(
|
|
779
|
+
{
|
|
780
|
+
"name": self.names[class_id],
|
|
781
|
+
"class": class_id,
|
|
782
|
+
"confidence": round(conf, decimals),
|
|
783
|
+
}
|
|
784
|
+
)
|
|
783
785
|
return results
|
|
784
786
|
|
|
785
787
|
is_obb = self.obb is not None
|
|
@@ -1500,7 +1502,7 @@ class OBB(BaseTensor):
|
|
|
1500
1502
|
Examples:
|
|
1501
1503
|
>>> import torch
|
|
1502
1504
|
>>> from ultralytics import YOLO
|
|
1503
|
-
>>> model = YOLO("
|
|
1505
|
+
>>> model = YOLO("yolo26n-obb.pt")
|
|
1504
1506
|
>>> results = model("path/to/image.jpg")
|
|
1505
1507
|
>>> for result in results:
|
|
1506
1508
|
... obb = result.obb
|