Configuration
YOLO settings and hyperparameters play a critical role in the model's performance, speed, and accuracy. These settings can affect the model's behavior at various stages, including training, validation, and prediction.
Watch: Mastering Ultralytics YOLO: Configuration
Watch: Mastering Ultralytics YOLO: Configuration
Ultralytics commands use the following syntax:
Example
Where:
TASK
(optional) is one of (detect, segment, classify, pose, obb)MODE
(required) is one of (train, val, predict, export, track, benchmark)ARGS
(optional) arearg=value
pairs likeimgsz=640
that override defaults.
Default ARG
values are defined on this page and come from the cfg/defaults.yaml
file.
Tasks
Ultralytics YOLO models can perform a variety of computer vision tasks, including:
- Detect: Object detection identifies and localizes objects within an image or video.
- Segment: Instance segmentation divides an image or video into regions corresponding to different objects or classes.
- Classify: Image classification predicts the class label of an input image.
- Pose: Pose estimation identifies objects and estimates their keypoints in an image or video.
- OBB: Oriented Bounding Boxes uses rotated bounding boxes, suitable for satellite or medical imagery.
Argument | Default | Description |
---|---|---|
task |
'detect' |
Specifies the YOLO task: detect for object detection, segment for segmentation, classify for classification, pose for pose estimation, and obb for oriented bounding boxes. Each task is tailored to specific outputs and problems in image and video analysis. |
Modes
Ultralytics YOLO models operate in different modes, each designed for a specific stage of the model lifecycle:
- Train: Train a YOLO model on a custom dataset.
- Val: Validate a trained YOLO model.
- Predict: Use a trained YOLO model to make predictions on new images or videos.
- Export: Export a YOLO model for deployment.
- Track: Track objects in real-time using a YOLO model.
- Benchmark: Benchmark the speed and accuracy of YOLO exports (ONNX, TensorRT, etc.).
Argument | Default | Description |
---|---|---|
mode |
'train' |
Specifies the YOLO model's operating mode: train for model training, val for validation, predict for inference, export for converting to deployment formats, track for object tracking, and benchmark for performance evaluation. Each mode supports different stages, from development to deployment. |
Train Settings
Training settings for YOLO models include hyperparameters and configurations that affect the model's performance, speed, and accuracy. Key settings include batch size, learning rate, momentum, and weight decay. The choice of optimizer, loss function, and dataset composition also impact training. Tuning and experimentation are crucial for optimal performance. For more details, see the Ultralytics entrypoint function.
参数 | 类型 | 默认值 | 描述 |
---|---|---|---|
model |
str |
None |
指定用于训练的模型文件。接受一个路径,可以是.pt I need to translate the phrase "pretrained model or a" into Simplified Chinese while maintaining the original format. |
预训练模型或一个.yaml
配置文件。对于定义模型结构或初始化权重至关重要。
| data
| str
| None
I notice that the content you've provided appears to be incomplete. It seems to be a fragment of a sentence or instruction about a path to a dataset configuration file, but it cuts off after "e.g.,".
Would you like me to translate this fragment into Simplified Chinese, or would you prefer to provide the complete text for translation?coco8.yaml
这个文件包含特定于数据集的参数,包括训练路径和validation dataI need to translate the given text fragment to Simplified Chinese while preserving its format and meaning.
,类名和类的数量。 |
| epochs
| int
| 100
I'll translate the provided content into Simplified Chinese while maintaining the original format:
| 训练的总轮数。每个[epoch](https://www.ultralytics.com/glossary/epoch)表示对整个数据集的一次完整遍历。调整这个值可能会影响训练时间和模型性能。
| time
| float
| None
| 最大训练时间(小时)。如果设置,这将覆盖epochs
参数,允许训练在指定的持续时间后自动停止。适用于时间受限的训练场景。
| patience
| int
| 100
| 在验证指标没有改善的情况下等待多少个训练周期后提前停止训练。有助于防止overfitting通过在性能达到平稳状态时停止训练。 |
| batch
| int
| 16
| Batch size, 有三种模式:设置为整数(例如,batch=16
I'll translate the text to Simplified Chinese while maintaining the original format:
)、60% GPU 内存利用率的自动模式(batch=-1
I'll translate the given text into Simplified Chinese while preserving the original format and meaning:
),或带有指定利用率分数的自动模式(batch=0.70
). |
| imgsz
| int
或者list
| 640
| 训练的目标图像尺寸。所有图像在输入模型前都会被调整为此尺寸。影响模型accuracy和计算复杂性。
| save
| bool
| True
| 支持保存训练检查点和最终模型权重。对于恢复训练或model deployment. |
| save_period
| int
| -1
| 保存模型检查点的频率,以周期(epochs)为单位指定。值为-1时禁用此功能。在长时间训练过程中保存中间模型时很有用。 |
| cache
| bool
| False
| 启用数据集图像在内存中的缓存 (True
/ram
I need to translate the text fragment "), on disk (" into Simplified Chinese while maintaining the original format.
Here's the translation:
), 在磁盘上 (disk
I notice that the text you've provided appears to be a fragment rather than a complete sentence or paragraph. It seems to be part of a larger text describing options where something either "disables it" or some other action represented by the closing parenthesis at the beginning.
Without more context, I'll translate just this fragment as accurately as possible:
),或禁用它 (False
). 通过减少磁盘I/O来提高训练速度,但代价是增加内存使用量。
| device
| int
或者str
或者list
| None
| 指定用于训练的计算设备:单个GPU (device=0
),多个GPU(device=0,1
I notice that the text you've provided is very short and appears to be a fragment. It looks like part of a technical description, possibly about hardware components, with "CPU" mentioned in parentheses.
Here's the translation to Simplified Chinese:
), CPU (
The text is identical in Simplified Chinese because it only contains the abbreviation "CPU" and some punctuation marks, which remain the same in both English and Simplified Chinese.device=cpu
I'll translate the text to Simplified Chinese while maintaining the original format:
), 或者用于 Apple 芯片的 MPS (device=mps
). |
| workers
| int
| 8
I need to translate the given text fragment into Simplified Chinese while preserving its original meaning and format.
| 数据加载的工作线程数量(每`RANK`如果是多GPU训练)。影响数据预处理和输入模型的速度,尤其在多GPU设置中非常有用。
| project
| str
| None
| 保存训练输出的项目目录名称。允许有组织地存储不同的实验。 |
| name
| str
| None
| 训练运行的名称。用于在项目文件夹内创建子目录,训练日志和输出将存储在该子目录中。 |
| exist_ok
| bool
| False
| 如果为 True,允许覆盖已存在的项目/名称目录。这对于迭代实验很有用,无需手动清除先前的输出。 |
| pretrained
| bool
或者str
| True
| 确定是否从预训练模型开始训练。可以是布尔值或指向特定模型的字符串路径,用于加载权重。提高训练效率和模型性能。 |
| optimizer
| str
| 'auto'
| 训练优化器的选择。选项包括SGD
, Adam
, AdamW
, NAdam
, RAdam
, RMSProp
I notice that the content you've provided for translation is incomplete or fragmented. All I can see is "etc., or" which doesn't form a complete sentence or paragraph to translate properly.
Could you please provide the complete text that you'd like me to translate to Simplified Chinese? Once you share the full content, I'll be happy to translate it while maintaining the original format and meaning.auto
基于模型配置的自动选择。影响收敛速度和稳定性。
| seed
| int
| 0
| 设置训练的随机种子,确保在相同配置下的多次运行能够产生可重复的结果。 |
| deterministic
| bool
| True
| 强制使用确定性算法,确保可重现性,但由于限制使用非确定性算法,可能会影响性能和速度。 |
| single_cls
| bool
| False
| 在训练过程中将多类数据集中的所有类别视为单一类别。适用于二元分类任务或当关注对象存在而非分类时。 |
| classes
| list[int]
| None
| 指定要训练的类别ID列表。在训练期间用于过滤掉特定类别并只关注某些类别,非常实用。 |
| rect
| bool
| False
| 启用矩形训练,优化批次组合以最小化填充。可以提高效率和速度,但可能会影响模型准确性。 |
| multi_scale
| bool
| False
| 通过增加/减少来实现多尺度训练imgsz
最多可达到...倍0.5
在训练期间。训练模型通过多种方式提高准确性imgsz
在推理过程中。
| cos_lr
| bool
| False
| 利用余弦learning rate调度器,根据余弦曲线在训练周期内调整学习率。有助于管理学习率以获得更好的收敛效果。
| close_mosaic
| int
| 10
I'll translate this content into Simplified Chinese while maintaining the original format:
| 禁用马赛克[data augmentation](https://www.ultralytics.com/glossary/data-augmentation)在最后的N个训练周期中稳定训练以便完成。设置为0将禁用此功能。
| resume
| bool
| False
| 从上次保存的检查点恢复训练。自动加载模型权重、优化器状态和训练轮数,无缝继续训练。 |
| amp
| bool
| True
| 启用自动Mixed Precision(AMP)训练,减少内存使用并可能加速训练,同时对准确性的影响最小。
| fraction
| float
| 1.0
| 指定用于训练的数据集比例。允许在完整数据集的子集上进行训练,这在实验或资源有限时很有用。 |
| profile
| bool
| False
| 在训练期间启用ONNX和TensorRT速度的分析,有助于优化模型部署。 |
| freeze
| int
或者list
| None
| 冻结模型的前N层或指定索引的层,减少可训练参数的数量。对于微调或迁移学习非常有用。transfer learning. |
| lr0
| float
| 0.01
| 初始学习率(即SGD=1E-2
, Adam=1E-3
调整这个值对于优化过程至关重要,它会影响模型权重更新的速度。
| lrf
| float
| 0.01
| 最终学习率作为初始率的分数 = (lr0 * lrf
这部分内容是关于与调度器(schedulers)一起使用的内容,用于随时间调整学习率。
| momentum
| float
| 0.937
I'll translate this content into Simplified Chinese while maintaining the original format:
| SGD的动量因子或beta1为Adam optimizers,影响过去梯度在当前更新中的融合。
| weight_decay
| float
| 0.0005
I need to translate "L2" to Simplified Chinese while maintaining the original format. However, "L2" appears to be a very brief code or label without much context. In technical contexts, "L2" often refers to "Layer 2" in networking or other technical domains, and it's typically kept as "L2" in Chinese technical documentation as well.
Given the minimal content and lack of context, I'll provide the most appropriate translation:
| L2regularization项,惩罚较大的权重以防止过拟合。
| warmup_epochs
| float
| 3.0
| 学习率预热的周期数,在训练初期逐渐将学习率从低值增加到初始学习率,以稳定早期训练。 |
| warmup_momentum
| float
| 0.8
| 预热阶段的初始动量,在预热期间逐渐调整到设定的动量值。 |
| warmup_bias_lr
| float
| 0.1
| 在预热阶段用于偏置参数的学习率,有助于在初始训练周期中稳定模型训练。 |
| box
| float
| 7.5
| 盒子损失组件的权重loss functionI'll translate this fragment into Simplified Chinese while maintaining the original format and meaning:
,影响对准确预测的重视程度bounding box坐标。 |
| cls
| float
| 0.5
| 分类损失在总损失函数中的权重,影响正确类别预测相对于其他组件的重要性。 |
| dfl
| float
| 1.5
| 分布焦点损失的权重,用于某些 YOLO 版本中的细粒度分类。 |
| pose
| float
| 12.0
| 在训练用于姿态估计的模型中,姿态损失的权重,影响对准确预测姿态关键点的重视程度。 |
| kobj
| float
| 2.0
| 姿态估计模型中关键点目标性损失的权重,平衡检测置信度与姿态准确性。 |
| nbs
| int
| 64
| 用于损失归一化的标称批量大小。 |
| overlap_mask
| bool
| True
| 确定是否应将对象蒙版合并为单个蒙版用于训练,或为每个对象保持单独的蒙版。在重叠的情况下,较小的蒙版会在合并过程中覆盖在较大蒙版的顶部。 |
| mask_ratio
| int
| 4
| 分割掩码的下采样比率,影响训练期间使用的掩码分辨率。 |
| dropout
| float
| 0.0
| 用于分类任务的丢弃率正则化,通过在训练过程中随机忽略单元来防止过拟合。 |
| val
| bool
| True
| 在训练过程中启用验证,允许定期评估模型在单独数据集上的性能。 |
| plots
| bool
| False
| 生成并保存训练和验证指标的图表,以及预测示例,提供关于模型性能和学习进展的可视化见解。 |
Note on Batch-size Settings
The batch
argument offers three configuration options:
- Fixed Batch Size: Specify the number of images per batch with an integer (e.g.,
batch=16
). - Auto Mode (60% GPU Memory): Use
batch=-1
for automatic adjustment to approximately 60% CUDA memory utilization. - Auto Mode with Utilization Fraction: Set a fraction (e.g.,
batch=0.70
) to adjust based on a specified GPU memory usage.
Predict Settings
Prediction settings for YOLO models include hyperparameters and configurations that influence performance, speed, and accuracy during inference. Key settings include the confidence threshold, Non-Maximum Suppression (NMS) threshold, and the number of classes. Input data size, format, and supplementary features like masks also affect predictions. Tuning these settings is essential for optimal performance.
Inference arguments:
Argument | Type | Default | Description |
---|---|---|---|
source |
str |
'ultralytics/assets' |
Specifies the data source for inference. Can be an image path, video file, directory, URL, or device ID for live feeds. Supports a wide range of formats and sources, enabling flexible application across different types of input. |
conf |
float |
0.25 |
Sets the minimum confidence threshold for detections. Objects detected with confidence below this threshold will be disregarded. Adjusting this value can help reduce false positives. |
iou |
float |
0.7 |
Intersection Over Union (IoU) threshold for Non-Maximum Suppression (NMS). Lower values result in fewer detections by eliminating overlapping boxes, useful for reducing duplicates. |
imgsz |
int or tuple |
640 |
Defines the image size for inference. Can be a single integer 640 for square resizing or a (height, width) tuple. Proper sizing can improve detection accuracy and processing speed. |
half |
bool |
False |
Enables half-precision (FP16) inference, which can speed up model inference on supported GPUs with minimal impact on accuracy. |
device |
str |
None |
Specifies the device for inference (e.g., cpu , cuda:0 or 0 ). Allows users to select between CPU, a specific GPU, or other compute devices for model execution. |
batch |
int |
1 |
Specifies the batch size for inference (only works when the source is a directory, video file or .txt file). A larger batch size can provide higher throughput, shortening the total amount of time required for inference. |
max_det |
int |
300 |
Maximum number of detections allowed per image. Limits the total number of objects the model can detect in a single inference, preventing excessive outputs in dense scenes. |
vid_stride |
int |
1 |
Frame stride for video inputs. Allows skipping frames in videos to speed up processing at the cost of temporal resolution. A value of 1 processes every frame, higher values skip frames. |
stream_buffer |
bool |
False |
Determines whether to queue incoming frames for video streams. If False , old frames get dropped to accommodate new frames (optimized for real-time applications). If True , queues new frames in a buffer, ensuring no frames get skipped, but will cause latency if inference FPS is lower than stream FPS. |
visualize |
bool |
False |
Activates visualization of model features during inference, providing insights into what the model is "seeing". Useful for debugging and model interpretation. |
augment |
bool |
False |
Enables test-time augmentation (TTA) for predictions, potentially improving detection robustness at the cost of inference speed. |
agnostic_nms |
bool |
False |
Enables class-agnostic Non-Maximum Suppression (NMS), which merges overlapping boxes of different classes. Useful in multi-class detection scenarios where class overlap is common. |
classes |
list[int] |
None |
Filters predictions to a set of class IDs. Only detections belonging to the specified classes will be returned. Useful for focusing on relevant objects in multi-class detection tasks. |
retina_masks |
bool |
False |
Returns high-resolution segmentation masks. The returned masks (masks.data ) will match the original image size if enabled. If disabled, they have the image size used during inference. |
embed |
list[int] |
None |
Specifies the layers from which to extract feature vectors or embeddings. Useful for downstream tasks like clustering or similarity search. |
project |
str |
None |
Name of the project directory where prediction outputs are saved if save is enabled. |
name |
str |
None |
Name of the prediction run. Used for creating a subdirectory within the project folder, where prediction outputs are stored if save is enabled. |
stream |
bool |
False |
Enables memory-efficient processing for long videos or numerous images by returning a generator of Results objects instead of loading all frames into memory at once. |
verbose |
bool |
True |
Controls whether to display detailed inference logs in the terminal, providing real-time feedback on the prediction process. |
Visualization arguments:
Argument | Type | Default | Description |
---|---|---|---|
show |
bool |
False |
If True , displays the annotated images or videos in a window. Useful for immediate visual feedback during development or testing. |
save |
bool |
False or True |
Enables saving of the annotated images or videos to file. Useful for documentation, further analysis, or sharing results. Defaults to True when using CLI & False when used in Python. |
save_frames |
bool |
False |
When processing videos, saves individual frames as images. Useful for extracting specific frames or for detailed frame-by-frame analysis. |
save_txt |
bool |
False |
Saves detection results in a text file, following the format [class] [x_center] [y_center] [width] [height] [confidence] . Useful for integration with other analysis tools. |
save_conf |
bool |
False |
Includes confidence scores in the saved text files. Enhances the detail available for post-processing and analysis. |
save_crop |
bool |
False |
Saves cropped images of detections. Useful for dataset augmentation, analysis, or creating focused datasets for specific objects. |
show_labels |
bool |
True |
Displays labels for each detection in the visual output. Provides immediate understanding of detected objects. |
show_conf |
bool |
True |
Displays the confidence score for each detection alongside the label. Gives insight into the model's certainty for each detection. |
show_boxes |
bool |
True |
Draws bounding boxes around detected objects. Essential for visual identification and location of objects in images or video frames. |
line_width |
None or int |
None |
Specifies the line width of bounding boxes. If None , the line width is automatically adjusted based on the image size. Provides visual customization for clarity. |
font_size |
float |
None |
Text font size for annotations. Scales automatically with image size if set to None . |
font |
str |
'Arial.ttf' |
Font name or path for text annotations in the visualization. |
pil |
bool |
False |
Return image as a PIL Image object instead of numpy array. |
kpt_radius |
int |
5 |
Radius of keypoints when visualizing pose estimation results. |
kpt_line |
bool |
True |
Connect keypoints with lines when visualizing pose estimation. |
masks |
bool |
True |
Display segmentation masks in the visualization output. |
probs |
bool |
True |
Include classification probabilities in the visualization. |
filename |
str |
None |
Path and filename to save the annotated image when save=True . |
color_mode |
str |
'class' |
Specify the coloring mode for visualizations, e.g., 'instance' or 'class'. |
txt_color |
tuple[int, int, int] |
(255, 255, 255) |
RGB text color for classification task annotations. |
Validation Settings
Validation settings for YOLO models involve hyperparameters and configurations to evaluate performance on a validation dataset. These settings influence performance, speed, and accuracy. Common settings include batch size, validation frequency, and performance metrics. The validation dataset's size and composition, along with the specific task, also affect the process.
Argument | Type | Default | Description |
---|---|---|---|
data |
str |
None |
Specifies the path to the dataset configuration file (e.g., coco8.yaml ). This file includes paths to validation data, class names, and number of classes. |
imgsz |
int |
640 |
Defines the size of input images. All images are resized to this dimension before processing. Larger sizes may improve accuracy for small objects but increase computation time. |
batch |
int |
16 |
Sets the number of images per batch. Higher values utilize GPU memory more efficiently but require more VRAM. Adjust based on available hardware resources. |
save_json |
bool |
False |
If True , saves the results to a JSON file for further analysis, integration with other tools, or submission to evaluation servers like COCO. |
conf |
float |
0.001 |
Sets the minimum confidence threshold for detections. Lower values increase recall but may introduce more false positives. Used during validation to compute precision-recall curves. |
iou |
float |
0.6 |
Sets the Intersection Over Union threshold for Non-Maximum Suppression. Controls duplicate detection elimination. |
max_det |
int |
300 |
Limits the maximum number of detections per image. Useful in dense scenes to prevent excessive detections and manage computational resources. |
half |
bool |
True |
Enables half-precision (FP16) computation, reducing memory usage and potentially increasing speed with minimal impact on accuracy. |
device |
str |
None |
Specifies the device for validation (cpu , cuda:0 , etc.). When None , automatically selects the best available device. Multiple CUDA devices can be specified with comma separation. |
dnn |
bool |
False |
If True , uses the OpenCV DNN module for ONNX model inference, offering an alternative to PyTorch inference methods. |
plots |
bool |
False |
When set to True , generates and saves plots of predictions versus ground truth, confusion matrices, and PR curves for visual evaluation of model performance. |
rect |
bool |
True |
If True , uses rectangular inference for batching, reducing padding and potentially increasing speed and efficiency by processing images in their original aspect ratio. |
split |
str |
'val' |
Determines the dataset split to use for validation (val , test , or train ). Allows flexibility in choosing the data segment for performance evaluation. |
project |
str |
None |
Name of the project directory where validation outputs are saved. Helps organize results from different experiments or models. |
name |
str |
None |
Name of the validation run. Used for creating a subdirectory within the project folder, where validation logs and outputs are stored. |
verbose |
bool |
False |
If True , displays detailed information during the validation process, including per-class metrics, batch progress, and additional debugging information. |
save_txt |
bool |
False |
If True , saves detection results in text files, with one file per image, useful for further analysis, custom post-processing, or integration with other systems. |
save_conf |
bool |
False |
If True , includes confidence values in the saved text files when save_txt is enabled, providing more detailed output for analysis and filtering. |
save_crop |
bool |
False |
If True , saves cropped images of detected objects, which can be useful for creating focused datasets, visual verification, or further analysis of individual detections. |
workers |
int |
8 |
Number of worker threads for data loading. Higher values can speed up data preprocessing but may increase CPU usage. Setting to 0 uses main thread, which can be more stable in some environments. |
augment |
bool |
False |
Enables test-time augmentation (TTA) during validation, potentially improving detection accuracy at the cost of inference speed by running inference on transformed versions of the input. |
agnostic_nms |
bool |
False |
Enables class-agnostic Non-Maximum Suppression, which merges overlapping boxes regardless of their predicted class. Useful for instance-focused applications. |
single_cls |
bool |
False |
Treats all classes as a single class during validation. Useful for evaluating model performance on binary detection tasks or when class distinctions aren't important. |
Careful tuning and experimentation are crucial to ensure optimal performance and to detect and prevent overfitting.
Export Settings
Export settings for YOLO models include configurations for saving or exporting the model for use in different environments. These settings impact performance, size, and compatibility. Key settings include the exported file format (e.g., ONNX, TensorFlow SavedModel), the target device (e.g., CPU, GPU), and features like masks. The model's task and the destination environment's constraints also affect the export process.
Argument | Type | Default | Description |
---|---|---|---|
format |
str |
'torchscript' |
Target format for the exported model, such as 'onnx' , 'torchscript' , 'engine' (TensorRT), or others. Each format enables compatibility with different deployment environments. |
imgsz |
int or tuple |
640 |
Desired image size for the model input. Can be an integer for square images (e.g., 640 for 640×640) or a tuple (height, width) for specific dimensions. |
keras |
bool |
False |
Enables export to Keras format for TensorFlow SavedModel, providing compatibility with TensorFlow serving and APIs. |
optimize |
bool |
False |
Applies optimization for mobile devices when exporting to TorchScript, potentially reducing model size and improving inference performance. Not compatible with NCNN format or CUDA devices. |
half |
bool |
False |
Enables FP16 (half-precision) quantization, reducing model size and potentially speeding up inference on supported hardware. Not compatible with INT8 quantization or CPU-only exports for ONNX. |
int8 |
bool |
False |
Activates INT8 quantization, further compressing the model and speeding up inference with minimal accuracy loss, primarily for edge devices. When used with TensorRT, performs post-training quantization (PTQ). |
dynamic |
bool |
False |
Allows dynamic input sizes for ONNX, TensorRT and OpenVINO exports, enhancing flexibility in handling varying image dimensions. Automatically set to True when using TensorRT with INT8. |
simplify |
bool |
True |
Simplifies the model graph for ONNX exports with onnxslim , potentially improving performance and compatibility with inference engines. |
opset |
int |
None |
Specifies the ONNX opset version for compatibility with different ONNX parsers and runtimes. If not set, uses the latest supported version. |
workspace |
float or None |
None |
Sets the maximum workspace size in GiB for TensorRT optimizations, balancing memory usage and performance. Use None for auto-allocation by TensorRT up to device maximum. |
nms |
bool |
False |
Adds Non-Maximum Suppression (NMS) to the exported model when supported (see Export Formats), improving detection post-processing efficiency. Not available for end2end models. |
batch |
int |
1 |
Specifies export model batch inference size or the maximum number of images the exported model will process concurrently in predict mode. For Edge TPU exports, this is automatically set to 1. |
device |
str |
None |
Specifies the device for exporting: GPU (device=0 ), CPU (device=cpu ), MPS for Apple silicon (device=mps ) or DLA for NVIDIA Jetson (device=dla:0 or device=dla:1 ). TensorRT exports automatically use GPU. |
data |
str |
'coco8.yaml' |
Path to the dataset configuration file (default: coco8.yaml ), essential for INT8 quantization calibration. If not specified with INT8 enabled, a default dataset will be assigned. |
fraction |
float |
1.0 |
Specifies the fraction of the dataset to use for INT8 quantization calibration. Allows for calibrating on a subset of the full dataset, useful for experiments or when resources are limited. If not specified with INT8 enabled, the full dataset will be used. |
Thoughtful configuration ensures the exported model is optimized for its use case and functions effectively in the target environment.
Solutions Settings
Ultralytics Solutions configuration settings offer flexibility to customize models for tasks like object counting, heatmap creation, workout tracking, data analysis, zone tracking, queue management, and region-based counting. These options allow easy adjustments for accurate and useful results tailored to specific needs.
Argument | Type | Default | Description |
---|---|---|---|
model |
str |
None |
Path to Ultralytics YOLO Model File. |
region |
list |
[(20, 400), (1260, 400)] |
List of points defining the counting region. |
show_in |
bool |
True |
Flag to control whether to display the in counts on the video stream. |
show_out |
bool |
True |
Flag to control whether to display the out counts on the video stream. |
analytics_type |
str |
line |
Type of graph, i.e., line , bar , area , or pie . |
colormap |
int |
cv2.COLORMAP_JET |
Colormap to use for the heatmap. |
json_file |
str |
None |
Path to the JSON file that contains all parking coordinates data. |
up_angle |
float |
145.0 |
Angle threshold for the 'up' pose. |
kpts |
list[int, int, int] |
[6, 8, 10] |
List of keypoints used for monitoring workouts. These keypoints correspond to body joints or parts, such as shoulders, elbows, and wrists, for exercises like push-ups, pull-ups, squats, ab-workouts. |
down_angle |
float |
90.0 |
Angle threshold for the 'down' pose. |
blur_ratio |
float |
0.5 |
Adjusts percentage of blur intensity, with values in range 0.1 - 1.0 . |
crop_dir |
str |
"cropped-detections" |
Directory name for storing cropped detections. |
records |
int |
5 |
Total detections count to trigger an email with security alarm system. |
vision_point |
tuple[int, int] |
(50, 50) |
The point where vision will track objects and draw paths using VisionEye Solution. |
tracker |
str |
'botsort.yaml' |
Specifies the tracking algorithm to use, e.g., bytetrack.yaml or botsort.yaml . |
conf |
float |
0.3 |
Sets the confidence threshold for detections; lower values allow more objects to be tracked but may include false positives. |
iou |
float |
0.5 |
Sets the Intersection over Union (IoU) threshold for filtering overlapping detections. |
classes |
list |
None |
Filters results by class index. For example, classes=[0, 2, 3] only tracks the specified classes. |
verbose |
bool |
True |
Controls the display of tracking results, providing a visual output of tracked objects. |
device |
str |
None |
Specifies the device for inference (e.g., cpu , cuda:0 or 0 ). Allows users to select between CPU, a specific GPU, or other compute devices for model execution. |
show |
bool |
False |
If True , displays the annotated images or videos in a window. Useful for immediate visual feedback during development or testing. |
line_width |
None or int |
None |
Specifies the line width of bounding boxes. If None , the line width is automatically adjusted based on the image size. Provides visual customization for clarity. |
Augmentation Settings
Data augmentation techniques are essential for improving YOLO model robustness and performance by introducing variability into the training data, helping the model generalize better to unseen data. The following table outlines each augmentation argument's purpose and effect:
参数 | 类型 | 默认值 | 范围 | 描述 |
---|---|---|---|---|
hsv_h |
float |
0.015 |
0.0 - 1.0 |
通过色轮的一部分调整图像的色调,引入色彩变化。帮助模型在不同光照条件下实现泛化。 |
hsv_s |
float |
0.7 |
0.0 - 1.0 |
通过一定比例改变图像的饱和度,影响颜色的强度。适用于模拟不同的环境条件。 |
hsv_v |
float |
0.4 |
0.0 - 1.0 |
通过调整图像的亮度值,帮助模型在各种光照条件下都能表现良好。 |
degrees |
float |
0.0 |
-180 - +180 |
在指定的角度范围内随机旋转图像,提高模型识别各种方向上的物体的能力。 |
translate |
float |
0.1 |
0.0 - 1.0 |
水平和垂直方向上按图像尺寸的一部分平移图像,有助于学习检测部分可见的物体。 |
scale |
float |
0.5 |
>=0.0 |
通过增益因子缩放图像,模拟不同距离下的物体与相机的关系。 |
shear |
float |
0.0 |
-180 - +180 |
通过指定角度剪切图像,模拟从不同角度观看物体的效果。 |
perspective |
float |
0.0 |
0.0 - 0.001 |
对图像应用随机透视变换,增强模型理解三维空间中物体的能力。 |
flipud |
float |
0.0 |
0.0 - 1.0 |
以指定的概率将图像上下翻转,在不影响对象特征的情况下增加数据的多样性。 |
fliplr |
float |
0.5 |
0.0 - 1.0 |
以指定的概率将图像从左到右翻转,有助于学习对称物体和增加数据集多样性。 |
bgr |
float |
0.0 |
0.0 - 1.0 |
以指定的概率将图像通道从RGB翻转为BGR,有助于增强对不正确通道排序的鲁棒性。 |
mosaic |
float |
1.0 |
0.0 - 1.0 |
将四张训练图像合并为一张,模拟不同的场景组合和物体交互。对于复杂场景理解非常有效。 |
mixup |
float |
0.0 |
0.0 - 1.0 |
混合两张图像及其标签,创建一个合成图像。通过引入标签噪声和视觉变化,增强模型的泛化能力。 |
copy_paste |
float |
0.0 |
0.0 - 1.0 |
跨图像复制和粘贴对象,有助于增加对象实例数量并学习对象遮挡。需要分割标签。 |
copy_paste_mode |
str |
'flip' 我将把这段内容翻译成简体中文,保持原始格式和含义: |
| - | 在选项中选择复制粘贴增强方法 (`"flip"`, `"mixup"`). |
| auto_augment
| str
| 'randaugment'
| - | 自动应用预定义的增强策略 (randaugment
, autoaugment
, augmix
), 通过多样化视觉特征来优化分类任务。|
| erasing
| float
| 0.4
| 0.0 - 0.9
| 在分类训练过程中随机擦除图像的一部分,鼓励模型关注不太明显的特征来进行识别。 |
| crop_fraction
| float
| 1.0
| 0.1 - 1.0
| 将分类图像裁剪至其原始尺寸的一部分,以突出中心特征并适应物体比例,减少背景干扰。 |
Adjust these settings to meet dataset and task requirements. Experimenting with different values can help find the optimal augmentation strategy for the best model performance.
Logging, Checkpoints and Plotting Settings
Logging, checkpoints, plotting, and file management are important when training a YOLO model:
- Logging: Track the model's progress and diagnose issues using libraries like TensorBoard or by writing to a file.
- Checkpoints: Save the model at regular intervals to resume training or experiment with different configurations.
- Plotting: Visualize performance and training progress using libraries like matplotlib or TensorBoard.
- File management: Organize files generated during training, such as checkpoints, log files, and plots, for easy access and analysis.
Effective management of these aspects helps track progress and makes debugging and optimization easier.
Argument | Default | Description |
---|---|---|
project |
'runs' |
Specifies the root directory for saving training runs. Each run is saved in a separate subdirectory. |
name |
'exp' |
Defines the experiment name. If unspecified, YOLO increments this name for each run (e.g., exp , exp2 ) to avoid overwriting. |
exist_ok |
False |
Determines whether to overwrite an existing experiment directory. True allows overwriting; False prevents it. |
plots |
False |
Controls the generation and saving of training and validation plots. Set to True to create plots like loss curves, precision-recall curves, and sample predictions for visual tracking of performance. |
save |
False |
Enables saving training checkpoints and final model weights. Set to True to save model states periodically, allowing training resumption or model deployment. |
FAQ
How do I improve my YOLO model's performance during training?
Improve performance by tuning hyperparameters like batch size, learning rate, momentum, and weight decay. Adjust data augmentation settings, select the right optimizer, and use techniques like early stopping or mixed precision. For details, see the Train Guide.
What are the key hyperparameters for YOLO model accuracy?
Key hyperparameters affecting accuracy include:
- Batch Size (
batch
): Larger sizes can stabilize training but need more memory. - Learning Rate (
lr0
): Smaller rates offer fine adjustments but slower convergence. - Momentum (
momentum
): Accelerates gradient vectors, dampening oscillations. - Image Size (
imgsz
): Larger sizes improve accuracy but increase computational load.
Adjust these based on your dataset and hardware. Learn more in Train Settings.
How do I set the learning rate for training a YOLO model?
The learning rate (lr0
) is crucial; start with 0.01
for SGD or 0.001
for Adam optimizer. Monitor metrics and adjust as needed. Use cosine learning rate schedulers (cos_lr
) or warmup (warmup_epochs
, warmup_momentum
). Details are in the Train Guide.
What are the default inference settings for YOLO models?
Default settings include:
- Confidence Threshold (
conf=0.25
): Minimum confidence for detections. - IoU Threshold (
iou=0.7
): For Non-Maximum Suppression (NMS). - Image Size (
imgsz=640
): Resizes input images. - Device (
device=None
): Selects CPU or GPU.
For a full overview, see Predict Settings and the Predict Guide.
Why use mixed precision training with YOLO models?
Mixed precision training (amp=True
) reduces memory usage and speeds up training using FP16 and FP32. It's beneficial for modern GPUs, allowing larger models and faster computations without significant accuracy loss. Learn more in the Train Guide.