ultralytics 8.3.64__py3-none-any.whl → 8.3.66__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tests/test_exports.py +3 -2
- ultralytics/__init__.py +1 -1
- ultralytics/cfg/__init__.py +97 -94
- ultralytics/cfg/models/11/yolo11-cls-resnet18.yaml +1 -8
- ultralytics/data/augment.py +1 -1
- ultralytics/data/build.py +5 -1
- ultralytics/data/split_dota.py +3 -3
- ultralytics/data/utils.py +1 -1
- ultralytics/engine/exporter.py +51 -18
- ultralytics/engine/model.py +5 -5
- ultralytics/engine/predictor.py +16 -14
- ultralytics/engine/results.py +1 -1
- ultralytics/engine/trainer.py +3 -4
- ultralytics/engine/tuner.py +2 -2
- ultralytics/engine/validator.py +16 -14
- 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/obb/predict.py +1 -1
- ultralytics/models/yolo/obb/train.py +1 -1
- ultralytics/models/yolo/obb/val.py +1 -1
- ultralytics/models/yolo/pose/predict.py +1 -1
- ultralytics/models/yolo/pose/train.py +1 -1
- ultralytics/models/yolo/pose/val.py +1 -1
- ultralytics/models/yolo/segment/predict.py +1 -1
- ultralytics/models/yolo/segment/train.py +1 -1
- ultralytics/models/yolo/segment/val.py +1 -1
- ultralytics/nn/autobackend.py +34 -4
- ultralytics/nn/modules/block.py +1 -3
- ultralytics/nn/modules/conv.py +1 -1
- ultralytics/nn/tasks.py +61 -53
- ultralytics/solutions/ai_gym.py +1 -1
- ultralytics/solutions/heatmap.py +1 -1
- ultralytics/solutions/parking_management.py +1 -1
- ultralytics/solutions/solutions.py +1 -1
- ultralytics/trackers/track.py +3 -0
- ultralytics/trackers/utils/matching.py +2 -2
- ultralytics/utils/__init__.py +17 -3
- ultralytics/utils/benchmarks.py +29 -23
- ultralytics/utils/checks.py +21 -2
- ultralytics/utils/downloads.py +1 -1
- ultralytics/utils/instance.py +1 -1
- ultralytics/utils/loss.py +2 -2
- ultralytics/utils/tuner.py +2 -2
- {ultralytics-8.3.64.dist-info → ultralytics-8.3.66.dist-info}/METADATA +1 -2
- {ultralytics-8.3.64.dist-info → ultralytics-8.3.66.dist-info}/RECORD +50 -50
- {ultralytics-8.3.64.dist-info → ultralytics-8.3.66.dist-info}/LICENSE +0 -0
- {ultralytics-8.3.64.dist-info → ultralytics-8.3.66.dist-info}/WHEEL +0 -0
- {ultralytics-8.3.64.dist-info → ultralytics-8.3.66.dist-info}/entry_points.txt +0 -0
- {ultralytics-8.3.64.dist-info → ultralytics-8.3.66.dist-info}/top_level.txt +0 -0
tests/test_exports.py
CHANGED
@@ -11,6 +11,7 @@ from tests import MODEL, SOURCE
|
|
11
11
|
from ultralytics import YOLO
|
12
12
|
from ultralytics.cfg import TASK2DATA, TASK2MODEL, TASKS
|
13
13
|
from ultralytics.utils import (
|
14
|
+
ARM64,
|
14
15
|
IS_RASPBERRYPI,
|
15
16
|
LINUX,
|
16
17
|
MACOS,
|
@@ -157,7 +158,7 @@ def test_export_tflite_matrix(task, dynamic, int8, half, batch):
|
|
157
158
|
|
158
159
|
@pytest.mark.skipif(not TORCH_1_9, reason="CoreML>=7.2 not supported with PyTorch<=1.8")
|
159
160
|
@pytest.mark.skipif(WINDOWS, reason="CoreML not supported on Windows") # RuntimeError: BlobWriter not loaded
|
160
|
-
@pytest.mark.skipif(
|
161
|
+
@pytest.mark.skipif(LINUX and ARM64, reason="CoreML not supported on aarch64 Linux")
|
161
162
|
@pytest.mark.skipif(checks.IS_PYTHON_3_12, reason="CoreML not supported in Python 3.12")
|
162
163
|
def test_export_coreml():
|
163
164
|
"""Test YOLO exports to CoreML format, optimized for macOS only."""
|
@@ -210,7 +211,7 @@ def test_export_ncnn():
|
|
210
211
|
@pytest.mark.skipif(True, reason="Test disabled as keras and tensorflow version conflicts with tflite export.")
|
211
212
|
@pytest.mark.skipif(not LINUX or MACOS, reason="Skipping test on Windows and Macos")
|
212
213
|
def test_export_imx():
|
213
|
-
"""Test
|
214
|
+
"""Test YOLO exports to IMX format."""
|
214
215
|
model = YOLO("yolov8n.pt")
|
215
216
|
file = model.export(format="imx", imgsz=32)
|
216
217
|
YOLO(file)(SOURCE, imgsz=32)
|
ultralytics/__init__.py
CHANGED
ultralytics/cfg/__init__.py
CHANGED
@@ -47,8 +47,8 @@ SOLUTION_MAP = {
|
|
47
47
|
}
|
48
48
|
|
49
49
|
# Define valid tasks and modes
|
50
|
-
MODES = {"train", "val", "predict", "export", "track", "benchmark"}
|
51
|
-
TASKS = {"detect", "segment", "classify", "pose", "obb"}
|
50
|
+
MODES = frozenset({"train", "val", "predict", "export", "track", "benchmark"})
|
51
|
+
TASKS = frozenset({"detect", "segment", "classify", "pose", "obb"})
|
52
52
|
TASK2DATA = {
|
53
53
|
"detect": "coco8.yaml",
|
54
54
|
"segment": "coco8-seg.yaml",
|
@@ -70,7 +70,7 @@ TASK2METRIC = {
|
|
70
70
|
"pose": "metrics/mAP50-95(P)",
|
71
71
|
"obb": "metrics/mAP50-95(B)",
|
72
72
|
}
|
73
|
-
MODELS = {TASK2MODEL[task] for task in TASKS}
|
73
|
+
MODELS = frozenset({TASK2MODEL[task] for task in TASKS})
|
74
74
|
|
75
75
|
ARGV = sys.argv or ["", ""] # sometimes sys.argv = []
|
76
76
|
SOLUTIONS_HELP_MSG = f"""
|
@@ -144,90 +144,98 @@ CLI_HELP_MSG = f"""
|
|
144
144
|
"""
|
145
145
|
|
146
146
|
# Define keys for arg type checks
|
147
|
-
CFG_FLOAT_KEYS =
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
147
|
+
CFG_FLOAT_KEYS = frozenset(
|
148
|
+
{ # integer or float arguments, i.e. x=2 and x=2.0
|
149
|
+
"warmup_epochs",
|
150
|
+
"box",
|
151
|
+
"cls",
|
152
|
+
"dfl",
|
153
|
+
"degrees",
|
154
|
+
"shear",
|
155
|
+
"time",
|
156
|
+
"workspace",
|
157
|
+
"batch",
|
158
|
+
}
|
159
|
+
)
|
160
|
+
CFG_FRACTION_KEYS = frozenset(
|
161
|
+
{ # fractional float arguments with 0.0<=values<=1.0
|
162
|
+
"dropout",
|
163
|
+
"lr0",
|
164
|
+
"lrf",
|
165
|
+
"momentum",
|
166
|
+
"weight_decay",
|
167
|
+
"warmup_momentum",
|
168
|
+
"warmup_bias_lr",
|
169
|
+
"hsv_h",
|
170
|
+
"hsv_s",
|
171
|
+
"hsv_v",
|
172
|
+
"translate",
|
173
|
+
"scale",
|
174
|
+
"perspective",
|
175
|
+
"flipud",
|
176
|
+
"fliplr",
|
177
|
+
"bgr",
|
178
|
+
"mosaic",
|
179
|
+
"mixup",
|
180
|
+
"copy_paste",
|
181
|
+
"conf",
|
182
|
+
"iou",
|
183
|
+
"fraction",
|
184
|
+
}
|
185
|
+
)
|
186
|
+
CFG_INT_KEYS = frozenset(
|
187
|
+
{ # integer-only arguments
|
188
|
+
"epochs",
|
189
|
+
"patience",
|
190
|
+
"workers",
|
191
|
+
"seed",
|
192
|
+
"close_mosaic",
|
193
|
+
"mask_ratio",
|
194
|
+
"max_det",
|
195
|
+
"vid_stride",
|
196
|
+
"line_width",
|
197
|
+
"nbs",
|
198
|
+
"save_period",
|
199
|
+
}
|
200
|
+
)
|
201
|
+
CFG_BOOL_KEYS = frozenset(
|
202
|
+
{ # boolean-only arguments
|
203
|
+
"save",
|
204
|
+
"exist_ok",
|
205
|
+
"verbose",
|
206
|
+
"deterministic",
|
207
|
+
"single_cls",
|
208
|
+
"rect",
|
209
|
+
"cos_lr",
|
210
|
+
"overlap_mask",
|
211
|
+
"val",
|
212
|
+
"save_json",
|
213
|
+
"save_hybrid",
|
214
|
+
"half",
|
215
|
+
"dnn",
|
216
|
+
"plots",
|
217
|
+
"show",
|
218
|
+
"save_txt",
|
219
|
+
"save_conf",
|
220
|
+
"save_crop",
|
221
|
+
"save_frames",
|
222
|
+
"show_labels",
|
223
|
+
"show_conf",
|
224
|
+
"visualize",
|
225
|
+
"augment",
|
226
|
+
"agnostic_nms",
|
227
|
+
"retina_masks",
|
228
|
+
"show_boxes",
|
229
|
+
"keras",
|
230
|
+
"optimize",
|
231
|
+
"int8",
|
232
|
+
"dynamic",
|
233
|
+
"simplify",
|
234
|
+
"nms",
|
235
|
+
"profile",
|
236
|
+
"multi_scale",
|
237
|
+
}
|
238
|
+
)
|
231
239
|
|
232
240
|
|
233
241
|
def cfg2dict(cfg):
|
@@ -472,7 +480,7 @@ def check_dict_alignment(base: Dict, custom: Dict, e=None):
|
|
472
480
|
- Prints detailed error messages for each mismatched key to help users correct their configurations.
|
473
481
|
"""
|
474
482
|
custom = _handle_deprecation(custom)
|
475
|
-
base_keys, custom_keys = (
|
483
|
+
base_keys, custom_keys = (frozenset(x.keys()) for x in (base, custom))
|
476
484
|
if mismatched := [k for k in custom_keys if k not in base_keys]:
|
477
485
|
from difflib import get_close_matches
|
478
486
|
|
@@ -913,12 +921,7 @@ def entrypoint(debug=""):
|
|
913
921
|
# Task
|
914
922
|
task = overrides.pop("task", None)
|
915
923
|
if task:
|
916
|
-
if task
|
917
|
-
raise ValueError(
|
918
|
-
f"❌ Classification doesn't support 'mode=track'. Valid modes for classification are"
|
919
|
-
f" {MODES - {'track'}}.\n{CLI_HELP_MSG}"
|
920
|
-
)
|
921
|
-
elif task not in TASKS:
|
924
|
+
if task not in TASKS:
|
922
925
|
if task == "track":
|
923
926
|
LOGGER.warning(
|
924
927
|
"WARNING ⚠️ invalid 'task=track', setting 'task=detect' and 'mode=track'. Valid tasks are {TASKS}.\n{CLI_HELP_MSG}."
|
@@ -6,18 +6,11 @@
|
|
6
6
|
|
7
7
|
# Parameters
|
8
8
|
nc: 10 # number of classes
|
9
|
-
scales: # model compound scaling constants, i.e. 'model=yolo11n-cls.yaml' will call yolo11-cls.yaml with scale 'n'
|
10
|
-
# [depth, width, max_channels]
|
11
|
-
n: [0.33, 0.25, 1024]
|
12
|
-
s: [0.33, 0.50, 1024]
|
13
|
-
m: [0.67, 0.75, 1024]
|
14
|
-
l: [1.00, 1.00, 1024]
|
15
|
-
x: [1.00, 1.25, 1024]
|
16
9
|
|
17
10
|
# ResNet18 backbone
|
18
11
|
backbone:
|
19
12
|
# [from, repeats, module, args]
|
20
|
-
- [-1, 1, TorchVision, [512,
|
13
|
+
- [-1, 1, TorchVision, [512, resnet18, DEFAULT, True, 2]] # truncate two layers from the end
|
21
14
|
|
22
15
|
# YOLO11n head
|
23
16
|
head:
|
ultralytics/data/augment.py
CHANGED
@@ -1850,7 +1850,7 @@ class Albumentations:
|
|
1850
1850
|
A.CLAHE(p=0.01),
|
1851
1851
|
A.RandomBrightnessContrast(p=0.0),
|
1852
1852
|
A.RandomGamma(p=0.0),
|
1853
|
-
A.ImageCompression(
|
1853
|
+
A.ImageCompression(quality_range=(75, 100), p=0.0),
|
1854
1854
|
]
|
1855
1855
|
|
1856
1856
|
# Compose transforms
|
ultralytics/data/build.py
CHANGED
@@ -49,11 +49,15 @@ class InfiniteDataLoader(dataloader.DataLoader):
|
|
49
49
|
|
50
50
|
def __del__(self):
|
51
51
|
"""Ensure that workers are terminated."""
|
52
|
-
|
52
|
+
try:
|
53
|
+
if not hasattr(self.iterator, "_workers"):
|
54
|
+
return
|
53
55
|
for w in self.iterator._workers: # force terminate
|
54
56
|
if w.is_alive():
|
55
57
|
w.terminate()
|
56
58
|
self.iterator._shutdown_workers() # cleanup
|
59
|
+
except Exception:
|
60
|
+
pass
|
57
61
|
|
58
62
|
def reset(self):
|
59
63
|
"""
|
ultralytics/data/split_dota.py
CHANGED
@@ -8,9 +8,9 @@ from pathlib import Path
|
|
8
8
|
import cv2
|
9
9
|
import numpy as np
|
10
10
|
from PIL import Image
|
11
|
-
from tqdm import tqdm
|
12
11
|
|
13
12
|
from ultralytics.data.utils import exif_size, img2label_paths
|
13
|
+
from ultralytics.utils import TQDM
|
14
14
|
from ultralytics.utils.checks import check_requirements
|
15
15
|
|
16
16
|
|
@@ -221,7 +221,7 @@ def split_images_and_labels(data_root, save_dir, split="train", crop_sizes=(1024
|
|
221
221
|
lb_dir.mkdir(parents=True, exist_ok=True)
|
222
222
|
|
223
223
|
annos = load_yolo_dota(data_root, split=split)
|
224
|
-
for anno in
|
224
|
+
for anno in TQDM(annos, total=len(annos), desc=split):
|
225
225
|
windows = get_windows(anno["ori_size"], crop_sizes, gaps)
|
226
226
|
window_objs = get_window_obj(anno, windows)
|
227
227
|
crop_and_save(anno, windows, window_objs, str(im_dir), str(lb_dir))
|
@@ -281,7 +281,7 @@ def split_test(data_root, save_dir, crop_size=1024, gap=200, rates=(1.0,)):
|
|
281
281
|
im_dir = Path(data_root) / "images" / "test"
|
282
282
|
assert im_dir.exists(), f"Can't find {im_dir}, please check your data root."
|
283
283
|
im_files = glob(str(im_dir / "*"))
|
284
|
-
for im_file in
|
284
|
+
for im_file in TQDM(im_files, total=len(im_files), desc="test"):
|
285
285
|
w, h = exif_size(Image.open(im_file))
|
286
286
|
windows = get_windows((h, w), crop_sizes=crop_sizes, gaps=gaps)
|
287
287
|
im = cv2.imread(im_file)
|
ultralytics/data/utils.py
CHANGED
@@ -136,7 +136,7 @@ def verify_image_label(args):
|
|
136
136
|
|
137
137
|
# All labels
|
138
138
|
max_cls = lb[:, 0].max() # max label count
|
139
|
-
assert max_cls
|
139
|
+
assert max_cls < num_cls, (
|
140
140
|
f"Label class {int(max_cls)} exceeds dataset class count {num_cls}. "
|
141
141
|
f"Possible class labels are 0-{num_cls - 1}"
|
142
142
|
)
|
ultralytics/engine/exporter.py
CHANGED
@@ -19,6 +19,7 @@ PaddlePaddle | `paddle` | yolo11n_paddle_model/
|
|
19
19
|
MNN | `mnn` | yolo11n.mnn
|
20
20
|
NCNN | `ncnn` | yolo11n_ncnn_model/
|
21
21
|
IMX | `imx` | yolo11n_imx_model/
|
22
|
+
RKNN | `rknn` | yolo11n_rknn_model/
|
22
23
|
|
23
24
|
Requirements:
|
24
25
|
$ pip install "ultralytics[export]"
|
@@ -78,11 +79,13 @@ from ultralytics.nn.tasks import DetectionModel, SegmentationModel, WorldModel
|
|
78
79
|
from ultralytics.utils import (
|
79
80
|
ARM64,
|
80
81
|
DEFAULT_CFG,
|
82
|
+
IS_COLAB,
|
81
83
|
IS_JETSON,
|
82
84
|
LINUX,
|
83
85
|
LOGGER,
|
84
86
|
MACOS,
|
85
87
|
PYTHON_VERSION,
|
88
|
+
RKNN_CHIPS,
|
86
89
|
ROOT,
|
87
90
|
WINDOWS,
|
88
91
|
__version__,
|
@@ -122,6 +125,7 @@ def export_formats():
|
|
122
125
|
["MNN", "mnn", ".mnn", True, True, ["batch", "half", "int8"]],
|
123
126
|
["NCNN", "ncnn", "_ncnn_model", True, True, ["batch", "half"]],
|
124
127
|
["IMX", "imx", "_imx_model", True, True, ["int8"]],
|
128
|
+
["RKNN", "rknn", "_rknn_model", False, False, ["batch", "name"]],
|
125
129
|
]
|
126
130
|
return dict(zip(["Format", "Argument", "Suffix", "CPU", "GPU", "Arguments"], zip(*x)))
|
127
131
|
|
@@ -226,22 +230,10 @@ class Exporter:
|
|
226
230
|
flags = [x == fmt for x in fmts]
|
227
231
|
if sum(flags) != 1:
|
228
232
|
raise ValueError(f"Invalid export format='{fmt}'. Valid formats are {fmts}")
|
229
|
-
(
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
engine,
|
234
|
-
coreml,
|
235
|
-
saved_model,
|
236
|
-
pb,
|
237
|
-
tflite,
|
238
|
-
edgetpu,
|
239
|
-
tfjs,
|
240
|
-
paddle,
|
241
|
-
mnn,
|
242
|
-
ncnn,
|
243
|
-
imx,
|
244
|
-
) = flags # export booleans
|
233
|
+
(jit, onnx, xml, engine, coreml, saved_model, pb, tflite, edgetpu, tfjs, paddle, mnn, ncnn, imx, rknn) = (
|
234
|
+
flags # export booleans
|
235
|
+
)
|
236
|
+
|
245
237
|
is_tf_format = any((saved_model, pb, tflite, edgetpu, tfjs))
|
246
238
|
|
247
239
|
# Device
|
@@ -277,6 +269,16 @@ class Exporter:
|
|
277
269
|
if self.args.optimize:
|
278
270
|
assert not ncnn, "optimize=True not compatible with format='ncnn', i.e. use optimize=False"
|
279
271
|
assert self.device.type == "cpu", "optimize=True not compatible with cuda devices, i.e. use device='cpu'"
|
272
|
+
if rknn:
|
273
|
+
if not self.args.name:
|
274
|
+
LOGGER.warning(
|
275
|
+
"WARNING ⚠️ Rockchip RKNN export requires a missing 'name' arg for processor type. Using default name='rk3588'."
|
276
|
+
)
|
277
|
+
self.args.name = "rk3588"
|
278
|
+
self.args.name = self.args.name.lower()
|
279
|
+
assert self.args.name in RKNN_CHIPS, (
|
280
|
+
f"Invalid processor name '{self.args.name}' for Rockchip RKNN export. Valid names are {RKNN_CHIPS}."
|
281
|
+
)
|
280
282
|
if self.args.int8 and tflite:
|
281
283
|
assert not getattr(model, "end2end", False), "TFLite INT8 export not supported for end2end models."
|
282
284
|
if edgetpu:
|
@@ -417,6 +419,8 @@ class Exporter:
|
|
417
419
|
f[12], _ = self.export_ncnn()
|
418
420
|
if imx:
|
419
421
|
f[13], _ = self.export_imx()
|
422
|
+
if rknn:
|
423
|
+
f[14], _ = self.export_rknn()
|
420
424
|
|
421
425
|
# Finish
|
422
426
|
f = [str(x) for x in f if x] # filter out '' and None
|
@@ -746,7 +750,7 @@ class Exporter:
|
|
746
750
|
model = IOSDetectModel(self.model, self.im) if self.args.nms else self.model
|
747
751
|
else:
|
748
752
|
if self.args.nms:
|
749
|
-
LOGGER.warning(f"{prefix} WARNING ⚠️ 'nms=True' is only available for Detect models like '
|
753
|
+
LOGGER.warning(f"{prefix} WARNING ⚠️ 'nms=True' is only available for Detect models like 'yolo11n.pt'.")
|
750
754
|
# TODO CoreML Segment and Pose model pipelining
|
751
755
|
model = self.model
|
752
756
|
|
@@ -1140,6 +1144,33 @@ class Exporter:
|
|
1140
1144
|
yaml_save(Path(f) / "metadata.yaml", self.metadata) # add metadata.yaml
|
1141
1145
|
return f, None
|
1142
1146
|
|
1147
|
+
@try_export
|
1148
|
+
def export_rknn(self, prefix=colorstr("RKNN:")):
|
1149
|
+
"""YOLO RKNN model export."""
|
1150
|
+
LOGGER.info(f"\n{prefix} starting export with rknn-toolkit2...")
|
1151
|
+
|
1152
|
+
check_requirements("rknn-toolkit2")
|
1153
|
+
if IS_COLAB:
|
1154
|
+
# Prevent 'exit' from closing the notebook https://github.com/airockchip/rknn-toolkit2/issues/259
|
1155
|
+
import builtins
|
1156
|
+
|
1157
|
+
builtins.exit = lambda: None
|
1158
|
+
|
1159
|
+
from rknn.api import RKNN
|
1160
|
+
|
1161
|
+
f, _ = self.export_onnx()
|
1162
|
+
export_path = Path(f"{Path(f).stem}_rknn_model")
|
1163
|
+
export_path.mkdir(exist_ok=True)
|
1164
|
+
|
1165
|
+
rknn = RKNN(verbose=False)
|
1166
|
+
rknn.config(mean_values=[[0, 0, 0]], std_values=[[255, 255, 255]], target_platform=self.args.name)
|
1167
|
+
rknn.load_onnx(model=f)
|
1168
|
+
rknn.build(do_quantization=False) # TODO: Add quantization support
|
1169
|
+
f = f.replace(".onnx", f"-{self.args.name}.rknn")
|
1170
|
+
rknn.export_rknn(f"{export_path / f}")
|
1171
|
+
yaml_save(export_path / "metadata.yaml", self.metadata)
|
1172
|
+
return export_path, None
|
1173
|
+
|
1143
1174
|
@try_export
|
1144
1175
|
def export_imx(self, prefix=colorstr("IMX:")):
|
1145
1176
|
"""YOLO IMX export."""
|
@@ -1158,6 +1189,8 @@ class Exporter:
|
|
1158
1189
|
import onnx
|
1159
1190
|
from sony_custom_layers.pytorch.object_detection.nms import multiclass_nms
|
1160
1191
|
|
1192
|
+
LOGGER.info(f"\n{prefix} starting export with model_compression_toolkit {mct.__version__}...")
|
1193
|
+
|
1161
1194
|
try:
|
1162
1195
|
out = subprocess.run(
|
1163
1196
|
["java", "--version"], check=True, capture_output=True
|
@@ -1253,7 +1286,7 @@ class Exporter:
|
|
1253
1286
|
|
1254
1287
|
f = Path(str(self.file).replace(self.file.suffix, "_imx_model"))
|
1255
1288
|
f.mkdir(exist_ok=True)
|
1256
|
-
onnx_model = f / Path(str(self.file).replace(self.file.suffix, "_imx.onnx")) # js dir
|
1289
|
+
onnx_model = f / Path(str(self.file.name).replace(self.file.suffix, "_imx.onnx")) # js dir
|
1257
1290
|
mct.exporter.pytorch_export_model(
|
1258
1291
|
model=quant_model, save_model_path=onnx_model, repr_dataset=representative_dataset_gen
|
1259
1292
|
)
|
ultralytics/engine/model.py
CHANGED
@@ -194,7 +194,7 @@ class Model(nn.Module):
|
|
194
194
|
(bool): True if the model string is a valid Triton Server URL, False otherwise.
|
195
195
|
|
196
196
|
Examples:
|
197
|
-
>>> Model.is_triton_model("http://localhost:8000/v2/models/
|
197
|
+
>>> Model.is_triton_model("http://localhost:8000/v2/models/yolo11n")
|
198
198
|
True
|
199
199
|
>>> Model.is_triton_model("yolo11n.pt")
|
200
200
|
False
|
@@ -247,7 +247,7 @@ class Model(nn.Module):
|
|
247
247
|
|
248
248
|
Examples:
|
249
249
|
>>> model = Model()
|
250
|
-
>>> model._new("
|
250
|
+
>>> model._new("yolo11n.yaml", task="detect", verbose=True)
|
251
251
|
"""
|
252
252
|
cfg_dict = yaml_model_load(cfg)
|
253
253
|
self.cfg = cfg
|
@@ -283,7 +283,7 @@ class Model(nn.Module):
|
|
283
283
|
"""
|
284
284
|
if weights.lower().startswith(("https://", "http://", "rtsp://", "rtmp://", "tcp://")):
|
285
285
|
weights = checks.check_file(weights, download_dir=SETTINGS["weights_dir"]) # download and return local file
|
286
|
-
weights = checks.check_model_file_from_stem(weights) # add suffix, i.e.
|
286
|
+
weights = checks.check_model_file_from_stem(weights) # add suffix, i.e. yolo11n -> yolo11n.pt
|
287
287
|
|
288
288
|
if Path(weights).suffix == ".pt":
|
289
289
|
self.model, self.ckpt = attempt_load_one_weight(weights)
|
@@ -313,7 +313,7 @@ class Model(nn.Module):
|
|
313
313
|
Examples:
|
314
314
|
>>> model = Model("yolo11n.pt")
|
315
315
|
>>> model._check_is_pytorch_model() # No error raised
|
316
|
-
>>> model = Model("
|
316
|
+
>>> model = Model("yolo11n.onnx")
|
317
317
|
>>> model._check_is_pytorch_model() # Raises TypeError
|
318
318
|
"""
|
319
319
|
pt_str = isinstance(self.model, (str, Path)) and Path(self.model).suffix == ".pt"
|
@@ -323,7 +323,7 @@ class Model(nn.Module):
|
|
323
323
|
f"model='{self.model}' should be a *.pt PyTorch model to run this method, but is a different format. "
|
324
324
|
f"PyTorch models can train, val, predict and export, i.e. 'model.train(data=...)', but exported "
|
325
325
|
f"formats like ONNX, TensorRT etc. only support 'predict' and 'val' modes, "
|
326
|
-
f"i.e. 'yolo predict model=
|
326
|
+
f"i.e. 'yolo predict model=yolo11n.onnx'.\nTo run CUDA or MPS inference please pass the device "
|
327
327
|
f"argument directly in your inference command, i.e. 'model.predict(source=..., device=0)'"
|
328
328
|
)
|
329
329
|
|
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=yolo11n.pt source=0 # webcam
|
7
7
|
img.jpg # image
|
8
8
|
vid.mp4 # video
|
9
9
|
screen # screenshot
|
@@ -15,19 +15,21 @@ 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
|
-
|
18
|
+
$ yolo mode=predict model=yolo11n.pt # PyTorch
|
19
|
+
yolo11n.torchscript # TorchScript
|
20
|
+
yolo11n.onnx # ONNX Runtime or OpenCV DNN with dnn=True
|
21
|
+
yolo11n_openvino_model # OpenVINO
|
22
|
+
yolo11n.engine # TensorRT
|
23
|
+
yolo11n.mlpackage # CoreML (macOS-only)
|
24
|
+
yolo11n_saved_model # TensorFlow SavedModel
|
25
|
+
yolo11n.pb # TensorFlow GraphDef
|
26
|
+
yolo11n.tflite # TensorFlow Lite
|
27
|
+
yolo11n_edgetpu.tflite # TensorFlow Edge TPU
|
28
|
+
yolo11n_paddle_model # PaddlePaddle
|
29
|
+
yolo11n.mnn # MNN
|
30
|
+
yolo11n_ncnn_model # NCNN
|
31
|
+
yolo11n_imx_model # Sony IMX
|
32
|
+
yolo11n_rknn_model # Rockchip RKNN
|
31
33
|
"""
|
32
34
|
|
33
35
|
import platform
|
ultralytics/engine/results.py
CHANGED
@@ -1718,7 +1718,7 @@ class OBB(BaseTensor):
|
|
1718
1718
|
Examples:
|
1719
1719
|
>>> import torch
|
1720
1720
|
>>> from ultralytics import YOLO
|
1721
|
-
>>> model = YOLO("
|
1721
|
+
>>> model = YOLO("yolo11n-obb.pt")
|
1722
1722
|
>>> results = model("path/to/image.jpg")
|
1723
1723
|
>>> for result in results:
|
1724
1724
|
... obb = result.obb
|
ultralytics/engine/trainer.py
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
Train a model on a dataset.
|
4
4
|
|
5
5
|
Usage:
|
6
|
-
$ yolo mode=train model=
|
6
|
+
$ yolo mode=train model=yolo11n.pt data=coco8.yaml imgsz=640 epochs=100 batch=16
|
7
7
|
"""
|
8
8
|
|
9
9
|
import gc
|
@@ -128,7 +128,7 @@ class BaseTrainer:
|
|
128
128
|
self.args.workers = 0 # faster CPU training as time dominated by inference, not dataloading
|
129
129
|
|
130
130
|
# Model and Dataset
|
131
|
-
self.model = check_model_file_from_stem(self.args.model) # add suffix, i.e.
|
131
|
+
self.model = check_model_file_from_stem(self.args.model) # add suffix, i.e. yolo11n -> yolo11n.pt
|
132
132
|
with torch_distributed_zero_first(LOCAL_RANK): # avoid auto-downloading dataset multiple times
|
133
133
|
self.trainset, self.testset = self.get_dataset()
|
134
134
|
self.ema = None
|
@@ -271,7 +271,6 @@ class BaseTrainer:
|
|
271
271
|
)
|
272
272
|
if world_size > 1:
|
273
273
|
self.model = nn.parallel.DistributedDataParallel(self.model, device_ids=[RANK], find_unused_parameters=True)
|
274
|
-
self.set_model_attributes() # set again after DDP wrapper
|
275
274
|
|
276
275
|
# Check imgsz
|
277
276
|
gs = max(int(self.model.stride.max() if hasattr(self.model, "stride") else 32), 32) # grid size (max stride)
|
@@ -782,7 +781,7 @@ class BaseTrainer:
|
|
782
781
|
f"ignoring 'lr0={self.args.lr0}' and 'momentum={self.args.momentum}' and "
|
783
782
|
f"determining best 'optimizer', 'lr0' and 'momentum' automatically... "
|
784
783
|
)
|
785
|
-
nc =
|
784
|
+
nc = self.data.get("nc", 10) # number of classes
|
786
785
|
lr_fit = round(0.002 * 5 / (4 + nc), 6) # lr0 fit equation to 6 decimal places
|
787
786
|
name, lr, momentum = ("SGD", 0.01, 0.9) if iterations > 10000 else ("AdamW", lr_fit, 0.9)
|
788
787
|
self.args.warmup_bias_lr = 0.0 # no higher than 0.01 for Adam
|
ultralytics/engine/tuner.py
CHANGED
@@ -8,7 +8,7 @@ that yield the best model performance. This is particularly crucial in deep lear
|
|
8
8
|
where small changes in hyperparameters can lead to significant differences in model accuracy and efficiency.
|
9
9
|
|
10
10
|
Example:
|
11
|
-
Tune hyperparameters for
|
11
|
+
Tune hyperparameters for YOLO11n on COCO8 at imgsz=640 and epochs=30 for 300 tuning iterations.
|
12
12
|
```python
|
13
13
|
from ultralytics import YOLO
|
14
14
|
|
@@ -50,7 +50,7 @@ class Tuner:
|
|
50
50
|
Executes the hyperparameter evolution across multiple iterations.
|
51
51
|
|
52
52
|
Example:
|
53
|
-
Tune hyperparameters for
|
53
|
+
Tune hyperparameters for YOLO11n on COCO8 at imgsz=640 and epochs=30 for 300 tuning iterations.
|
54
54
|
```python
|
55
55
|
from ultralytics import YOLO
|
56
56
|
|