Cutout is a data augmentation method that fills a square region at a random position in a training image with 0 and trains with the label unchanged. It was proposed by DeVries and Taylor in 2017.
For example, even if part of a "cat" image is hidden by a gray square, the label stays "cat." The model learns to answer from other cues, such as the body shape or fur pattern, even when salient parts like the face or ears are hidden. Parts of objects are often hidden behind other things in real photos too, so this also serves as practice for such cases.
In equations:
x~=Mβx,y~β=y
Here, x is the image, M is a mask that is 0 only inside the square and 1 elsewhere, and β is element-wise multiplication. The ground-truth label y is not changed.
The paper positions Cutout as "dropout on the input image with an added spatial prior that nearby pixels are dropped together." The key point is that it removes a contiguous region rather than individual pixels.
The authors first tried a method that targets the locations of strongly activated features. However, simply erasing a fixed-size square at a random position performed about as well, so they adopted the simple random method as Cutout.
Procedure
During training, the following is done for each image (left side of the diagram at the top).
Normalize the whole dataset with per-channel mean and standard deviation so that the mean is 0.
If standard augmentations such as cropping and horizontal flipping are used, apply them first.
Choose one center point for the square uniformly from all pixels in the image.
Fill the inside of a square with side L pixels centered at that point with 0. Any part that sticks out of the image is simply discarded (the square is not shifted to fit inside the image).
Train as usual with a loss such as cross-entropy, without changing the label.
Cutout is used only during training. At evaluation and inference time, the original images are fed in as is, and no output rescaling like that of dropout is done. The processing can run on the CPU during data loading, so if it runs in parallel with GPU training, training time hardly increases.
Normalize the data to zero mean before filling with 0. In a normalized image, 0 is the "average color," so the filled region does not badly distort the statistics used by batch normalization and similar layers. If you fill with 0 while the values are still in 0 to 1, the region becomes pure black.
Allowing the square to stick out of the image is essential for good performance. When the center is near the edge, the erased area is smaller (right side of the diagram at the top). The paper explains that it is important for the model to occasionally see "mostly visible images" during training. If the square is not allowed to stick out, applying Cutout with only 50% probability and leaving the rest as original images gives similar performance.
Choosing the square size
The only hyperparameter is the side length L of the square. In the paper, size mattered more than shape (square or circle), so squares were used in all experiments.
The paper held out 10% of the training data for validation and chose L by grid search. Accuracy rose as L grew, then fell beyond a certain size, eventually becoming worse than without Cutout (an inverted-U trend). The chosen sizes were as follows.
On CIFAR-100, which has many classes and requires fine distinctions between similar classes, a smaller square than for CIFAR-10 worked better. The paper suggests that in fine-grained tasks, small details matter more than the surrounding context.
Why it works
The paper gives the following two reasons why Cutout works.
The model relies less on a few features: Because it must answer correctly even when salient parts are erased, it learns to also use the context of the whole image and other features. Examining the feature magnitudes of a ResNet-18 trained on CIFAR-10 showed that the model trained with Cutout had more features activated in deeper layers.
Erasing at the input removes the region consistently in later layers: When dropout is applied to convolutional layers, nearby pixels carry similar information, so the dropped information leaks back from neighboring pixels and the effect weakens. Cutout erases an entire region at the input stage, so that part of the object disappears from all subsequent feature maps. In this respect, the paper describes Cutout as closer to a data augmentation that "creates images with new appearances" than to "adding noise."
As an everyday analogy, it is like practicing guessing what is in a photo while covering part of it with your palm. If you always look at the same spot to answer, you cannot answer when that spot is covered.
Results reported in the paper
Test error rates on CIFAR and SVHN (%, mean of 5 runs; 3 runs for Shake-Shake) are as follows. "+" indicates results that also use the standard augmentation of cropping and horizontal flipping.
Wide ResNet already uses batch normalization, dropout, and data augmentation, but adding Cutout lowered the error further. On STL-10 (96 Γ 96), which has only 5,000 training images, Wide ResNet's error also dropped from 23.48% to 20.77% without augmentation and from 14.21% to 12.74% with augmentation.
Other papers have compared it as well. In the ImageNet experiments of the CutMix paper (ResNet-50, 112 Γ 112 square), the top-1 error dropped from 23.68% to 22.93%. On the other hand, the same paper found that models pretrained with Cutout sometimes did not improve when used for object detection.
Practical notes
It can backfire when data is scarce. In the AutoAugment paper, training on only 1,000 images from SVHN (Wide-ResNet-28-10) with Cutout (20 Γ 20) worsened the error sharply from 13.2% to 32.5%. With little data, start by trying small squares.
Choose the square size for each dataset using validation data. If it is too large, results are worse than without it.
Because the label is unchanged, the object can be hidden entirely. Using a large square on images with small objects means training on images where the object is not visible at all, with the original label attached.
It can be combined with other regularizers. In the paper, it was effective together with dropout, batch normalization, and Shake-Shake. In the CIFAR-100 experiments of the CutMix paper, even in a setting where Cutout alone did not help, combining it with Label Smoothing lowered the error.
torchvision has no transform named Cutout. The similar transforms.RandomErasing chooses positions so that the rectangle always fits inside the image, and also randomizes the area ratio (scale) and aspect ratio (ratio) each time. The default application probability p is 0.5. To get Cutout as in the paper (a fixed square allowed to stick out), write it yourself as in the implementation example below.
Comparison with similar methods and how to choose
The table below compares methods that "erase part of an image or features" from the same angles.
Method
What is erased
What fills the erased area
Label
Cutout
One square in the input image (fixed size, may stick out)
You want to add regularization easily for image classification first: Use Cutout. Its only hyperparameter is the side length, and it adds almost no computation.
You want the erased pixels to be used for training too, or object localization matters: Use CutMix. Cutout loses the information in the erased region, while CutMix pastes another image there, so no pixels are wasted.
You want to do the same thing inside the network rather than at the input: Use DropBlock. The DropBlock paper describes DropBlock as "a generalization of Cutout applied to every feature map."
Cutout is also used as part of the standard augmentation in the CIFAR experiments of AutoAugment and RandAugment.
PyTorch example
βΆShow code
python
import numpy as np
import torch
import torch.nn as nn
import torch.optim as optim
from torchvision import datasets, transforms
from torch.utils.data import DataLoader
'''
CIFAR-10 image classification (trained with Cutout)
'''
# Hyperparameters
batch_size = 128 # Batch size
epochs = 5 # Number of epochs
learning_rate = 1e-3 # Learning rate
length = 16 # Side length of the square (paper's CIFAR-10 setting; 8 for CIFAR-100)
# Use 'cuda' if available, 'mps' on Apple Silicon, otherwise 'cpu'
device = 'cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu'
class Cutout:
# Same processing as the paper's official implementation (uoguelph-mlrg/Cutout).
# The center is chosen uniformly within the image; parts sticking out are discarded (not shifted to fit inside)
def __init__(self, length, n_holes=1):
self.length = length
self.n_holes = n_holes
def __call__(self, img): # img: normalized [C, H, W] tensor
h, w = img.size(1), img.size(2)
mask = torch.ones(h, w)
for _ in range(self.n_holes):
cy, cx = np.random.randint(h), np.random.randint(w)
y1, y2 = np.clip(cy - self.length // 2, 0, h), np.clip(cy + self.length // 2, 0, h)
x1, x2 = np.clip(cx - self.length // 2, 0, w), np.clip(cx + self.length // 2, 0, w)
mask[y1:y2, x1:x2] = 0.0
return img * mask # The label is unchanged
mean, std = (0.4914, 0.4822, 0.4465), (0.2470, 0.2435, 0.2616)
train_transform = transforms.Compose([
transforms.RandomCrop(32, padding=4), # Standard augmentation (crop, horizontal flip)
transforms.RandomHorizontalFlip(),
transforms.ToTensor(),
transforms.Normalize(mean, std), # Normalize to zero mean first (filling with 0 = filling with the average color)
Cutout(length=length), # Apply after normalization
# To do something similar with torchvision's RandomErasing (differs from the paper in that the rectangle always fits inside the image):
# transforms.RandomErasing(p=1.0, scale=(0.25, 0.25), ratio=(1.0, 1.0), value=0),
# p: application probability (default 0.5), scale: fraction of the image area (16x16 / 32x32 = 0.25),
# ratio: range of aspect ratios (1 for a square), value: fill value. Works only on tensors, so place it after ToTensor
])
test_transform = transforms.Compose([ # No Cutout for evaluation
transforms.ToTensor(),
transforms.Normalize(mean, std),
])
train_dataset = datasets.CIFAR10(root='./data', train=True, download=True, transform=train_transform)
test_dataset = datasets.CIFAR10(root='./data', train=False, download=True, transform=test_transform)
train_loader = DataLoader(train_dataset, batch_size=batch_size, shuffle=True)
test_loader = DataLoader(test_dataset, batch_size=batch_size)
class SmallCNN(nn.Module):
def __init__(self, num_classes=10):
super().__init__()
self.features = nn.Sequential(
nn.Conv2d(3, 32, kernel_size=3, padding=1), # [B, 3, 32, 32] -> [B, 32, 32, 32]
nn.BatchNorm2d(32),
nn.ReLU(),
nn.MaxPool2d(2), # -> [B, 32, 16, 16]
nn.Conv2d(32, 64, kernel_size=3, padding=1), # -> [B, 64, 16, 16]
nn.BatchNorm2d(64),
nn.ReLU(),
nn.MaxPool2d(2), # -> [B, 64, 8, 8]
nn.Flatten(),
)
self.classifier = nn.Linear(64 * 8 * 8, num_classes)
def forward(self, x):
return self.classifier(self.features(x))
model = SmallCNN().to(device)
criterion = nn.CrossEntropyLoss()
optimizer = optim.Adam(model.parameters(), lr=learning_rate)
# Training: Cutout is applied while loading data. Labels are used as is
for epoch in range(epochs):
model.train()
for images, labels in train_loader:
images, labels = images.to(device), labels.to(device)
loss = criterion(model(images), labels)
optimizer.zero_grad()
loss.backward()
optimizer.step()
# Evaluation: check on the original images (no output rescaling either)
model.eval()
correct = 0
total = 0
with torch.no_grad():
for images, labels in test_loader:
images, labels = images.to(device), labels.to(device)
predicted = model(images).argmax(dim=1)
total += labels.size(0)
correct += (predicted == labels).sum().item()
print(f"Test Accuracy: {100 * correct / total:.2f}%")
FAQ
Q. Is Cutout also applied at test or inference time?
A.
No. Cutout is used only during training; at evaluation and inference time, the original images are fed in as is. Unlike dropout, there is no need to rescale outputs at test time either.
Q. What square size should I start with?
A.
In the paper, for 32 Γ 32 images, side lengths of 16 for CIFAR-10, 8 for CIFAR-100, and 20 for SVHN were chosen. Start with about 1/4 to 1/2 of the image side and adjust based on validation results. If it is too large, results are worse than without Cutout.
Q. Are Cutout and Random Erasing the same thing?
A.
The ideas are similar, but they were proposed independently and differ in the details. Cutout fills a fixed-size square with 0 and allows it to stick out of the image. Random Erasing (torchvision's RandomErasing) also randomizes the area and aspect ratio and places the rectangle so that it fits inside the image.