yoloV8-Train

from ultralytics import YOLO

# Load a model
model = YOLO("yolov8n.yaml")  # build a new model from YAML
model = YOLO("yolov8n.pt")  # load a pretrained model (recommended for training)
model = YOLO("yolov8n.yaml").load("yolov8n.pt")  # build from YAML and transfer weights

# Train the model
results = model.train(data="coco8.yaml", epochs=100, imgsz=640)

# Build a new model from YAML and start training from scratch
yolo detect train data=coco8.yaml model=yolov8n.yaml epochs=100 imgsz=640

# Start training from a pretrained *.pt model
yolo detect train data=coco8.yaml model=yolov8n.pt epochs=100 imgsz=640

# Build a new model from YAML, transfer pretrained weights to it and start training
yolo detect train data=coco8.yaml model=yolov8n.yaml pretrained=yolov8n.pt epochs=100 imgsz=640


 

Argument 论点

Default 默认的

Description 描述

model

None

Specifies the model file for training. Accepts a path to either a .pt pretrained model or a .yaml configuration file. Essential for defining the model structure or initializing weights.

指定用于训练的模型文件。接受 .pt 预训练模型或 .yaml 配置文件的路径。对于定义模型结构或初始化权重至关重要。

data

None

Path to the dataset configuration file (e.g., coco8.yaml). This file contains dataset-specific parameters, including paths to training and validation data, class names, and number of classes.

数据集配置文件的路径(例如, coco8.yaml )。该文件包含特定于数据集的参数,包括到训练和验证数据的路径、类名和类数。

epochs

100

Total number of training epochs. Each epoch represents a full pass over the entire dataset. Adjusting this value can affect training duration and model performance.

训练周期总数。每个epoch代表整个数据集的完整传递。调整这个值会影响训练时间和模型性能。

time

None

Maximum training time in hours. If set, this overrides the epochs argument, allowing training to automatically stop after the specified duration. Useful for time-constrained training scenarios.

最大培训时间(以小时为单位)。如果设置了,这将覆盖 epochs 参数,允许训练在指定的持续时间后自动停止。对于时间限制的训练场景非常有用。

patience

100

Number of epochs to wait without improvement in validation metrics before early stopping the training. Helps prevent overfitting by stopping training when performance plateaus.

在早期停止训练之前,在验证度量没有改进的情况下等待的epoch数。当表现停滞时,停止训练有助于防止过度拟合。

batch

16

Batch size, with three modes: set as an integer (e.g., batch=16), auto mode for 60% GPU memory utilization (batch=-1), or auto mode with specified utilization fraction (batch=0.70).

批量大小,有三种模式:设置为整数(例如 batch=16 ),自动模式为60%的GPU内存利用率( batch=-1 ),或自动模式为指定的利用率分数( batch=0.70 )。

imgsz

640

Target image size for training. All images are resized to this dimension before being fed into the model. Affects model accuracy and computational complexity.

用于训练的目标图像大小。所有图像在输入到模型之前都会被调整到这个尺寸。影响模型精度和计算复杂度。

save

True

Enables saving of training checkpoints and final model weights. Useful for resuming training or model deployment.

允许保存训练检查点和最终模型权重。用于恢复训练或模型部署。

save_period

-1

Frequency of saving model checkpoints, specified in epochs. A value of -1 disables this feature. Useful for saving interim models during long training sessions.

保存模型检查点的频率,以epoch指定。值为-1时禁用此特性。用于在长时间的训练期间保存临时模型。

cache

False

Enables caching of dataset images in memory (True/ram), on disk (disk), or disables it (False). Improves training speed by reducing disk I/O at the cost of increased memory usage.

启用在内存( True / ram )、磁盘( disk )或禁用( False )中缓存数据集图像。以增加内存使用为代价,通过减少磁盘I/O来提高训练速度。

device

None

Specifies the computational device(s) for training: a single GPU (device=0), multiple GPUs (device=0,1), CPU (device=cpu), or MPS for Apple silicon (device=mps).

指定用于训练的计算设备:单个GPU ( device=0 ),多个GPU ( device=0,1 ), CPU ( device=cpu ),或用于Apple芯片的MPS ( device=mps )。

workers

8

Number of worker threads for data loading (per RANK if Multi-GPU training). Influences the speed of data preprocessing and feeding into the model, especially useful in multi-GPU setups.

用于数据加载的工作线程数(per RANK 如果是多gpu训练)。影响数据预处理和输入模型的速度,在多gpu设置中特别有用。

project

None

Name of the project directory where training outputs are saved. Allows for organized storage of different experiments.

保存培训输出的项目目录名称。允许有组织地存储不同的实验。

name

None

Name of the training run. Used for creating a subdirectory within the project folder, where training logs and outputs are stored.

训练运行的名称。用于在项目文件夹中创建子目录,用于存储培训日志和输出。

exist_ok

False

If True, allows overwriting of an existing project/name directory. Useful for iterative experimentation without needing to manually clear previous outputs.

如果为True,则允许覆盖现有的项目/名称目录。可用于迭代实验,无需手动清除先前的输出。

pretrained

True

Determines whether to start training from a pretrained model. Can be a boolean value or a string path to a specific model from which to load weights. Enhances training efficiency and model performance.

确定是否从预训练的模型开始训练。可以是布尔值或到要从中加载权重的特定模型的字符串路径。提高培训效率和模型性能。

optimizer

'auto'

Choice of optimizer for training. Options include SGD, Adam, AdamW, NAdam, RAdam, RMSProp etc., or auto for automatic selection based on model configuration. Affects convergence speed and stability.

训练优化器的选择。选项包括 SGDAdamAdamWNAdamRAdamRMSProp 等,或者根据型号配置自动选择 auto 。影响收敛速度和稳定性。

verbose

False

Enables verbose output during training, providing detailed logs and progress updates. Useful for debugging and closely monitoring the training process.

支持训练期间的详细输出,提供详细的日志和进度更新。用于调试和密切监视培训过程。

seed

0

Sets the random seed for training, ensuring reproducibility of results across runs with the same configurations.

为训练设置随机种子,确保在相同配置的运行中结果的可重复性。

deterministic

True

Forces deterministic algorithm use, ensuring reproducibility but may affect performance and speed due to the restriction on non-deterministic algorithms.

强制使用确定性算法,确保再现性,但由于对非确定性算法的限制,可能会影响性能和速度。

single_cls

False

Treats all classes in multi-class datasets as a single class during training. Useful for binary classification tasks or when focusing on object presence rather than classification.

在训练期间将多类数据集中的所有类视为单个类。用于二元分类任务或关注对象存在而不是分类时。

rect

False

Enables rectangular training, optimizing batch composition for minimal padding. Can improve efficiency and speed but may affect model accuracy.

使矩形训练,优化批量组成最小填充。可以提高效率和速度,但可能会影响模型的准确性。

cos_lr

False

Utilizes a cosine learning rate scheduler, adjusting the learning rate following a cosine curve over epochs. Helps in managing learning rate for better convergence.

利用余弦学习率调度程序,调整学习率后,余弦曲线的epoch。有助于管理学习率以实现更好的收敛。

close_mosaic

10

Disables mosaic data augmentation in the last N epochs to stabilize training before completion. Setting to 0 disables this feature.

在最后N次迭代中禁用马赛克数据增强,以在完成之前稳定训练。设置为0禁用此功能。

resume

False

Resumes training from the last saved checkpoint. Automatically loads model weights, optimizer state, and epoch count, continuing training seamlessly.

从上次保存的检查点恢复训练。自动加载模型权重、优化器状态和历元计数,无缝地继续训练。

amp

True

Enables Automatic Mixed Precision (AMP) training, reducing memory usage and possibly speeding up training with minimal impact on accuracy.

支持自动混合精度(AMP)训练,减少内存使用,并可能在对准确性影响最小的情况下加速训练。

fraction

1.0

Specifies the fraction of the dataset to use for training. Allows for training on a subset of the full dataset, useful for experiments or when resources are limited.

指定要用于训练的数据集的部分。允许在完整数据集的子集上进行训练,对于实验或资源有限时非常有用。

profile

False

Enables profiling of ONNX and TensorRT speeds during training, useful for optimizing model deployment.

允许在训练期间对ONNX和TensorRT速度进行分析,有助于优化模型部署。

freeze

None

Freezes the first N layers of the model or specified layers by index, reducing the number of trainable parameters. Useful for fine-tuning or transfer learning.

通过索引冻结模型的前N层或指定层,减少可训练参数的数量。用于微调或迁移学习。

lr0

0.01

Initial learning rate (i.e. SGD=1E-2, Adam=1E-3) . Adjusting this value is crucial for the optimization process, influencing how rapidly model weights are updated.

最初的学习速率(即 SGD=1E-2 , Adam=1E-3 )。调整此值对于优化过程至关重要,它会影响模型权重更新的速度。

lrf

0.01

Final learning rate as a fraction of the initial rate = (lr0 * lrf), used in conjunction with schedulers to adjust the learning rate over time.

最终学习率作为初始学习率的一部分= ( lr0 * lrf ),与调度器一起使用以随时间调整学习率。

momentum

0.937

Momentum factor for SGD or beta1 for Adam optimizers, influencing the incorporation of past gradients in the current update.

SGD的动量因子或Adam优化器的beta1,影响当前更新中过去梯度的整合。

weight_decay

0.0005

L2 regularization term, penalizing large weights to prevent overfitting.

L2正则化项,惩罚大权重以防止过拟合。

warmup_epochs

3.0

Number of epochs for learning rate warmup, gradually increasing the learning rate from a low value to the initial learning rate to stabilize training early on.

学习率预热的epoch数,从一个较低的学习率逐渐增加到初始学习率,以稳定早期的训练。

warmup_momentum

0.8

Initial momentum for warmup phase, gradually adjusting to the set momentum over the warmup period.

热身阶段的初始动量,在热身期间逐渐调整到设定的动量。

warmup_bias_lr

0.1

Learning rate for bias parameters during the warmup phase, helping stabilize model training in the initial epochs.

预热阶段偏差参数的学习率,有助于稳定初始阶段的模型训练。

box

7.5

Weight of the box loss component in the loss function, influencing how much emphasis is placed on accurately predicting bounding box coordinates.

损失函数中盒损失分量的权重,影响对准确预测边界盒坐标的重视程度。

cls

0.5

Weight of the classification loss in the total loss function, affecting the importance of correct class prediction relative to other components.

总损失函数中分类损失的权重,影响正确分类预测相对于其他成分的重要性。

dfl

1.5

Weight of the distribution focal loss, used in certain YOLO versions for fine-grained classification.

分布焦点损失的权重,在某些YOLO版本中用于细粒度分类。

pose

12.0

Weight of the pose loss in models trained for pose estimation, influencing the emphasis on accurately predicting pose keypoints.

姿态估计模型中姿态损失的权重,影响了对准确预测姿态关键点的重视。

kobj

2.0

Weight of the keypoint objectness loss in pose estimation models, balancing detection confidence with pose accuracy.

姿态估计模型中关键点目标损失的权重,平衡检测置信度和姿态精度。

label_smoothing

0.0

Applies label smoothing, softening hard labels to a mix of the target label and a uniform distribution over labels, can improve generalization.

应用标签平滑,软化硬标签的混合目标标签和均匀分布的标签,可以提高泛化。

nbs

64

Nominal batch size for normalization of loss.

归一化损失的标称批量大小。

overlap_mask

True

Determines whether segmentation masks should overlap during training, applicable in instance segmentation tasks.

确定在训练期间分割掩码是否应该重叠,适用于实例分割任务。

mask_ratio

4

Downsample ratio for segmentation masks, affecting the resolution of masks used during training.

分割蒙版的下采样率,影响训练时使用的蒙版的分辨率。

dropout

0.0

Dropout rate for regularization in classification tasks, preventing overfitting by randomly omitting units during training.

分类任务中正则化的失败率,通过在训练过程中随机省略单元来防止过拟合。

val

True

Enables validation during training, allowing for periodic evaluation of model performance on a separate dataset.

在训练期间启用验证,允许在单独的数据集上定期评估模型性能。

plots

False

Generates and saves plots of training and validation metrics, as well as prediction examples, providing visual insights into model performance and learning progression.

生成并保存训练和验证度量的图,以及预测示例,提供对模型性能和学习进展的可视化洞察。

  • 10
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值