commentsdescriptionkeywords 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 the TASK from the model type.MODE (required) is one of [train, val, predict, export, track, benchmark]ARGS (optional) are any number of custom arg=value pairs like imgsz=320 that override defaults.

一、Tasks

YOLO 模型可用于各种任务,包括检测、分割、分类和姿势。 这些任务的不同之处在于它们产生的输出类型以及它们旨在解决的具体问题。

检测:用于识别和定位图像或视频中感兴趣的对象或区域。

分段:用于将图像或视频划分为对应于不同对象或类别的区域或像素。

分类:用于预测输入图像的类标签。

姿势:用于识别图像或视频中的对象并估计其关键点。

KeyValueDescriptiontask'detect'YOLO task, i.e. detect, segment, classify, pose

二、Modes

YOLO 模型可以根据您要解决的具体问题以不同的模式使用。

这些模式包括:

训练:用于在自定义数据集上训练 YOLOv8 模型。

Val:用于在训练后验证 YOLOv8 模型。

预测:使用经过训练的 YOLOv8 模型对新图像或视频进行预测。

导出:用于将 YOLOv8 模型导出为可用于部署的格式。

Track:用于使用 YOLOv8 模型实时跟踪对象。

基准:用于对 YOLOv8 导出(ONNX、TensorRT 等)速度和准确性进行基准测试。

KeyValueDescriptionmode'train'YOLO mode, i.e. train, val, predict, export, track, benchmark

三、Train

YOLO 模型的训练设置包含训练过程中使用的各种超参数和配置。 这些设置会影响模型的性能、速度和准确性。

关键的训练设置包括批量大小、学习率、动量和权重衰减。 此外,优化器、损失函数和训练数据集组成的选择也会影响训练过程。 仔细调整和试验这些设置对于优化性能至关重要。

KeyValueDescriptionmodelNonepath to model file, i.e. yolov8n.pt, yolov8n.yamldataNonepath to data file, i.e. coco128.yamlepochs100number of epochs to train forpatience50epochs to wait for no observable improvement for early stopping of trainingbatch16number of images per batch (-1 for AutoBatch)imgsz640size of input images as integer or w,hsaveTruesave train checkpoints and predict resultssave_period-1Save checkpoint every x epochs (disabled if < 1)cacheFalseTrue/ram, disk or False. Use cache for data loadingdeviceNonedevice to run on, i.e. cuda device=0 or device=0,1,2,3 or device=cpuworkers8number of worker threads for data loading (per RANK if DDP)projectNoneproject namenameNoneexperiment nameexist_okFalsewhether to overwrite existing experimentpretrainedTrue(bool or str) whether to use a pretrained model (bool) or a model to load weights from (str)optimizer'auto'optimizer to use, choices=[SGD, Adam, Adamax, AdamW, NAdam, RAdam, RMSProp, auto]verboseFalsewhether to print verbose outputseed0random seed for reproducibilitydeterministicTruewhether to enable deterministic modesingle_clsFalsetrain multi-class data as single-classrectFalserectangular training with each batch collated for minimum paddingcos_lrFalseuse cosine learning rate schedulerclose_mosaic10(int) disable mosaic augmentation for final epochs (0 to disable)resumeFalseresume training from last checkpointampTrueAutomatic Mixed Precision (AMP) training, choices=[True, False]fraction1.0dataset fraction to train on (default is 1.0, all images in train set)profileFalseprofile ONNX and TensorRT speeds during training for loggersfreezeNone(int or list, optional) freeze first n layers, or freeze list of layer indices during traininglr00.01initial learning rate (i.e. SGD=1E-2, Adam=1E-3)lrf0.01final learning rate (lr0 * lrf)momentum0.937SGD momentum/Adam beta1weight_decay0.0005optimizer weight decay 5e-4warmup_epochs3.0warmup epochs (fractions ok)warmup_momentum0.8warmup initial momentumwarmup_bias_lr0.1warmup initial bias lrbox7.5box loss gaincls0.5cls loss gain (scale with pixels)dfl1.5dfl loss gainpose12.0pose loss gain (pose-only)kobj2.0keypoint obj loss gain (pose-only)label_smoothing0.0label smoothing (fraction)nbs64nominal batch sizeoverlap_maskTruemasks should overlap during training (segment train only)mask_ratio4mask downsample ratio (segment train only)dropout0.0use dropout regularization (classify train only)valTruevalidate/test during training

四、Predict

YOLO 模型的预测设置包含一系列超参数和配置,这些超参数和配置会影响模型在推理新数据期间的性能、速度和准确性。 仔细调整和试验这些设置对于实现特定任务的最佳性能至关重要。 关键设置包括置信度阈值、非极大值抑制 (NMS) 阈值和考虑的类别数量。 影响预测过程的其他因素包括输入数据的大小和格式、是否存在补充特征(例如每个框的掩码或多个标签)以及模型所执行的特定任务。

KeyValueDescriptionsource'ultralytics/assets'source directory for images or videosconf0.25object confidence threshold for detectioniou0.7intersection over union (IoU) threshold for NMShalfFalseuse half precision (FP16)deviceNonedevice to run on, i.e. cuda device=0/1/2/3 or device=cpushowFalseshow results if possiblesaveFalsesave images with resultssave_txtFalsesave results as .txt filesave_confFalsesave results with confidence scoressave_cropFalsesave cropped images with resultsshow_labelsTrueshow object labels in plotsshow_confTrueshow object confidence scores in plotsmax_det300maximum number of detections per imagevid_strideFalsevideo frame-rate stridestream_bufferboolbuffer all streaming frames (True) or return the most recent frame (False)line_widthNoneThe line width of the bounding boxes. If None, it is scaled to the image size.visualizeFalsevisualize model featuresaugmentFalseapply image augmentation to prediction sourcesagnostic_nmsFalseclass-agnostic NMSretina_masksFalseuse high-resolution segmentation masksclassesNonefilter results by class, i.e. classes=0, or classes=[0,2,3]boxesTrueShow boxes in segmentation predictions

五、Val

YOLO 模型的 val(验证)设置涉及各种超参数和配置,用于评估模型在验证数据集上的性能。 这些设置会影响模型的性能、速度和准确性。 常见的 YOLO 验证设置包括批量大小、训练期间的验证频率以及性能评估指标。 影响验证过程的其他因素包括验证数据集的大小和组成,以及模型所用于的特定任务。 对这些设置进行仔细调整和实验对于确保验证数据集的最佳性能以及检测和防止过度拟合至关重要。

KeyValueDescriptionsave_jsonFalsesave results to JSON filesave_hybridFalsesave hybrid version of labels (labels + additional predictions)conf0.001object confidence threshold for detectioniou0.6intersection over union (IoU) threshold for NMSmax_det300maximum number of detections per imagehalfTrueuse half precision (FP16)deviceNonedevice to run on, i.e. cuda device=0/1/2/3 or device=cpudnnFalseuse OpenCV DNN for ONNX inferenceplotsFalseshow plots during trainingrectFalserectangular val with each batch collated for minimum paddingsplitvaldataset split to use for validation, i.e. 'val', 'test' or 'train'

六、Export

YOLO 模型的导出设置包含与保存或导出模型以在不同环境或平台中使用相关的配置和选项。 这些设置可能会影响模型的性能、大小以及与各种系统的兼容性。 关键导出设置包括导出的模型文件格式(例如 ONNX、TensorFlow SavedModel)、目标设备(例如 CPU、GPU)以及其他功能,例如掩模或每个框多个标签。 导出过程还可能受到模型的特定任务以及目标环境或平台的要求或约束的影响。 仔细配置这些设置以确保导出的模型针对预期用例进行优化并在目标环境中有效运行至关重要。

KeyValueDescriptionformat'torchscript'format to export toimgsz640image size as scalar or (h, w) list, i.e. (640, 480)kerasFalseuse Keras for TF SavedModel exportoptimizeFalseTorchScript: optimize for mobilehalfFalseFP16 quantizationint8FalseINT8 quantizationdynamicFalseONNX/TF/TensorRT: dynamic axessimplifyFalseONNX: simplify modelopsetNoneONNX: opset version (optional, defaults to latest)workspace4TensorRT: workspace size (GB)nmsFalseCoreML: add NMS

七、Augmentation

YOLO 模型的增强设置是指应用于训练数据的各种转换和修改,以增加数据集的多样性和大小。 这些设置会影响模型的性能、速度和准确性。 一些常见的 YOLO 增强设置包括所应用的变换的类型和强度(例如随机翻转、旋转、裁剪、颜色变化)、应用每个变换的概率以及是否存在附加功能,例如每个框的掩模或多个标签 。 可能影响增强过程的其他因素包括原始数据集的大小和组成以及模型所用于的特定任务。 仔细调整和试验这些设置非常重要,以确保增强数据集具有足够的多样性和代表性,足以训练高性能模型。

KeyValueDescriptionhsv_h0.015image HSV-Hue augmentation (fraction)hsv_s0.7image HSV-Saturation augmentation (fraction)hsv_v0.4image HSV-Value augmentation (fraction)degrees0.0image rotation (+/- deg)translate0.1image translation (+/- fraction)scale0.5image scale (+/- gain)shear0.0image shear (+/- deg)perspective0.0image perspective (+/- fraction), range 0-0.001flipud0.0image flip up-down (probability)fliplr0.5image flip left-right (probability)mosaic1.0image mosaic (probability)mixup0.0image mixup (probability)copy_paste0.0segment copy-paste (probability)

八、Logging, checkpoints, plotting and file management

训练 YOLO 模型时,日志记录、检查点、绘图和文件管理是重要的考虑因素。

日志记录:在训练期间记录各种指标和统计数据通常很有帮助,以跟踪模型的进度并诊断可能出现的任何问题。 这可以使用 TensorBoard 等日志库或通过将日志消息写入文件来完成。

检查点:在训练期间定期保存模型的检查点是一个很好的做法。 如果训练过程中断或者您想尝试不同的训练配置,您可以从之前的点恢复训练。

绘图:可视化模型的性能和训练进度有助于理解模型的行为方式并识别潜在问题。 这可以使用 matplotlib 等绘图库或使用 TensorBoard 等日志记录库生成绘图来完成。

文件管理:管理训练过程中生成的各种文件(例如模型检查点、日志文件和绘图)可能具有挑战性。 拥有清晰且有组织的文件结构来跟踪这些文件并使其易于根据需要访问和分析它们非常重要。

有效的日志记录、检查点、绘图和文件管理可以帮助您跟踪模型的进度,并更轻松地调试和优化训练过程。

KeyValueDescriptionproject'runs'project namename'exp'experiment name. exp gets automatically incremented if not specified, i.e, exp, exp2 ...exist_okFalsewhether to overwrite existing experimentplotsFalsesave plots during train/valsaveFalsesave train checkpoints and predict results

精彩内容

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: