The YOLOv8 cosine learning rate schedule gradually reduces the learning rate over the course of training using a cosine-shaped decay curve. In Ultralytics, cosine scheduling can be enabled with cos_lr=True. The scheduler starts near the initial learning rate and progressively moves toward a final learning-rate fraction controlled by lrf. This can provide smoother late-stage optimization than a simple linear schedule and may improve convergence on some datasets.
Introduction to YOLOv8 Cosine Learning Rate
The learning rate determines how strongly the optimizer changes model weights after each training update.
A large learning rate allows the network to make bigger changes, which can be useful early in training. Near the end of training, smaller parameter updates are often preferable because the model is refining an already learned solution.
A cosine learning-rate schedule provides this transition automatically.
Conceptually:
Training Start
↓
Higher Learning Rate
↓
Smooth Cosine Decay
↓
Lower Learning Rate
↓
Training End
Ultralytics exposes this behavior through the cos_lr training argument.
What Is Cosine Learning Rate in YOLOv8?
Cosine learning-rate scheduling changes the learning rate according to a cosine-shaped function instead of reducing it by the same amount after every epoch.
In Ultralytics, enabling:
cos_lr=True
causes the trainer to construct a cosine schedule that moves from a multiplier of 1 toward the configured lrf value over the selected number of epochs.
Role of Learning Rate During Training
During gradient-based optimization, model parameters are updated according to the calculated gradients.
A simplified update can be written as:
new_weight =
old_weight - learning_rate × gradient
The learning rate therefore controls the size of each optimization step.
If it is too high:
Large updates
↓
Overshooting
↓
Unstable training
If it is too low:
Very small updates
↓
Slow convergence
↓
Longer training
A scheduler changes the learning rate throughout training rather than keeping one fixed value.
How Cosine Learning Rate Scheduling Works
A cosine schedule normally begins near the configured initial learning rate.
It decreases relatively slowly at first, changes more strongly through the middle portion of training, and then becomes gradual again near the final learning rate.
Conceptually:
Learning
Rate
│
│████████
│ ███
│ ███
│ ██
│ ███
│ ████
└────────────────────────
Epochs
The curve is smooth rather than containing sudden learning-rate drops.
Current Ultralytics trainer source configures the cosine scheduler using its one_cycle() helper from a starting factor of 1 to the lrf factor over the training epochs.
YOLOv8 Cosine Learning Rate Formula
A general cosine-decay schedule can be expressed conceptually as:
lr(t) =
lr_final
+
0.5 × (lr_initial - lr_final)
×
(1 + cos(πt / T))
where:
lr_initial = starting learning rate
lr_final = final learning rate
t = current training progress
T = total decay duration
Ultralytics implements its own cosine multiplier through the trainer rather than requiring users to manually calculate this formula.
Initial Learning Rate
The initial learning rate is configured with:
lr0
For example:
yolo detect train model=yolov8n.pt data=data.yaml lr0=0.01
The appropriate value depends on:
- optimizer,
- batch size,
- model size,
- dataset,
- transfer-learning setup.
Ultralytics exposes lr0 as the initial optimizer learning-rate setting.
Final Learning Rate
The parameter:
lrf
defines the final learning-rate factor relative to the initial learning rate.
Conceptually:
final_lr = lr0 × lrf
For example:
lr0 = 0.01
lrf = 0.01
gives a target final scale of approximately:
0.01 × 0.01
=
0.0001
Ultralytics documentation describes lrf as the final learning rate expressed as a fraction of the initial learning rate.
Gradual Learning Rate Decay
With cosine scheduling enabled, the learning rate does not decrease by the same fixed amount every epoch.
Instead, the learning-rate multiplier follows the cosine curve from:
1.0
toward:
lrf
over the total configured epochs.
The result is a smooth nonlinear decay.
How to Enable Cosine Learning Rate in YOLOv8
Cosine LR can be enabled through either the CLI or Python API.
Enable Cosine LR Using the YOLO CLI
For object detection:
yolo detect train model=yolov8n.pt data=data.yaml epochs=100 cos_lr=True
A more explicit configuration could be:
yolo detect train model=yolov8n.pt data=data.yaml epochs=100 lr0=0.01 lrf=0.01 cos_lr=True
The cos_lr argument is officially exposed as a boolean training setting.
Enable Cosine LR in Python
Using Python:
from ultralytics import YOLO
model = YOLO("yolov8n.pt")
model.train(
data="data.yaml",
epochs=100,
lr0=0.01,
lrf=0.01,
cos_lr=True
)
The same training configuration is available through the Python training interface.
Important Training Parameters
Cosine scheduling should be considered together with:
lr0
lrf
epochs
optimizer
batch
warmup_epochs
For example:
model.train(
data="data.yaml",
epochs=150,
batch=16,
optimizer="SGD",
lr0=0.01,
lrf=0.01,
warmup_epochs=3,
cos_lr=True
)
One important detail is optimizer selection. If optimizer=auto is used, current Ultralytics can automatically determine optimizer, learning rate, and momentum, so manually supplied lr0 may not be used as expected.
YOLOv8 Cosine LR vs Linear Learning Rate
Cosine and linear schedules both reduce the learning rate, but they do so differently.
Difference in Learning Rate Decay
A simplified linear schedule might look like:
Learning Rate
│\
│ \
│ \
│ \
│ \
│ \
└────────────
Epochs
It decreases at a relatively constant rate.
Cosine decay looks more like:
Learning Rate
│████
│ ███
│ ██
│ ██
│ ███
│ ████
└────────────────
Epochs
The reduction rate changes throughout training.
In current Ultralytics source, setting cos_lr=True activates the cosine one_cycle() schedule; otherwise the trainer uses its non-cosine scheduler path.
Training Stability and Convergence
Cosine scheduling can provide smoother optimization near the end of training because the learning rate approaches its final level gradually.
This may help the optimizer make increasingly small refinements rather than continuing to apply larger updates.
However, cosine LR does not automatically guarantee:
higher mAP
lower validation loss
better generalization
Its effectiveness depends on the dataset and complete training configuration.
When to Use Cosine Scheduling
Cosine LR is worth testing when:
- training runs are long enough for scheduled decay to matter,
- late-stage training appears unstable,
- the default schedule plateaus,
- you want smoother LR reduction,
- you are comparing scheduler strategies systematically.
It is best treated as a tunable training choice rather than a mandatory setting.
Effect of Cosine Learning Rate on YOLOv8 Training
The effect changes depending on the stage of training.
Early Training Behavior
At the beginning of the main schedule, the learning rate remains relatively close to its initial level.
This allows the optimizer to make meaningful parameter updates while the model is still learning broad patterns.
Warmup can modify the first portion of this behavior before normal cosine decay takes over.
Learning Rate Changes During Later Epochs
As training progresses, cosine scheduling gradually reduces the learning rate.
Near the end:
Large changes → unlikely
Small refinements → more common
This can help stabilize optimization around a learned solution.
Impact on Accuracy and Loss
A suitable cosine schedule may lead to:
- smoother late-stage training,
- better convergence,
- reduced loss oscillation,
- potentially improved validation results.
But a poorly configured starting learning rate or final ratio can still produce weak results.
The scheduler cannot compensate for:
- incorrect labels,
- insufficient data,
- poor class balance,
- inappropriate augmentation,
- unsuitable model size.
Cosine Learning Rate and Warmup
Warmup and cosine scheduling control different phases of the training process.
How Warmup Works in YOLOv8
Warmup gradually transitions training settings during the early epochs.
Ultralytics exposes settings such as:
warmup_epochs
warmup_momentum
warmup_bias_lr
These help prevent overly aggressive parameter updates at the very beginning of training.
Conceptually:
Training begins
↓
Warmup
↓
Target early LR reached
↓
Normal scheduler continues
Combining Warmup with Cosine Decay
Together, the schedule can look conceptually like:
Learning Rate
│ /\
│ / \
│ / \
│ / ███
│ / ███
│ / ████
└──────────────────────
Warmup Cosine Decay
The first part gradually establishes the training learning rate.
The remaining training period then follows the configured scheduler toward the final LR factor.
This combination avoids starting immediately with aggressive optimization while still allowing smooth late-stage decay.
Choosing Cosine Learning Rate Settings
There is no single cosine configuration that works best for every dataset.
Selecting the Initial Learning Rate
Use:
lr0
to control the starting learning rate.
A suitable value depends heavily on the optimizer.
For example, SGD-style optimization may commonly use a larger starting learning rate than Adam-style optimization.
Start with a known stable configuration before tuning aggressively.
Setting the Final Learning Rate Ratio
Use:
lrf
to define how low the learning rate should become relative to lr0.
For example:
lr0 = 0.01
lrf = 0.1
means a final target of:
0.001
while:
lr0 = 0.01
lrf = 0.01
gives:
0.0001
A smaller lrf creates a larger difference between initial and final learning rates.
Adjusting Settings for Different Dataset Sizes
For a small dataset, training may converge relatively quickly.
An extremely long decay schedule may therefore provide little additional value.
For a large dataset with many iterations, longer scheduling can allow a gradual transition from broad learning to fine optimization.
However, dataset size alone should not determine the learning-rate configuration.
Also consider:
- optimizer,
- batch size,
- number of epochs,
- transfer learning,
- dataset complexity.
Common YOLOv8 Cosine Learning Rate Problems
Scheduler problems often appear as unstable loss curves or poor validation metrics.
Learning Rate Too High
Symptoms may include:
Loss spikes
Large metric fluctuations
Unstable convergence
NaN or divergence in severe cases
Reduce lr0 and compare against the previous training run.
Also check whether optimizer=auto is overriding manually selected LR settings.
Learning Rate Drops Too Quickly
If the learning rate becomes very small before the model has learned enough, later epochs may produce little improvement.
Possible causes include:
- too few epochs for the selected behavior,
- very small
lrf, - poor starting LR,
- unsuitable optimizer configuration.
Compare the actual logged learning rate over epochs when diagnosing the problem.
Training Loss Stops Improving
A plateau does not automatically mean cosine scheduling is wrong.
Possible causes include:
- model capacity limit,
- dataset noise,
- insufficient data,
- weak labels,
- excessive regularization,
- learning rate becoming too small.
Compare cosine scheduling with a baseline before changing multiple settings.
Poor Validation Performance
If training improves but validation gets worse, the main issue may be overfitting rather than scheduler choice.
Check:
Training loss
Validation loss
Precision
Recall
mAP50
mAP50-95
The scheduler should be evaluated using validation performance, not training loss alone.
Best Practices for YOLOv8 Cosine Learning Rate
Cosine LR should be tested systematically.
Monitor Training and Validation Loss
Track learning curves throughout training.
A useful pattern is:
Training loss ↓
Validation metrics ↑
A concerning pattern is:
Training loss ↓
Validation metrics ↓
The second pattern can indicate overfitting.
Tune Learning Rate with Batch Size
Learning rate and batch size can interact.
If batch size changes substantially, the best lr0 may also change.
For example, do not assume:
batch=8
lr0=0.01
will behave identically to:
batch=64
lr0=0.01
Compare configurations using controlled experiments.
Compare Cosine and Default Scheduling
Train a baseline:
yolo detect train model=yolov8n.pt data=data.yaml epochs=100 cos_lr=False
Then compare:
yolo detect train model=yolov8n.pt data=data.yaml epochs=100 cos_lr=True
Keep other settings consistent.
Compare:
mAP50-95
Precision
Recall
Validation loss
Training stability
This provides stronger evidence than assuming cosine scheduling must be better.
FAQs About YOLOv8 Cosine Learning Rate
What is cosine learning rate in YOLOv8?
Cosine learning rate is a scheduling strategy that reduces the learning rate over training according to a cosine-shaped curve.
Ultralytics enables it using:
cos_lr=True
The current trainer uses a cosine helper that moves from a multiplier of 1 toward the configured lrf factor over the training epochs.
How do I enable cosine learning rate in YOLOv8?
Using CLI:
yolo detect train model=yolov8n.pt data=data.yaml cos_lr=True
Using Python:
model.train(
data="data.yaml",
cos_lr=True
)
cos_lr is an official Ultralytics training argument.
Is cosine learning rate better than linear decay?
Not always.
Cosine decay provides smoother nonlinear reduction, while a linear schedule reduces the rate more uniformly.
Which performs better depends on:
- dataset,
- optimizer,
- learning rate,
- epochs,
- model,
- batch size.
The correct approach is to benchmark both on the same validation set.
What does cos_lr mean in YOLOv8?
cos_lr is a boolean training option.
When:
cos_lr=True
Ultralytics activates its cosine learning-rate scheduler.
When it is disabled, the trainer follows its non-cosine scheduler behavior.
Does cosine learning rate improve YOLOv8 accuracy?
It can improve convergence or final validation performance on some datasets, but improvement is not guaranteed.
A scheduler cannot replace good annotations, adequate data, suitable augmentation, or correct model selection.
Always compare validation metrics against a baseline.
What is the final learning rate in cosine scheduling?
In Ultralytics, lrf controls the final learning-rate factor relative to lr0.
Conceptually:
final learning rate ≈ lr0 × lrf
For:
lr0 = 0.01
lrf = 0.01
the final target is approximately:
0.0001
before considering optimizer-specific parameter-group behavior.
Should I use cosine learning rate for every YOLOv8 dataset?
No.
Cosine LR is one scheduling option, not a universal requirement.
Use it when validation experiments show that it provides better:
- convergence,
- stability,
- mAP,
- precision,
- recall,
than your baseline configuration.
Conclusion
The YOLOv8 cosine learning rate schedule provides a smooth nonlinear way to reduce the learning rate throughout training.
Enable it using:
cos_lr=True
For example:
yolo detect train model=yolov8n.pt data=data.yaml epochs=100 lr0=0.01 lrf=0.01 cos_lr=True
Current Ultralytics trainer logic uses a cosine schedule that transitions from a multiplier of 1 toward the lrf multiplier over the configured training epochs.
The three most important settings to understand are:
lr0 → initial learning rate
lrf → final learning-rate factor
cos_lr → enables cosine scheduling
Warmup can be used before the main schedule to stabilize the first stage of optimization, while cosine decay gradually reduces learning-rate magnitude later in training.
The best workflow is:
Create Baseline
↓
Enable cos_lr
↓
Keep Other Settings Consistent
↓
Train
↓
Compare Validation Metrics
↓
Tune lr0 and lrf
Cosine learning-rate scheduling can be a useful YOLOv8 training technique, particularly when smooth late-stage optimization is desirable, but it should be selected based on measured validation results rather than applied automatically to every dataset.
I’m Jane Austen, a skilled content writer with the ability to simplify any complex topic. I focus on delivering valuable tips and strategies throughout my articles.