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

Data Augmentation

Data augmentation trains models on randomly transformed copies of existing images, such as flips, crops, and color shifts, so they generalize better.

Data augmentation increases the variety of a training dataset by applying random transformations, such as flips, crops, rescaling, color shifts, and image mixing, to the examples it already contains. Each transformed copy keeps its original label, so the model learns that an object stays the same object under changes in viewpoint, lighting, and position. Collecting and labeling new images is slow and expensive, which makes augmentation the cheapest defense against overfitting, and nearly every modern computer vision model trains with it.

How Data Augmentation Works#

Most training pipelines augment online: the data loader transforms each image as it builds a batch, drawing new random parameters every time, so each epoch sees a different version of every image. Offline augmentation instead writes a fixed number of transformed copies to disk before training, which multiplies storage and gives the model far fewer distinct variants.

Two rules keep augmentation from corrupting the data. First, labels must move with the pixels: in object detection, instance segmentation, and pose estimation, a geometric transform has to update every bounding box, mask, and keypoint, and a horizontal flip also swaps left and right keypoints. Second, the transform must be one the real world could produce: vertical flips suit aerial and microscope images, while for street scenes they create upside-down cars that never appear at inference time. Torchvision's transforms handle the first rule automatically when boxes are passed alongside the image:

from urllib.request import urlopen

from PIL import Image
from torchvision import tv_tensors
from torchvision.transforms import v2

image = Image.open(urlopen("https://ultralytics.com/images/bus.jpg"))  # 810 x 1080 pixels
boxes = tv_tensors.BoundingBoxes([[50, 400, 250, 900]], format="XYXY", canvas_size=(1080, 810))

# Flip every time (p=1.0) and shift colors; the box must move with the pixels
augment = v2.Compose([v2.RandomHorizontalFlip(p=1.0), v2.ColorJitter(brightness=0.4, saturation=0.7)])
new_image, new_boxes = augment(image, boxes)

print(f"Original box: {boxes.tolist()}")
print(f"Flipped box:  {new_boxes.tolist()}")

The box around the man on the left of the image moves from [50, 400, 250, 900] to [560, 400, 760, 900], mirrored across the 810-pixel width, while the color jitter changes the pixels without touching the box.

Common Techniques#

  • Geometric transforms: Flips, rotations, scaling, translation, cropping, shearing, and perspective warps simulate different camera positions and object sizes.
  • Photometric transforms: Changes to brightness, contrast, saturation, and hue, plus blur and noise, simulate different lighting, sensors, and image quality.
  • Occlusion: Random erasing and cutout blank out rectangles so the model cannot rely on any single part of an object.
  • Image mixing: MixUp blends two images and their labels, CutMix pastes a patch from one image into another, mosaic tiles four images into one training sample, and copy-paste moves segmented objects onto new backgrounds.
  • Automated policies: RandAugment applies a random sequence of transforms controlled by just two settings, the number of transforms and their strength, which removes the costly search that earlier learned policies needed.

Augmentation Pipelines for Object Detection#

Detection pipelines chain several transforms, each applied with its own probability, so every training image receives a different random combination.

Ultralytics YOLO training runs this pipeline by default, with mosaic on every image (mosaic=1.0), a 50% chance of a horizontal flip (fliplr=0.5), up to ±50% scaling, and HSV color shifts, and it turns mosaic off for the final 10 epochs (close_mosaic=10) so the model finishes on complete, natural-looking images.

from ultralytics import YOLO

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

# fliplr: horizontal flip probability; scale: zoom range (+/- 70%); degrees: rotation range (+/- 5)
results = model.train(data="coco8.yaml", epochs=10, fliplr=0.5, scale=0.7, degrees=5.0)

During this run, the YOLO26 trainer saves its first three augmented batches as train_batch0.jpg, train_batch1.jpg, and train_batch2.jpg, with boxes drawn, so the effect of each setting can be checked before committing to a long run.

  • Synthetic data: Generated from scratch with rendering engines, simulators, or diffusion models. Augmentation modifies real images that already exist.
  • Data preprocessing: Deterministic steps such as resizing and normalization applied identically to every image during training and inference. Augmentation is random and runs only during training.
  • Test-time augmentation (TTA): Runs inference on several augmented versions of the same input, such as flipped and rescaled copies, and merges the predictions, trading extra compute for a small accuracy gain.

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