comments |
description |
keywords |
true |
Master YOLOv8 settings and hyperparameters for improved model performance. Learn to use YOLO CLI commands, adjust training settings, and optimize YOLO tasks & modes. |
YOLOv8, settings, hyperparameters, YOLO CLI commands, YOLO tasks, YOLO modes, Ultralytics documentation, model optimization, YOLOv8 training |
YOLO 设置和超参数对模型的性能、速度和准确性起着至关重要的作用。 这些设置和超参数可以影响模型开发过程各个阶段的模型行为,包括训练、验证和预测。
YOLOv8 yolo CLI 命令使用以下语法:
=== "CLI"
```bash
yolo TASK MODE ARGS
```
=== "Python"
```python
from ultralytics import YOLO
# Load a YOLOv8 model from a pre-trained weights file
model = YOLO('yolov8n.pt')
# Run MODE mode using the custom arguments ARGS (guess TASK)
model.MODE(ARGS)
```
Where:
TASK
(optional) is one of[detect, segment, classify, pose]
. If it is not passed explicitly YOLOv8 will try to guess theTASK
from the model type.MODE
(required) is one of[train, val, predict, export, track, benchmark]
ARGS
(optional) are any number of customarg=value
pairs likeimgsz=320
that override defaults.
Tasks
YOLO 模型可用于各种任务,包括检测、分割、分类和姿势。 这些任务的不同之处在于它们产生的输出类型以及它们旨在解决的具体问题。
检测:用于识别和定位图像或视频中感兴趣的对象或区域。
分割:用于将图像或视频划分为对应于不同对象或类别的区域或像素。
分类:用于预测输入图像的类标签。 姿势:用于识别图像或视频中的对象并估计其关键点。
Key |
Value |
Description |
|
|
YOLO task, i.e. detect, segment, classify, pose |
Modes
YOLO 模型可以根据您要解决的具体问题以不同的模式使用。
这些模式包括:
训练:用于在自定义数据集上训练 YOLOv8 模型。
Val:用于在训练后验证 YOLOv8 模型。
预测:使用经过训练的 YOLOv8 模型对新图像或视频进行预测。
导出:用于将 YOLOv8 模型导出为可用于部署的格式。
Track:用于使用 YOLOv8 模型实时跟踪对象。
基准:用于对 YOLOv8 导出(ONNX、TensorRT 等)速度和准确性进行基准测试。
Key |
Value |
Description |
|
|
YOLO mode, i.e. train, val, predict, export, track, benchmark |
Train
YOLO 模型的训练设置包含训练过程中使用的各种超参数和配置。 这些设置会影响模型的性能、速度和准确性。 关键的训练设置包括批量大小、学习率、动量和权重衰减。 此外,优化器、损失函数和训练数据集组成的选择也会影响训练过程。 仔细调整和试验这些设置对于优化性能至关重要。
Key |
Value |
Description |
|
|
path to model file, i.e. yolov8n.pt, yolov8n.yaml |
|
|
path to data file, i.e. coco128.yaml |
|
|
number of epochs to train for |
|
|
epochs to wait for no observable improvement for early stopping of training |
|
|
number of images per batch (-1 for AutoBatch) |
|
|
size of input images as integer or w,h |
|
|
save train checkpoints and predict results |
|
|
Save checkpoint every x epochs (disabled if < 1) |
|
|
True/ram, disk or False. Use cache for data loading |
|
|
device to run on, i.e. cuda device=0 or device=0,1,2,3 or device=cpu |
|
|
number of worker threads for data loading (per RANK if DDP) |
|
|
project name |
|
|
experiment name |
|
|
whether to overwrite existing experiment |
|
|
(bool or str) whether to use a pretrained model (bool) or a model to load weights from (str) |
|
|
optimizer to use, choices=[SGD, Adam, Adamax, AdamW, NAdam, RAdam, RMSProp, auto] |
|
|
whether to print verbose output |
|
|
random seed for reproducibility |
|
|
whether to enable deterministic mode |
|
|
train multi-class data as single-class |
|
|
rectangular training with each batch collated for minimum padding |
|
|
use cosine learning rate scheduler |
|
|
(int) disable mosaic augmentation for final epochs (0 to disable) |
|
|
resume training from last checkpoint |
|
|
Automatic Mixed Precision (AMP) training, choices=[True, False] |
|
|
dataset fraction to train on (default is 1.0, all images in train set) |
|
|
profile ONNX and TensorRT speeds during training for loggers |
|
|
(int or list, optional) freeze first n layers, or freeze list of layer indices during training |
|
|
initial learning rate (i.e. SGD=1E-2, Adam=1E-3) |
|
|
final learning rate (lr0 * lrf) |
|
|
SGD momentum/Adam beta1 |
|
|
optimizer weight decay 5e-4 |
|
|
warmup epochs (fractions ok) |
|
|
warmup initial momentum |
|
|
warmup initial bias lr |
|
|
box loss gain |
|
|
cls loss gain (scale with pixels) |
|
|
dfl loss gain |
|
|
pose loss gain (pose-only) |
|
|
keypoint obj loss gain (pose-only) |
|
|
label smoothing (fraction) |
|
|
nominal batch size |
|
|
masks should overlap during training (segment train only) |
|
|
mask downsample ratio (segment train only) |
|
|
use dropout regularization (classify train only) |
|
|
validate/test during training |
Predict
YOLO 模型的预测设置包含一系列超参数和配置,这些超参数和配置会影响模型在推理新数据期间的性能、速度和准确性。 仔细调整和试验这些设置对于实现特定任务的最佳性能至关重要。 关键设置包括置信度阈值、非极大值抑制 (NMS) 阈值和考虑的类别数量。 影响预测过程的其他因素包括输入数据的大小和格式、是否存在补充特征(例如每个框的掩码或多个标签)以及模型所执行的特定任务。
Key |
Value |
Description |
|
|
source directory for images or videos |
|
|
object confidence threshold for detection |
|
|
intersection over union (IoU) threshold for NMS |
|
|
use half precision (FP16) |
|
|
device to run on, i.e. cuda device=0/1/2/3 or device=cpu |
|
|
show results if possible |
|
|
save images with results |
|
|
save results as .txt file |
|
|
save results with confidence scores |
|
|
save cropped images with results |
|
|
show object labels in plots |
|
|
show object confidence scores in plots |
|
|
maximum number of detections per image |
|
|
video frame-rate stride |
|
|
buffer all streaming frames (True) or return the most recent frame (False) |
|
|
The line width of the bounding boxes. If None, it is scaled to the image size. |
|
|
visualize model features |
|
|
apply image augmentation to prediction sources |
|
|
class-agnostic NMS |
|
|
use high-resolution segmentation masks |
|
|
filter results by class, i.e. classes=0, or classes=[0,2,3] |
|
|
Show boxes in segmentation predictions |
Val
YOLO 模型的 val(验证)设置涉及各种超参数和配置,用于评估模型在验证数据集上的性能。 这些设置会影响模型的性能、速度和准确性。 常见的 YOLO 验证设置包括批量大小、训练期间的验证频率以及性能评估指标。 影响验证过程的其他因素包括验证数据集的大小和组成,以及模型所用于的特定任务。 对这些设置进行仔细调整和实验对于确保验证数据集的最佳性能以及检测和防止过度拟合至关重要。
Key |
Value |
Description |
|
|
save results to JSON file |
|
|
save hybrid version of labels (labels + additional predictions) |
|
|
object confidence threshold for detection |
|
|
intersection over union (IoU) threshold for NMS |
|
|
maximum number of detections per image |
|
|
use half precision (FP16) |
|
|
device to run on, i.e. cuda device=0/1/2/3 or device=cpu |
|
|
use OpenCV DNN for ONNX inference |
|
|
show plots during training |
|
|
rectangular val with each batch collated for minimum padding |
|
|
dataset split to use for validation, i.e. 'val', 'test' or 'train' |
Export
YOLO 模型的导出设置包含与保存或导出模型以在不同环境或平台中使用相关的配置和选项。 这些设置可能会影响模型的性能、大小以及与各种系统的兼容性。 关键导出设置包括导出的模型文件格式(例如 ONNX、TensorFlow SavedModel)、目标设备(例如 CPU、GPU)以及其他功能,例如掩模或每个框多个标签。 导出过程还可能受到模型的特定任务以及目标环境或平台的要求或约束的影响。 仔细配置这些设置以确保导出的模型针对预期用例进行优化并在目标环境中有效运行至关重要。
Key |
Value |
Description |
|
|
format to export to |
|
|
image size as scalar or (h, w) list, i.e. (640, 480) |
|
|
use Keras for TF SavedModel export |
|
|
TorchScript: optimize for mobile |
|
|
FP16 quantization |
|
|
INT8 quantization |
|
|
ONNX/TF/TensorRT: dynamic axes |
|
|
ONNX: simplify model |
|
|
ONNX: opset version (optional, defaults to latest) |
|
|
TensorRT: workspace size (GB) |
|
|
CoreML: add NMS |
Augmentation
YOLO 模型的增强设置是指应用于训练数据的各种转换和修改,以增加数据集的多样性和大小。 这些设置会影响模型的性能、速度和准确性。 一些常见的 YOLO 增强设置包括所应用的变换的类型和强度(例如随机翻转、旋转、裁剪、颜色变化)、应用每个变换的概率以及是否存在附加功能,例如每个框的掩模或多个标签 。 可能影响增强过程的其他因素包括原始数据集的大小和组成以及模型所用于的特定任务。 仔细调整和试验这些设置非常重要,以确保增强数据集具有足够的多样性和代表性,足以训练高性能模型。
Key |
Value |
Description |
|
|
image HSV-Hue augmentation (fraction) |
|
|
image HSV-Saturation augmentation (fraction) |
|
|
image HSV-Value augmentation (fraction) |
|
|
image rotation (+/- deg) |
|
|
image translation (+/- fraction) |
|
|
image scale (+/- gain) |
|
|
image shear (+/- deg) |
|
|
image perspective (+/- fraction), range 0-0.001 |
|
|
image flip up-down (probability) |
|
|
image flip left-right (probability) |
|
|
image mosaic (probability) |
|
|
image mixup (probability) |
|
|
segment copy-paste (probability) |
Logging, checkpoints, plotting and file management
训练 YOLO 模型时,日志记录、检查点、绘图和文件管理是重要的考虑因素。
日志记录:在训练期间记录各种指标和统计数据通常很有帮助,以跟踪模型的进度并诊断可能出现的任何问题。 这可以使用 TensorBoard 等日志库或通过将日志消息写入文件来完成。
检查点:在训练期间定期保存模型的检查点是一个很好的做法。 如果训练过程中断或者您想尝试不同的训练配置,您可以从之前的点恢复训练。
绘图:可视化模型的性能和训练进度有助于理解模型的行为方式并识别潜在问题。 这可以使用 matplotlib 等绘图库或使用 TensorBoard 等日志记录库生成绘图来完成。
文件管理:管理训练过程中生成的各种文件(例如模型检查点、日志文件和绘图)可能具有挑战性。 拥有清晰且有组织的文件结构来跟踪这些文件并使其易于根据需要访问和分析它们非常重要。
有效的日志记录、检查点、绘图和文件管理可以帮助您跟踪模型的进度,并更轻松地调试和优化训练过程。
Key |
Value |
Description |
|
|
project name |
|
|
experiment name. |
|
|
whether to overwrite existing experiment |
|
|
save plots during train/val |
|
|
save train checkpoints and predict results |