Freezing layers in YOLOv8 means preventing selected model parameters from being updated during training. This is commonly used for transfer learning, especially when starting from pretrained weights and training on a relatively small custom dataset. Ultralytics supports the freeze training argument as either an integer, which freezes the first N model layers, or a list of specific layer indices.
Introduction to Freezing Layers in YOLOv8
YOLOv8 models pretrained on large datasets already contain useful visual features such as edges, textures, shapes, and higher-level object patterns.
When training on a new dataset, it is not always necessary to update every model layer immediately.
Instead, you can freeze selected early layers and train only the remaining parts of the network.
Conceptually:
Pretrained YOLOv8
↓
Freeze Early Layers
↓
Keep Later Layers Trainable
↓
Train on Custom Dataset
This technique is particularly useful for transfer learning, where pretrained features are reused instead of relearned from scratch.
What Does Freezing Layers Mean in YOLOv8?
A frozen layer remains part of the model and still participates in the forward pass, but its trainable parameters are excluded from gradient-based updates.
In PyTorch, this behavior is implemented by setting:
requires_grad = False
for the selected parameters. Ultralytics uses this mechanism when applying the freeze configuration.
How Frozen Layers Behave During Training
A frozen layer still processes incoming feature maps.
For example:
Input
↓
Frozen Conv Layer
↓
Frozen C2f Layer
↓
Trainable Layer
↓
Detection Head
The frozen layers continue producing features, but their weights are not optimized during backpropagation.
Conceptually:
Forward Pass → Yes
Gradient Update → No
This allows pretrained features to remain unchanged while later model components adapt to the custom dataset.
Difference Between Frozen and Trainable Layers
A trainable parameter uses:
requires_grad = True
A frozen parameter uses:
requires_grad = False
The difference is:
Trainable Layer
Forward pass ✓
Backward gradient ✓
Weight update ✓
Frozen Layer
Forward pass ✓
Backward parameter gradient ✗
Weight update ✗
Ultralytics’ trainer sets frozen parameters so that they are excluded from normal optimization.
Why Freeze Layers in YOLOv8?
Layer freezing is mainly used to make transfer learning more efficient and to preserve useful pretrained representations.
Reduce Training Time
When fewer parameters require gradients and optimizer updates, some training computation can be reduced.
This can make fine-tuning more efficient, particularly when a large portion of the feature extractor remains fixed.
However, frozen layers still perform forward computation, so freezing does not remove their inference cost.
Lower GPU Memory Usage
Freezing layers can reduce memory used for gradients and optimizer-related training state for those parameters.
This can be useful when:
- GPU memory is limited,
- the model is relatively large,
- image resolution is high,
- only part of the network needs adaptation.
The amount saved depends on the model and training configuration.
Preserve Pretrained Features
Early layers often contain useful general-purpose features.
For example:
Edges
Textures
Simple shapes
Color patterns
If your custom dataset is similar to the data used for pretraining, preserving these features can be useful.
Instead of changing the complete network immediately, the trainable layers can focus on adapting the model to new classes and dataset characteristics.
How to Freeze Layers in YOLOv8
Ultralytics provides the freeze argument directly through Train mode. It accepts either an integer or a list of layer indices.
Freeze Layers Using the YOLO CLI
To freeze the first 10 model layers:
yolo detect train model=yolov8n.pt data=data.yaml epochs=100 freeze=10
This tells Ultralytics to freeze layers:
0 through 9
while leaving later layers trainable.
The same idea can be used with other YOLOv8 model sizes:
yolo detect train model=yolov8s.pt data=data.yaml epochs=100 freeze=10
Freeze Layers Using Python
Using Python:
from ultralytics import YOLO
model = YOLO("yolov8n.pt")
model.train(
data="data.yaml",
epochs=100,
freeze=10
)
This freezes the first 10 layers at training setup.
You can also specify selected layer indices if the installed Ultralytics version supports the current list-based syntax documented by Train mode.
For example:
model.train(
data="data.yaml",
epochs=100,
freeze=[0, 1, 2, 3, 4]
)
Freeze a Specific Number of Layers
The integer form:
freeze=N
means freeze the first N layers.
For example:
freeze=5
freezes:
Layer 0
Layer 1
Layer 2
Layer 3
Layer 4
while:
freeze=10
freezes:
Layers 0–9
The exact architectural meaning of those indices depends on the model definition, so inspect the actual model before assuming that a specific number always corresponds exactly to the backbone. Ultralytics explicitly documents integer freezing as the first N layers or list-based freezing by index.
Which YOLOv8 Layers Should You Freeze?
There is no fixed number that is best for every dataset.
The correct choice depends on:
- dataset size,
- similarity to pretraining data,
- model size,
- number of custom classes,
- available hardware.
Freezing Backbone Layers
The backbone extracts visual features from the image.
These features often transfer well between related computer vision tasks.
A common strategy is:
Backbone → frozen
Head → trainable
This lets the detector reuse pretrained visual features while adapting the prediction layers to the new dataset.
Before choosing a freeze number, inspect the actual layer indices because architectures and indexing can differ between model families and versions.
Keeping the Detection Head Trainable
The detection head is responsible for producing task-specific predictions.
When training custom classes, keeping the detection head trainable allows the model to adapt to the new class distribution.
Conceptually:
Pretrained Backbone
↓
Frozen Features
↓
Trainable Detection Head
↓
Custom Predictions
Freezing too much of the head can prevent the model from adapting properly.
Choosing Layers Based on Dataset Size
For a small dataset, freezing more early layers can reduce the number of trainable parameters and preserve general pretrained features.
For a larger dataset, full fine-tuning may be more beneficial because enough data is available to update deeper parts of the model safely.
A rough strategy is:
Very small dataset
→ freeze more early layers
Medium dataset
→ freeze fewer layers or compare both
Large diverse dataset
→ consider full fine-tuning
This should be tested using validation metrics rather than treated as a fixed rule.
YOLOv8 Layer Freezing for Transfer Learning
Freezing is most useful when starting from pretrained weights.
Use Pretrained Weights
Load a pretrained YOLOv8 checkpoint:
from ultralytics import YOLO
model = YOLO("yolov8n.pt")
Then train with frozen layers:
model.train(
data="data.yaml",
epochs=100,
freeze=10
)
This preserves selected pretrained parameters while adapting the remaining network.
Train on a Small Custom Dataset
Suppose your dataset contains only a few hundred labeled images.
Full fine-tuning may cause the entire model to adapt too aggressively to this small dataset.
Freezing some pretrained layers can reduce how many parameters need to be learned from limited examples.
This may be especially useful when the custom dataset visually resembles the pretraining domain.
Unfreeze Layers for Fine-Tuning
A useful strategy is staged training.
Stage 1:
Freeze early layers
Train task-specific layers
Stage 2:
Unfreeze more or all layers
Continue fine-tuning with a lower learning rate
For example:
from ultralytics import YOLO
model = YOLO("yolov8n.pt")
model.train(
data="data.yaml",
epochs=50,
freeze=10
)
Then load the resulting checkpoint and start a second fine-tuning run without the freeze setting.
If you want layers to unfreeze automatically during a single run, that requires custom training logic or callbacks rather than the basic fixed freeze argument. Ultralytics’ custom trainer documentation shows callback-based approaches for changing layer freezing during training.
Freeze vs Fine-Tune All YOLOv8 Layers
Freezing and full fine-tuning solve different problems.
When Freezing Layers Works Better
Freezing may work well when:
- the dataset is small,
- the domain is similar to pretrained data,
- GPU resources are limited,
- rapid transfer learning is required,
- overfitting is a concern.
For example, if a pretrained model already understands general vehicles and your custom dataset contains a specialized vehicle category, many early features may remain useful.
When Full Fine-Tuning Is Better
Full fine-tuning may be preferable when:
- the dataset is large,
- the new domain is visually different,
- the model must learn new low-level features,
- maximum adaptation is important.
For example, transferring from ordinary RGB photography to highly specialized thermal or scientific imagery may require deeper feature adaptation.
Effect on Accuracy and Training Speed
Freezing layers can reduce the amount of parameter optimization and may shorten or simplify fine-tuning.
However, too much freezing can reduce final accuracy because the model cannot sufficiently adapt.
Conceptually:
More Freezing
→ less adaptation
→ fewer trainable parameters
Less Freezing
→ more adaptation
→ more trainable parameters
The right balance should be determined experimentally.
How to Check Which YOLOv8 Layers Are Frozen
You can inspect model parameters directly in Python.
Review Model Parameters
Load the model:
from ultralytics import YOLO
model = YOLO("yolov8n.pt")
After the training configuration has applied freezing, frozen parameters can be identified by their requires_grad state.
Conceptually:
for name, param in model.model.named_parameters():
print(name, param.requires_grad)
Output may look like:
model.0.conv.weight False
model.1.conv.weight False
model.10.cv1.weight True
model.22.cv2.weight True
False indicates that the parameter is frozen.
Verify Trainable and Non-Trainable Layers
A clearer check is:
for name, param in model.model.named_parameters():
status = "trainable" if param.requires_grad else "frozen"
print(name, status)
You can also count parameters:
trainable = sum(
p.numel()
for p in model.model.parameters()
if p.requires_grad
)
total = sum(
p.numel()
for p in model.model.parameters()
)
print("Trainable:", trainable)
print("Total:", total)
Ultralytics’ trainer itself checks requires_grad states and raises an error if the chosen freeze configuration leaves the model with no trainable parameters.
Common Problems When Freezing YOLOv8 Layers
Layer freezing can reduce performance when applied too aggressively.
Freezing Too Many Layers
If too many layers are frozen, the model may not have enough trainable capacity to adapt.
Ultralytics currently detects the extreme case where a freeze setting leaves no trainable parameters and raises an error instructing the user to reduce freeze or specify fewer indices.
Even before reaching that extreme, excessive freezing can hurt validation performance.
Low Accuracy on Custom Classes
If custom classes differ significantly from pretrained categories, frozen features may not be sufficiently specialized.
For example:
Pretraining domain:
ordinary photographs
Custom domain:
infrared industrial inspection
The visual statistics may be too different for aggressive freezing.
Try reducing:
freeze=10
to:
freeze=5
or perform full fine-tuning.
Model Fails to Adapt to New Data
Symptoms include:
- training loss improves very slowly,
- validation metrics remain weak,
- new classes are poorly separated,
- predictions resemble pretrained behavior too strongly.
This may indicate that important intermediate features are frozen.
Unfreeze more layers and compare again.
Incorrect Freeze Configuration
A common mistake is assuming that layer number 10 always means exactly the same architectural section.
The actual layer indices depend on the model architecture.
Use the model structure to verify layer positions rather than blindly copying a freeze value from another model family.
Also remember that the freeze argument accepts either the first N layers or a list of selected indices in current Ultralytics Train mode.
Best Practices for Freezing YOLOv8 Layers
Layer freezing should be treated as an experimental transfer-learning strategy.
Start with Pretrained Weights
Freezing is most useful when the frozen layers already contain useful learned features.
Use:
model = YOLO("yolov8n.pt")
instead of starting from an untrained architecture if the goal is transfer learning.
Freezing randomly initialized features would usually prevent those layers from learning anything useful.
Freeze Fewer Layers for Different Domains
If the target dataset differs significantly from the pretraining domain, allow more layers to adapt.
For example:
Similar domain
→ more freezing may work
Different domain
→ less freezing
Very different domain
→ full fine-tuning may work better
This gives the feature extractor greater flexibility.
Compare Frozen and Fully Trainable Models
Run controlled experiments.
For example:
Run A
freeze=10
Run B
freeze=5
Run C
freeze=None
Compare:
mAP50-95
precision
recall
training time
GPU memory
validation loss
This is more reliable than assuming one freeze configuration will work for every dataset.
FAQs About Freezing Layers in YOLOv8
How do I freeze layers in YOLOv8?
Use the freeze training parameter.
CLI:
yolo detect train model=yolov8n.pt data=data.yaml freeze=10
Python:
model.train(
data="data.yaml",
freeze=10
)
Current Ultralytics Train mode supports an integer for the first N layers or a list of selected layer indices.
What does the freeze parameter do in YOLOv8?
The freeze parameter marks selected model parameters as non-trainable during optimization.
Conceptually:
Frozen layer:
requires_grad=False
The layer still participates in the forward pass but its weights are not updated.
How many YOLOv8 layers should I freeze?
There is no universal number.
A reasonable experiment might compare:
freeze=5
freeze=10
freeze=None
The correct setting depends on dataset size, domain similarity, and the actual YOLOv8 architecture being used.
Always inspect layer indices before assuming a particular number corresponds exactly to the entire backbone.
Should I freeze the YOLOv8 backbone?
Freezing part of the backbone can be useful for transfer learning on a small dataset that is reasonably similar to the pretraining domain.
For a large or visually different dataset, full fine-tuning may be better.
The decision should be based on validation performance.
Does freezing layers improve training speed?
It can reduce some training computation because frozen parameters do not require normal gradient and optimizer updates.
It may also reduce memory usage.
However, frozen layers still execute their forward pass, so training does not become proportionally faster simply because many parameters are frozen.
Can I unfreeze layers after training starts?
Not automatically through the basic fixed freeze=N setting.
A practical approach is staged training:
Run 1 → freeze layers
Run 2 → load checkpoint and fine-tune without freeze
For automatic unfreezing during one run, custom callbacks or trainer logic are required. Ultralytics’ custom trainer documentation provides an example of changing freezing behavior through training callbacks.
Is layer freezing useful for small custom datasets?
Yes, it can be.
Small datasets may not contain enough examples to reliably retrain every model parameter.
Freezing pretrained feature layers reduces the number of parameters that must adapt and can help preserve general visual knowledge.
However, the result should always be compared against full fine-tuning because freezing too much can also reduce accuracy.
Conclusion
Freezing layers in YOLOv8 is a transfer-learning technique that prevents selected model parameters from being updated during training.
Ultralytics provides the freeze parameter directly:
yolo detect train model=yolov8n.pt data=data.yaml freeze=10
or:
model.train(
data="data.yaml",
freeze=10
)
An integer freezes the first N layers, while current Ultralytics Train mode can also accept a list of specific layer indices.
The general strategy is:
Load Pretrained Model
↓
Freeze Selected Layers
↓
Train Remaining Layers
↓
Evaluate Validation Results
↓
Optionally Unfreeze
↓
Fine-Tune Full Model
Freezing can reduce training resource requirements and preserve pretrained features, but too much freezing can prevent the model from adapting to a new dataset.
For best results, inspect the actual model layer indices, start from pretrained weights, compare several freeze configurations, and use validation mAP, precision, recall, training cost, and memory usage to decide whether freezing is beneficial.
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.