yolo-tuning
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseImproving models & hyperparameter tuning
模型改进与超参数调优
The improvement playbook (follow in order — tuning is the LAST step)
改进指南(按顺序执行——调优是最后一步)
Hyperparameter tuning is expensive and usually not the bottleneck. Escalate in this
order, re-validating after each step:
- Fix the data — check and
confusion_matrix.pngfor label noise; review the top false-negative/false-positive val images; add examples of failing classes and true-background images. Data quality beats every other lever.train_batch*.jpg - Train longer — if val mAP was still rising at the end: more , higher
epochs.patience - Bigger input — small objects or mAP50 ≫ mAP50-95: raise (640 → 960/1280).
imgsz - Bigger model — underfitting (train and val both mediocre): n → s → m → l.
- Domain-matched augmentation — aerial , crowded scenes
degrees=180 flipud=0.5/copy_paste=0.3, color-critical classes lowermixup=0.1(see yolo-training'shsv_h).training-args.md - Only now: hyperparameter tuning — worth ~0.5–2 mAP when everything above is exhausted.
Decision signals: overfitting (val drops while train improves) → more data/aug or
smaller model, NOT tuning. Underfitting → bigger model/longer, NOT tuning. Label noise
in the confusion matrix → nothing else matters until fixed.
超参数调优成本高昂,通常并非性能瓶颈。请按以下顺序逐步优化,每一步后重新验证效果:
- 修复数据问题 — 查看和
confusion_matrix.png检查标签噪声;回顾验证集里排名靠前的假阴性/假阳性图像;添加识别失败类别的样本和真实背景图像。数据质量优于其他所有优化手段。train_batch*.jpg - 延长训练时长 — 如果验证集mAP在训练结束时仍呈上升趋势:增加,提高
epochs值。patience - 增大输入尺寸 — 存在小目标或mAP50远大于mAP50-95时:提升(从640调整为960/1280)。
imgsz - 更换更大模型 — 出现欠拟合(训练集和验证集表现均不佳):从n模型切换到s→m→l模型。
- 匹配领域的增强策略 — 航拍数据设置,密集场景设置
degrees=180 flipud=0.5/copy_paste=0.3,对颜色敏感的类别降低mixup=0.1值(详见yolo-training的hsv_h)。training-args.md - 最后才进行:超参数调优 — 当以上所有步骤都完成后,调优能带来约0.5–2的mAP提升。
判断信号:过拟合(训练集性能提升但验证集下降)→ 增加数据/增强或更换更小模型,而非调优。欠拟合→更换更大模型/延长训练时长,而非调优。混淆矩阵中存在标签噪声→在修复前其他优化都无效。
Compare experiments in Platform
在平台中对比实验
Keep candidates in one Platform project.
Train from the New Model dialog, or stream local runs by setting
and a unique . Select models together in the
project charts, or use Table > Diff to compare training arguments and final metrics.
project=username/project-slugnamePlatform is the experiment owner and visualization layer; the built-in genetic tuner and
Ray Tune below remain Python workflows. Use a completed Platform model as the next base
checkpoint, or download its file, after the comparison identifies a winner.
.pt将候选模型放在同一个平台项目中。通过「新建模型」对话框进行训练,或通过设置和唯一的来同步本地运行记录。在项目图表中选择多个模型进行对比,或使用「表格 > 差异」功能对比训练参数和最终指标。
project=username/project-slugname平台是实验的管理和可视化层;以下内置遗传调优器和Ray Tune仍为Python工作流。对比确定最优模型后,可将已完成的平台模型作为下一个基准检查点,或下载其文件。
.ptBuilt-in genetic tuner
内置遗传调优器
python
from ultralytics import YOLO
model = YOLO("yolo26n.pt")
model.tune(data="data.yaml", epochs=30, iterations=300, plots=False, save=False, val=False)Tuning is Python-only — there is no CLI mode (MODES are
train/val/predict/export/track/benchmark).
yolo tune- Each iteration = one full (short) training with mutated hyperparameters; fitness is read from the run's val metrics.
- Default search space: 26 keys — ,
lr0,lrf,momentum,weight_decay,warmup_epochs, loss weights (warmup_momentum,box,cls,cls_pw), all augmentation knobs (dfl,hsv_*,degrees,translate,scale,shear,perspective,flipud,fliplr,bgr,mosaic,mixup,cutmix),copy_paste.close_mosaic - Custom space (subset + ranges as ):
(min, max)pythonmodel.tune(data="data.yaml", epochs=30, iterations=100, space={"lr0": (1e-5, 1e-1), "mosaic": (0.5, 1.0)}) - Results: —
runs/<task>/tune/,best_hyperparameters.yaml, fitness plots. Load the yaml and retrain fully with it.tune_results.ndjson - Distributed tuning across machines: pass (+ optional
mongodb_uri=,mongodb_db=) — workers share one result pool via MongoDB.mongodb_collection=
python
from ultralytics import YOLO
model = YOLO("yolo26n.pt")
model.tune(data="data.yaml", epochs=30, iterations=300, plots=False, save=False, val=False)调优仅支持Python方式——没有命令行模式(命令行模式包括train/val/predict/export/track/benchmark)。
yolo tune- 每次迭代 = 使用变异超参数完成一次(短时长)完整训练;适应度从运行的验证指标中读取。
- 默认搜索空间:26个参数——、
lr0、lrf、momentum、weight_decay、warmup_epochs、损失权重(warmup_momentum、box、cls、cls_pw)、所有数据增强参数(dfl、hsv_*、degrees、translate、scale、shear、perspective、flipud、fliplr、bgr、mosaic、mixup、cutmix)、copy_paste。close_mosaic - 自定义空间(子集+范围设置为):
(min, max)pythonmodel.tune(data="data.yaml", epochs=30, iterations=100, space={"lr0": (1e-5, 1e-1), "mosaic": (0.5, 1.0)}) - 结果存储在目录下——包含
runs/<task>/tune/、best_hyperparameters.yaml、适应度图表。加载该yaml文件并使用其配置进行完整训练。tune_results.ndjson - 跨机器分布式调优:传入(可选
mongodb_uri=、mongodb_db=)——工作节点通过MongoDB共享同一个结果池。mongodb_collection=
Ray Tune (advanced search algorithms, parallel trials)
Ray Tune(高级搜索算法,并行试验)
python
model = YOLO("yolo26n.pt")
result_grid = model.tune(use_ray=True, data="data.yaml", iterations=20, epochs=30, gpu_per_trial=1)- Requires . Default scheduler is ASHA (early-kills bad trials after
pip install "ray[tune]"epochs, default 10).grace_period - accepts Ax, BOHB, Nevergrad, ZOOpt, Optuna, HyperOpt, HEBO, BayesOpt, or
search_alg=(string, or an object for Ax/BOHB/ZOOpt) instead of random search."random" - Optional W&B logging if is installed. Use Ray when you have multiple GPUs to parallelize trials or want smarter-than-genetic search; the built-in tuner is simpler and has no extra dependency.
wandb
python
model = YOLO("yolo26n.pt")
result_grid = model.tune(use_ray=True, data="data.yaml", iterations=20, epochs=30, gpu_per_trial=1)- 需要安装。默认调度器为ASHA(在
pip install "ray[tune]"轮次(默认10轮)后提前终止表现不佳的试验)。grace_period - 参数可接受Ax、BOHB、Nevergrad、ZOOpt、Optuna、HyperOpt、HEBO、BayesOpt,或
search_alg=(字符串,或Ax/BOHB/ZOOpt的对象)来替代随机搜索。"random" - 如果安装了,可选择进行W&B日志记录。当你有多块GPU用于并行试验,或需要比遗传算法更智能的搜索时使用Ray;内置调优器更简单且无额外依赖。
wandb
Evolution best practices ("autotraining" recipe)
进化调优最佳实践(「自动训练」方案)
- Search cheap, retrain expensive: tune with a small model (/
n), reduceds(~30),epochs; then retrain the best config at full size/epochs.plots=False save=False val=False - Budget: iterations × epochs × time-per-epoch. 100–300 iterations is a realistic minimum for the genetic tuner to beat defaults.
- Keep fixed during the search — changing data invalidates all prior fitness.
data - One fitness target: the tuner optimizes the task's default metric (e.g. mAP50-95(B)); confirm that matches what you actually care about before burning GPU days.
- Sanity-check the winner on the val AND test split — tuned configs can overfit the val split when iterations are high.
If the installed version rejects an argument ( shows the version), trust
the error text and over this file.
yolo checksyolo cfg- 低成本搜索,高成本重训:使用小型模型(/
n)、减少s(约30轮)、设置epochs进行调优;然后使用最优配置以全尺寸/全轮次重新训练。plots=False save=False val=False - 预算:迭代次数 × 轮次 × 每轮耗时。遗传调优器要优于默认配置,100–300次迭代是现实的最低要求。
- 搜索过程中保持固定——更改数据会使之前所有的适应度结果失效。
data - 单一适应度目标:调优器会优化任务的默认指标(例如mAP50-95(B));在消耗GPU资源前,请确认该指标与你实际关注的指标一致。
- 在验证集和测试集上 sanity-check 最优配置——当迭代次数较多时,调优后的配置可能会过拟合验证集。
如果已安装的版本不支持某个参数(可查看版本),请以错误提示和为准,而非本文档。
yolo checksyolo cfg