Ultralytics YOLO27: Join the waitlist.
License YOLO
Back to Ultralytics Glossary

Hyperparameter Tuning

Hyperparameter tuning finds the training settings that maximize validation performance. Compares grid, random, Bayesian, and evolutionary search.

Hyperparameter tuning is the search for the training settings that give a machine learning model its best performance on held-out data. Hyperparameters are fixed before training starts, unlike the model weights that training learns from the data. Every candidate configuration has to be scored by training a model and evaluating it on validation data, so tuning is one of the most compute-intensive steps in building a model, and choosing a good search strategy matters as much as choosing the values to search.

Common Hyperparameters#

In deep learning for vision, the settings that most often need tuning fall into a few groups:

  • Optimization: The learning rate and its schedule, momentum, weight decay, and the choice of optimizer, such as SGD or the Adam optimizer. The learning rate usually has the largest effect and is searched on a log scale.
  • Training length and batching: The number of epochs, warmup length, and batch size.
  • Data augmentation: The probability and strength of each transform, such as flips, scaling, color shifts, and mosaic.
  • Loss weights: The gains that balance the terms of a composite loss function, such as box and classification losses in a detector.

Search Methods#

Practitioners navigate the space of possible configurations with a handful of strategies:

  • Grid search: Trains every combination of a fixed list of values. It is simple and exhaustive, but its cost multiplies with every added hyperparameter.
  • Random search: Samples configurations at random from the allowed ranges. Bergstra and Bengio showed it finds models as good as or better than grid search in a small fraction of the computation, because only a few hyperparameters matter much for any given problem and random sampling tries more distinct values of each.
  • Bayesian optimization: Fits a surrogate model of how the score depends on the hyperparameters and picks each next trial where improvement looks most likely. Libraries such as Optuna use this approach by default.
  • Early-termination methods: Hyperband and successive halving start many configurations on a small budget and give more epochs only to the most promising ones.
  • Evolutionary algorithms: Treat each configuration as a genome and improve a population of them through selection and mutation.

Evolutionary search suits training runs with many interacting hyperparameters because it needs no model of the search space, only a fitness score for each trial. Each round takes one of the best configurations found so far, mutates some of its values, trains with the result, and keeps the new configuration in the pool if it scores well.

The Ultralytics tuner runs this loop for YOLO training: each iteration picks a parent from the nine highest-fitness results, mutates roughly half of up to 26 hyperparameters covering learning rate, loss gains, and augmentation, and scores fitness as mAP50-95 for detection. The COCO-stage hyperparameters of the official YOLO26 checkpoints were found with this evolutionary search.

from ultralytics import YOLO

# Load a pretrained YOLO26n model
model = YOLO("yolo26n.pt")

# Search space: (min, max) bounds for each hyperparameter to tune
search_space = {"lr0": (1e-5, 1e-2), "degrees": (0.0, 45.0)}

# Each of the 30 iterations trains for 10 epochs with newly mutated values
model.tune(data="coco8.yaml", epochs=10, iterations=30, space=search_space, plots=False, save=False, val=False)

The run writes best_hyperparameters.yaml, a fitness-per-iteration plot, and the best iteration's weights to a tune directory. model.tune() trains with AdamW unless the optimizer is specified, because the default optimizer="auto" would override the tuned lr0.

  • Model training: Training learns the weights for one fixed set of hyperparameters through backpropagation. Tuning is the outer loop that runs training many times and compares the results.
  • Fine-tuning: Despite the similar name, fine-tuning continues training a pretrained model's weights on new data. It has its own hyperparameters to tune, such as a lower learning rate and the number of frozen layers.
  • Neural architecture search (NAS): Searches over the network's structure, such as layer types and widths, instead of training settings.
  • Automated machine learning (AutoML): Automates the wider pipeline, including model selection and data preprocessing, with hyperparameter tuning as one component.
  • Overfitting to the validation set: Hundreds of tuning trials scored on the same validation split can pick settings that suit that split by chance, so final results belong on a separate test set that tuning never touched.

Explore solutions

Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Turn drone and aerial imagery into real-time insights for agriculture, aquaculture, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Apply computer vision in aerospace with Ultralytics YOLO for aircraft inspection, runway FOD detection, airport ground operations, and composite defect detection.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more

Let's build the future of AI together!

Begin your journey with the future of machine learning