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 描述 |
|
| Specifies the model file for training. Accepts a path to either a 指定用于训练的模型文件。接受 |
|
| Path to the dataset configuration file (e.g., 数据集配置文件的路径(例如, |
|
| 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代表整个数据集的完整传递。调整这个值会影响训练时间和模型性能。 |
|
| Maximum training time in hours. If set, this overrides the 最大培训时间(以小时为单位)。如果设置了,这将覆盖 |
|
| 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 size, with three modes: set as an integer (e.g., 批量大小,有三种模式:设置为整数(例如 |
|
| Target image size for training. All images are resized to this dimension before being fed into the model. Affects model accuracy and computational complexity. 用于训练的目标图像大小。所有图像在输入到模型之前都会被调整到这个尺寸。影响模型精度和计算复杂度。 |
|
| Enables saving of training checkpoints and final model weights. Useful for resuming training or model deployment. 允许保存训练检查点和最终模型权重。用于恢复训练或模型部署。 |
|
| 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时禁用此特性。用于在长时间的训练期间保存临时模型。 |
|
| Enables caching of dataset images in memory ( 启用在内存( |
|
| Specifies the computational device(s) for training: a single GPU ( 指定用于训练的计算设备:单个GPU ( |
|
| Number of worker threads for data loading (per 用于数据加载的工作线程数(per |
|
| Name of the project directory where training outputs are saved. Allows for organized storage of different experiments. 保存培训输出的项目目录名称。允许有组织地存储不同的实验。 |
|
| Name of the training run. Used for creating a subdirectory within the project folder, where training logs and outputs are stored. 训练运行的名称。用于在项目文件夹中创建子目录,用于存储培训日志和输出。 |
|
| If True, allows overwriting of an existing project/name directory. Useful for iterative experimentation without needing to manually clear previous outputs. 如果为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. 确定是否从预训练的模型开始训练。可以是布尔值或到要从中加载权重的特定模型的字符串路径。提高培训效率和模型性能。 |
|
| Choice of optimizer for training. Options include 训练优化器的选择。选项包括 |
|
| Enables verbose output during training, providing detailed logs and progress updates. Useful for debugging and closely monitoring the training process. 支持训练期间的详细输出,提供详细的日志和进度更新。用于调试和密切监视培训过程。 |
|
| Sets the random seed for training, ensuring reproducibility of results across runs with the same configurations. 为训练设置随机种子,确保在相同配置的运行中结果的可重复性。 |
|
| Forces deterministic algorithm use, ensuring reproducibility but may affect performance and speed due to the restriction on non-deterministic algorithms. 强制使用确定性算法,确保再现性,但由于对非确定性算法的限制,可能会影响性能和速度。 |
|
| 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. 在训练期间将多类数据集中的所有类视为单个类。用于二元分类任务或关注对象存在而不是分类时。 |
|
| Enables rectangular training, optimizing batch composition for minimal padding. Can improve efficiency and speed but may affect model accuracy. 使矩形训练,优化批量组成最小填充。可以提高效率和速度,但可能会影响模型的准确性。 |
|
| 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。有助于管理学习率以实现更好的收敛。 |
|
| Disables mosaic data augmentation in the last N epochs to stabilize training before completion. Setting to 0 disables this feature. 在最后N次迭代中禁用马赛克数据增强,以在完成之前稳定训练。设置为0禁用此功能。 |
|
| Resumes training from the last saved checkpoint. Automatically loads model weights, optimizer state, and epoch count, continuing training seamlessly. 从上次保存的检查点恢复训练。自动加载模型权重、优化器状态和历元计数,无缝地继续训练。 |
|
| Enables Automatic Mixed Precision (AMP) training, reducing memory usage and possibly speeding up training with minimal impact on accuracy. 支持自动混合精度(AMP)训练,减少内存使用,并可能在对准确性影响最小的情况下加速训练。 |
|
| 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. 指定要用于训练的数据集的部分。允许在完整数据集的子集上进行训练,对于实验或资源有限时非常有用。 |
|
| Enables profiling of ONNX and TensorRT speeds during training, useful for optimizing model deployment. 允许在训练期间对ONNX和TensorRT速度进行分析,有助于优化模型部署。 |
|
| 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层或指定层,减少可训练参数的数量。用于微调或迁移学习。 |
|
| Initial learning rate (i.e. 最初的学习速率(即 |
|
| Final learning rate as a fraction of the initial rate = ( 最终学习率作为初始学习率的一部分= ( |
|
| Momentum factor for SGD or beta1 for Adam optimizers, influencing the incorporation of past gradients in the current update. SGD的动量因子或Adam优化器的beta1,影响当前更新中过去梯度的整合。 |
|
| L2 regularization term, penalizing large weights to prevent overfitting. L2正则化项,惩罚大权重以防止过拟合。 |
|
| 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数,从一个较低的学习率逐渐增加到初始学习率,以稳定早期的训练。 |
|
| Initial momentum for warmup phase, gradually adjusting to the set momentum over the warmup period. 热身阶段的初始动量,在热身期间逐渐调整到设定的动量。 |
|
| Learning rate for bias parameters during the warmup phase, helping stabilize model training in the initial epochs. 预热阶段偏差参数的学习率,有助于稳定初始阶段的模型训练。 |
|
| Weight of the box loss component in the loss function, influencing how much emphasis is placed on accurately predicting bounding box coordinates. 损失函数中盒损失分量的权重,影响对准确预测边界盒坐标的重视程度。 |
|
| Weight of the classification loss in the total loss function, affecting the importance of correct class prediction relative to other components. 总损失函数中分类损失的权重,影响正确分类预测相对于其他成分的重要性。 |
|
| Weight of the distribution focal loss, used in certain YOLO versions for fine-grained classification. 分布焦点损失的权重,在某些YOLO版本中用于细粒度分类。 |
|
| Weight of the pose loss in models trained for pose estimation, influencing the emphasis on accurately predicting pose keypoints. 姿态估计模型中姿态损失的权重,影响了对准确预测姿态关键点的重视。 |
|
| Weight of the keypoint objectness loss in pose estimation models, balancing detection confidence with pose accuracy. 姿态估计模型中关键点目标损失的权重,平衡检测置信度和姿态精度。 |
|
| Applies label smoothing, softening hard labels to a mix of the target label and a uniform distribution over labels, can improve generalization. 应用标签平滑,软化硬标签的混合目标标签和均匀分布的标签,可以提高泛化。 |
|
| Nominal batch size for normalization of loss. 归一化损失的标称批量大小。 |
|
| Determines whether segmentation masks should overlap during training, applicable in instance segmentation tasks. 确定在训练期间分割掩码是否应该重叠,适用于实例分割任务。 |
|
| Downsample ratio for segmentation masks, affecting the resolution of masks used during training. 分割蒙版的下采样率,影响训练时使用的蒙版的分辨率。 |
|
| Dropout rate for regularization in classification tasks, preventing overfitting by randomly omitting units during training. 分类任务中正则化的失败率,通过在训练过程中随机省略单元来防止过拟合。 |
|
| Enables validation during training, allowing for periodic evaluation of model performance on a separate dataset. 在训练期间启用验证,允许在单独的数据集上定期评估模型性能。 |
|
| Generates and saves plots of training and validation metrics, as well as prediction examples, providing visual insights into model performance and learning progression. 生成并保存训练和验证度量的图,以及预测示例,提供对模型性能和学习进展的可视化洞察。 |