The YOLOv8 close_mosaic parameter controls when Mosaic augmentation is turned off near the end of training. Mosaic augmentation is useful because it combines multiple training images into a single composite image, increasing visual diversity and exposing the model to unusual object positions and scales. However, keeping Mosaic active until the final epoch can make the last stage of training less representative of real inference images. Current Ultralytics training settings therefore use close_mosaic=10 by default, which disables Mosaic during the final 10 epochs.
This parameter is not the same as the mosaic augmentation probability. mosaic controls how often Mosaic augmentation is applied while it is active, whereas close_mosaic defines how many final epochs should run without Mosaic. For example, with epochs=200 and close_mosaic=20, Mosaic is disabled after epoch 180 so the final 20 epochs use more natural training images.
Introduction to the YOLOv8 Close Mosaic Parameter
Mosaic is one of the stronger image augmentations commonly used during YOLO training. Instead of training on a single original image, Mosaic creates one training sample from multiple images. Objects can therefore appear in different positions, scales, and contexts within a single batch.
This can improve generalization, especially during the earlier and middle stages of training when the model benefits from high visual diversity. The downside is that Mosaic images are synthetic compositions rather than normal camera images. Their object placement, cropping, and context can differ from what the detector will later see during inference.
The close_mosaic parameter addresses this by dividing training into two practical phases:
Early and Middle Training
→ Mosaic augmentation active
→ stronger visual diversity
Final Training Epochs
→ Mosaic disabled
→ more natural images
→ final fine-tuning
Current Ultralytics documentation explicitly describes close_mosaic as the number of final epochs during which Mosaic augmentation is disabled to stabilize training before completion.
This makes close_mosaic particularly useful in long training runs where the model can first benefit from aggressive augmentation and then spend the final phase refining predictions on image distributions that more closely resemble normal inference inputs.
What Is the Close Mosaic Parameter in YOLOv8?
close_mosaic is an integer training argument that tells Ultralytics how many epochs before the planned end of training Mosaic augmentation should be switched off.
For example:
epochs=100
close_mosaic=10
means Mosaic is active during most of training and disabled for the final 10 epochs.
Similarly:
epochs=200
close_mosaic=20
means Mosaic stops after the first 180 epochs, leaving the final 20 epochs without Mosaic. This exact relationship is documented in the Ultralytics augmentation guide.
The current default value is:
close_mosaic=10
so unless you override it, Ultralytics normally reserves the final 10 epochs for non-Mosaic training.
Purpose of Mosaic Augmentation
Mosaic combines several source images into one training image. This creates a sample containing objects from different scenes, positions, and scales.
Conceptually:
Image A + Image B
+
Image C + Image D
↓
Mosaic Image
The model may see a small object that originally occupied a large portion of one image now appearing in a much smaller region of the Mosaic. It can also see objects close to artificial image boundaries or in contexts that would not normally occur in the original data.
This provides stronger augmentation pressure and helps reduce over-reliance on specific backgrounds or object locations.
Ultralytics treats Mosaic as a configurable augmentation and provides close_mosaic specifically to turn it off near the end of training.
Why Mosaic Is Disabled Near the End of Training
The final stage of training is often used for refinement rather than aggressive exploration.
During early training, heavy augmentation helps expose the detector to a broad range of examples. Near the end, however, training on more natural images can allow bounding-box predictions, class confidence, and localization behavior to adapt more closely to the true data distribution.
Conceptually:
Early Epochs
High Augmentation
↓
Broad Feature Learning
Final Epochs
Mosaic Off
↓
Natural Image Fine-Tuning
Ultralytics describes this final no-Mosaic period as a way to stabilize training before completion.
It is common to see metrics change noticeably after Mosaic closes because the input distribution changes from synthetic composite images back to normal training images. Ultralytics issue discussions also show users observing metric improvements when the dataloader closes Mosaic in the final epochs.
How Close Mosaic Works in YOLOv8
The close_mosaic behavior is tied to the planned number of epochs. Ultralytics knows the configured training duration and turns off Mosaic once training enters the final N epochs specified by close_mosaic.
For instance:
epochs=150
close_mosaic=15
results conceptually in:
Epochs 1–135
→ Mosaic may be active
Epochs 136–150
→ Mosaic disabled
The exact epoch indexing in logs can appear slightly different depending on whether epochs are displayed from zero or one, but the intended behavior is that the final configured number of epochs run without Mosaic.
When Mosaic is closed, Ultralytics’ dataset code does more than just set the Mosaic probability to zero. The current dataset implementation disables mosaic, copy_paste, mixup, and cutmix augmentation probabilities when the close operation is triggered.
Mosaic Augmentation During Early Epochs
During the main part of training, the Mosaic probability is controlled by the mosaic parameter.
For example:
mosaic=1.0
means Mosaic is eligible to be applied with strong frequency while it remains active.
The model therefore receives highly augmented examples containing multiple source images.
This can be useful for:
- increasing scene diversity,
- changing object scale,
- reducing background dependence,
- exposing more objects per training sample.
The close_mosaic setting does not change how strongly Mosaic is used during these earlier epochs. It only controls when the Mosaic phase ends.
Disabling Mosaic in the Final Epochs
Once the final close_mosaic window begins, Ultralytics closes the Mosaic dataloader behavior.
For example:
epochs=100
close_mosaic=10
gives:
Approximately first 90 epochs
→ Mosaic available
Final 10 epochs
→ Mosaic disabled
This behavior is the primary purpose of the parameter.
You may also see a training message similar to:
Closing dataloader mosaic
This is normal behavior rather than a training error. Ultralytics issue guidance confirms that this message indicates the scheduled end of Mosaic augmentation.
Effect on Final Model Fine-Tuning
The no-Mosaic stage allows the detector to spend its final epochs adapting to more natural training images.
During this phase, objects are no longer being artificially combined into four-image composite scenes. The model instead receives image layouts closer to those used during validation or deployment.
This can support better late-stage refinement of:
bounding box localization
class confidence
object scale interpretation
background context
The effect is especially important because strong augmentations can sometimes make training harder even though they improve generalization earlier in the run.
The final no-Mosaic phase attempts to preserve the earlier generalization benefits while giving the model time to settle on the original data distribution.
How to Set Close Mosaic in YOLOv8
close_mosaic is configured as a normal Ultralytics Train mode argument.
The important relationship is between:
epochs
close_mosaic
mosaic
epochs defines the maximum run length, mosaic controls Mosaic augmentation while active, and close_mosaic determines when it stops.
Configure Close Mosaic Using the YOLO CLI
A standard command is:
yolo detect train model=yolov8n.pt data=data.yaml epochs=100 close_mosaic=10
This reserves the final 10 epochs for training without Mosaic.
For a longer period:
yolo detect train model=yolov8n.pt data=data.yaml epochs=200 close_mosaic=20
Mosaic will be disabled during the last 20 planned epochs.
You can also explicitly define the Mosaic probability:
yolo detect train model=yolov8n.pt data=data.yaml epochs=200 mosaic=1.0 close_mosaic=20
Set Close Mosaic in Python
Using the Python API:
from ultralytics import YOLO
model = YOLO("yolov8n.pt")
model.train(
data="data.yaml",
epochs=100,
close_mosaic=10
)
A more complete configuration could be:
model.train(
data="data.yaml",
epochs=200,
imgsz=640,
batch=16,
mosaic=1.0,
close_mosaic=20
)
The same training argument is documented in current Ultralytics Train mode.
Choosing the Number of Final Epochs
There is no universal best number.
Current Ultralytics uses:
close_mosaic=10
as the default, which is a sensible baseline for many standard training runs.
For shorter training runs, the closing window should generally remain proportionate to the total number of epochs.
For example:
epochs=30
close_mosaic=10
means one-third of the full run uses no Mosaic.
That may be too much for some datasets.
A more conservative setting could be:
epochs=30
close_mosaic=5
For a long run:
epochs=300
close_mosaic=20
still leaves most training available for Mosaic while giving enough final epochs for natural-image refinement.
Benefits of Using Close Mosaic
The main benefit is that it combines two different training behaviors in one run.
The first stage uses heavy augmentation to encourage generalization. The second stage reduces synthetic augmentation and allows the detector to refine itself using more realistic image layouts.
This can be more effective than forcing the entire training run to use either aggressive Mosaic or no Mosaic at all.
More Natural Training Images Near the End
Mosaic images are synthetic composites.
Real deployment images are normally not arranged as:
four unrelated images
combined into one frame
Disabling Mosaic allows the final stage to return to normal individual training images.
This reduces the distribution gap between the final training samples and the images likely to be seen during validation or inference.
Better Bounding Box Refinement
Mosaic can place objects near artificial crop boundaries or resize them strongly.
These transformations are useful for learning robust detection, but the final detector still needs accurate boxes on natural image layouts.
The final non-Mosaic epochs provide opportunities to refine:
object boundaries
box center
box dimensions
class confidence
It is reasonable to view this as a fine-tuning phase rather than an entirely different training method.
Improved Final Model Stability
Ultralytics explicitly describes the purpose of disabling Mosaic during the final epochs as helping stabilize training before completion.
After a long period of aggressive augmentation, switching to normal images can reduce the amount of synthetic variation the optimizer must handle.
This may produce smoother final validation behavior, although the actual effect should always be checked on the target dataset.
Close Mosaic vs Mosaic Augmentation
mosaic and close_mosaic are related but control different things.
A useful way to remember the difference is:
mosaic
→ How much Mosaic is used
close_mosaic
→ When Mosaic stops
They should therefore be configured together when you want explicit control over augmentation.
How the Two Parameters Work Together
Suppose:
epochs=100
mosaic=1.0
close_mosaic=10
The training logic is conceptually:
Epochs 1–90:
mosaic probability = 1.0
Final 10 epochs:
mosaic probability = 0
The exact Mosaic application during active epochs still depends on the training pipeline and the configured probability.
When Mosaic Remains Active
Mosaic remains available until the run reaches the final close_mosaic portion.
For:
epochs=200
close_mosaic=20
it remains active for approximately the first 180 epochs.
If:
close_mosaic=0
the automatic closing behavior is disabled, so Mosaic can remain enabled throughout training if mosaic itself is greater than zero. Ultralytics documentation explicitly states that close_mosaic=0 disables the close-Mosaic feature.
When Mosaic Is Turned Off
Mosaic is automatically turned off when the training process enters the final number of epochs specified by:
close_mosaic
For example:
epochs=150
close_mosaic=15
means the final 15 epochs run without Mosaic.
If you do not want Mosaic at all, the clearer configuration is to set:
mosaic=0.0
rather than relying on close_mosaic.
This distinction is important: close_mosaic=0 does not mean Mosaic is disabled from the beginning. It disables the automatic closing behavior. The Mosaic probability itself should be set to zero when you want no Mosaic throughout training.
How Close Mosaic Affects YOLOv8 Training
The effect of closing Mosaic can be visible in training curves because the data distribution changes suddenly.
The model transitions from composite augmented images to normal training images. Losses and metrics may therefore change around the closing epoch.
This is not automatically a sign of a problem.
Impact on Accuracy
Close Mosaic may improve final detection performance when the detector benefits from a final period of natural-image fine-tuning.
A possible pattern is:
Before close:
mAP50-95 = 0.58
After close:
mAP50-95 = 0.61
But this improvement is not guaranteed.
Some datasets may show little change, while others may perform better with Mosaic active longer.
The correct setting should therefore be selected using validation results.
Impact on Validation Performance
Validation typically uses normal images rather than Mosaic composites.
When Mosaic closes, the training distribution becomes more similar to validation.
This can explain why validation metrics sometimes improve noticeably after the close point.
Ultralytics issue reports include users observing metric increases when Mosaic is closed in the final epochs.
The change is expected enough that it should be interpreted as part of the training schedule rather than automatically treated as abnormal behavior.
Effect on Training Loss
Loss can also change after Mosaic is disabled.
Before closing Mosaic, each batch may contain aggressively transformed scenes. After closing, the network sees more natural images.
That means the difficulty and statistical properties of training batches change.
A sudden loss shift near the close point may therefore be normal.
Instead of focusing on one loss value, monitor the complete trend:
box loss
classification loss
DFL loss
validation mAP
precision
recall
Choosing the Best Close Mosaic Value
There is no single close_mosaic value that is best for every YOLOv8 training run.
The default value of 10 is a useful starting point, but the appropriate setting depends on total training duration, dataset size, object complexity, and how useful Mosaic is for that particular dataset.
The goal is to leave enough training time with Mosaic for generalization while preserving enough final epochs without Mosaic for refinement.
Settings for Short Training Runs
For a short run such as:
epochs=30
using:
close_mosaic=10
means one-third of the run has Mosaic disabled.
That may be excessive.
A smaller value such as:
close_mosaic=3
or:
close_mosaic=5
may provide a more balanced experiment.
The correct value should be determined from validation behavior rather than a fixed percentage rule.
Settings for Long Training Runs
For longer runs:
epochs=200
the default:
close_mosaic=10
uses only the final 5% of training without Mosaic.
You might experiment with:
close_mosaic=20
to provide a longer refinement phase.
For example:
yolo detect train model=yolov8n.pt data=data.yaml epochs=200 close_mosaic=20
Dataset Size and Object Complexity
Datasets containing highly variable scenes and object scales may benefit from Mosaic for longer.
Datasets with controlled environments may need less Mosaic.
For example:
Street scenes
many object scales
many backgrounds
→ Mosaic may remain useful longer
while:
Industrial camera
fixed background
fixed object scale
→ Mosaic may be less important
Object complexity also matters. Tiny objects, dense scenes, and large scale variation can make Mosaic more useful than datasets containing a single large object per image.
When Should You Disable Close Mosaic?
Disabling the close-Mosaic behavior means setting:
close_mosaic=0
This does not disable Mosaic itself. It means Ultralytics will not automatically turn Mosaic off in the final epochs.
This may be useful when you intentionally want augmentation behavior to remain consistent throughout training.
Training Without Mosaic Augmentation
If you want no Mosaic from the start, use:
mosaic=0.0
For example:
yolo detect train model=yolov8n.pt data=data.yaml mosaic=0.0
In that situation, close_mosaic is effectively irrelevant because there is no active Mosaic augmentation to close.
Datasets Where Mosaic Is Less Useful
Mosaic may be less useful when:
- scene layouts must remain realistic,
- object scale is highly consistent,
- spatial relationships are important,
- synthetic image boundaries create unrealistic samples,
- the dataset is already extremely diverse.
For example, a fixed industrial inspection camera may always show the same object at nearly the same scale and angle.
Heavy Mosaic could create unrealistic training examples in that environment.
Fine-Tuning a Pretrained Model
If you are fine-tuning a strong pretrained model for only a small number of epochs, you may not want aggressive Mosaic augmentation at all.
For example:
epochs=20
and:
close_mosaic=10
would mean only half the training uses Mosaic.
In short transfer-learning runs, it may be better to reduce mosaic, reduce close_mosaic, or disable Mosaic entirely depending on validation results.
Common Close Mosaic Problems
Most problems come from misunderstanding the relationship between epochs, mosaic, close_mosaic, and early stopping.
The parameter itself is simple, but its effect depends strongly on the rest of the training schedule.
Mosaic Stops Too Early
Suppose:
epochs=50
close_mosaic=20
Mosaic is disabled for 40% of the entire run.
If the model needed longer exposure to strong augmentation, this may reduce its benefit.
Try:
close_mosaic=5
or:
close_mosaic=10
and compare validation results.
Mosaic Remains Active Too Long
If Mosaic remains active until nearly the end, the model gets very little time to adapt to normal images.
For example:
epochs=300
close_mosaic=2
provides only two final epochs without Mosaic.
Increasing the closing period may improve late-stage refinement.
Accuracy Drops After Disabling Mosaic
A temporary drop does not necessarily mean the setting is wrong.
The training distribution changes when Mosaic closes, so the optimizer may need several epochs to adapt.
If accuracy remains lower through the end of training, compare:
close_mosaic=5
close_mosaic=10
close_mosaic=20
using otherwise identical settings.
Incorrect Training Parameter Configuration
One common misunderstanding is:
close_mosaic=0
and expecting Mosaic to be disabled.
Current Ultralytics documentation says the opposite: close_mosaic=0 disables the feature that turns Mosaic off, allowing Mosaic to remain active throughout training if its probability is greater than zero.
To disable Mosaic itself, use:
mosaic=0.0
Another issue involves early stopping. close_mosaic is based on the configured epoch schedule. If early stopping ends the run before the planned final close-Mosaic window, Mosaic may never be disabled. Ultralytics issue discussions document this interaction.
FAQs About YOLOv8 Close Mosaic
What does close_mosaic mean in YOLOv8?
close_mosaic defines how many final training epochs should run with Mosaic augmentation disabled.
For example:
epochs=100
close_mosaic=10
means Mosaic is disabled during the final 10 epochs. Current Ultralytics uses 10 as the default.
What is the purpose of close_mosaic?
Its purpose is to allow the model to train with strong Mosaic augmentation early while finishing training on more natural images.
This provides a final refinement stage and is described by Ultralytics as helping stabilize training before completion.
How many epochs should close_mosaic use?
There is no universal best value.
The current default is:
10
For short training runs, a smaller value may be appropriate.
For long training runs, you may experiment with 10, 20, or another value based on validation performance.
Does close_mosaic improve YOLOv8 accuracy?
It can improve final performance when the model benefits from natural-image fine-tuning near the end.
However, it does not guarantee higher accuracy.
Compare multiple runs using the same:
dataset
epochs
model
batch
imgsz
optimizer
and vary only the close-Mosaic configuration.
Can I disable close_mosaic completely?
Yes.
Use:
close_mosaic=0
This disables the automatic final Mosaic shutdown. Mosaic may then remain enabled throughout training if mosaic is greater than zero.
If you want Mosaic itself disabled throughout training, instead use:
mosaic=0.0
What is the difference between mosaic and close_mosaic?
mosaic controls the Mosaic augmentation probability.
For example:
mosaic=1.0
means Mosaic is strongly enabled while its augmentation phase is active.
close_mosaic determines how many final epochs should have Mosaic turned off.
For example:
close_mosaic=10
means the final 10 epochs train without Mosaic.
Should I use close_mosaic for every YOLOv8 dataset?
Not necessarily.
The default setting is useful for many general-purpose detection datasets, but it should still be treated as a tunable training parameter.
For datasets where Mosaic itself provides little value, you may choose to reduce or disable Mosaic rather than focus on the close-Mosaic window.
Conclusion
The YOLOv8 close_mosaic parameter controls the transition from aggressive Mosaic augmentation to more natural image training near the end of a training run.
Current Ultralytics uses:
close_mosaic=10
by default, meaning the final 10 epochs normally run without Mosaic.
For example:
yolo detect train \
model=yolov8n.pt \
data=data.yaml \
epochs=100 \
mosaic=1.0 \
close_mosaic=10
produces a training schedule conceptually like:
Main Training Phase
↓
Mosaic Augmentation
↓
Final 10 Epochs
↓
Mosaic Disabled
↓
Natural Image Fine-Tuning
↓
Final Model
The two parameters should not be confused:
mosaic
→ controls Mosaic probability
close_mosaic
→ controls when Mosaic stops
A value of:
close_mosaic=0
does not disable Mosaic. It disables the automatic closing behavior, so Mosaic can continue throughout training. To disable Mosaic entirely, use:
mosaic=0.0
This distinction is explicitly documented by Ultralytics.
The best close-Mosaic value depends on total epochs, dataset diversity, object scale, augmentation strength, and training stability. The default of 10 is a strong baseline, but shorter runs may benefit from a smaller closing window while longer runs can justify a longer refinement phase.
For reliable results, compare fixed experiment settings with several close_mosaic values and evaluate final mAP, precision, recall, training loss, and validation behavior rather than assuming one configuration is optimal for every YOLOv8 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.