docs/en/usage/cfg.md
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
<p align="center"> <iframe loading="lazy" width="720" height="405" src="https://www.youtube.com/embed/GsXGnb-A4Kc?start=87" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen> </iframe><strong>Watch:</strong> Mastering Ultralytics YOLO: Configuration
</p>Ultralytics commands use the following syntax:
!!! example
=== "CLI"
```bash
yolo TASK MODE ARGS
```
=== "Python"
```python
from ultralytics import YOLO
# Load a YOLO model from a pretrained weights file
model = YOLO("yolo26n.pt")
# Run the model in MODE using custom ARGS
MODE = "predict"
ARGS = {"source": "image.jpg", "imgsz": 640}
getattr(model, MODE)(**ARGS)
```
Where:
TASK (optional) is one of (detect, segment, classify, pose, obb)MODE (required) is one of (train, val, predict, export, track, benchmark)ARGS (optional) are arg=value pairs like imgsz=640 that override defaults.Default ARG values are defined on this page and come from the cfg/default.yaml file.
Ultralytics YOLO models can perform a variety of computer vision tasks, including:
| 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. |
Tasks Guide{ .md-button }
Ultralytics YOLO models operate in different modes, each designed for a specific stage of the model lifecycle:
| 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. |
Modes Guide{ .md-button }
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.
{% include "macros/train-args.md" %}
!!! info "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.
Train Guide{ .md-button }
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:
{% include "macros/predict-args.md" %}
Visualization arguments:
{% from "macros/visualization-args.md" import param_table %} {{ param_table() }}
Predict Guide{ .md-button }
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.
{% include "macros/validation-args.md" %}
Careful tuning and experimentation are crucial to ensure optimal performance and to detect and prevent overfitting.
Val Guide{ .md-button }
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.
{% include "macros/export-args.md" %}
Thoughtful configuration ensures the exported model is optimized for its use case and functions effectively in the target environment.
Export Guide{ .md-button }
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.
{% from "macros/solutions-args.md" import param_table %} {{ param_table() }}
Solutions Guide{ .md-button }
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:
{% include "macros/augmentation-args.md" %}
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.
Augmentation Guide{ .md-button }
Logging, checkpoints, plotting, and file management are important when training a YOLO model:
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, exp-2) to avoid overwriting. |
exist_ok | False | Determines whether to overwrite an existing experiment directory. True allows overwriting; False prevents it. |
plots | True | 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 | True | Enables saving training checkpoints and final model weights. Set to True to save model states periodically, allowing training resumption or model deployment. |
Load a saved YAML to reuse a full set of arguments without passing them inline. The cfg argument overrides values from default.yaml, while additional arguments passed alongside still take precedence.
| Argument | Default | Description |
|---|---|---|
cfg | None | Path to a YAML file whose values replace default.yaml entries. See Overriding Default Config File for a worked CLI example. |
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.
Key hyperparameters affecting accuracy include:
batch): Larger sizes can stabilize training but need more memory.lr0): Smaller rates offer fine adjustments but slower convergence.momentum): Accelerates gradient vectors, dampening oscillations.imgsz): Larger sizes improve accuracy but increase computational load.Adjust these based on your dataset and hardware. Learn more in Train Settings.
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.
Default settings include:
conf=0.25): Minimum confidence for detections.iou=0.7): For Non-Maximum Suppression (NMS).imgsz=640): Resizes input images.device=None): Selects CPU, GPU, Apple MPS or Huawei Ascend NPU (npu).For a full overview, see Predict Settings and the Predict Guide.
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.