Dropout Layer
A dropout layer randomly zeroes a fraction of activations during training so a network cannot rely on any single unit, which reduces overfitting.
A dropout layer is a regularization component of a neural network that randomly sets a fraction p of its inputs to zero at every training step and passes all values through unchanged at inference. Because any unit can vanish at any step, the network cannot depend on a few specific neurons or on fragile co-adaptations between them, so it learns redundant features that generalize better and overfit the training data less. Geoffrey Hinton and colleagues introduced the technique in 2012, and Srivastava, Hinton, et al. described it in full in 2014. It is a built-in layer in PyTorch, TensorFlow, and most other deep learning frameworks, used in architectures from fully connected classifier heads to transformers.
How Dropout Works#
During training, the layer samples a fresh random mask for every forward pass, keeping each element with probability 1 − p and zeroing it with probability p. Each step therefore trains a different thinned subnetwork, and the full network used at test time approximates an average over the exponentially many subnetworks that share its weights, which is why dropout is often described as cheap ensemble training. To keep the expected activation the same in both phases, modern frameworks use inverted dropout: surviving values are multiplied by 1 / (1 − p) during training, so the layer does nothing at inference. In PyTorch, nn.Dropout follows the module's training or evaluation mode:
import torch
from torch import nn
torch.manual_seed(0)
dropout = nn.Dropout(p=0.5)
x = torch.ones(10)
# Training mode: about half the values are zeroed and survivors are scaled by 1 / (1 - p) = 2
dropout.train()
print("Train:", dropout(x))
# Evaluation mode: the layer passes every value through unchanged
dropout.eval()
print("Eval: ", dropout(x))In training mode six of the ten values are dropped and the four survivors become 2.0, keeping the expected value at 1.0; in evaluation mode all ten values stay 1.0.
Common Dropout Variants#
- Spatial Dropout: PyTorch's
nn.Dropout2dzeroes entire feature-map channels, which suits convolutional networks because neighboring pixels within a channel are strongly correlated and dropping single pixels barely regularizes them. - Stochastic Depth (DropPath): Instead of individual activations, whole residual branches are skipped at random for each sample, a standard ingredient in training Vision Transformers and modern CNNs.
- Monte Carlo Dropout: Dropout stays active at inference, and the model runs several forward passes on the same input. The spread of the predictions gives a low-cost estimate of model uncertainty for safety-critical systems, a method Gal and Ghahramani interpreted as approximate Bayesian inference.
- DropConnect: Random individual weights are zeroed instead of activations, giving each connection its own mask.
Dropout in Practice#
Dropout rates are tuned like any other hyperparameter. Srivastava et al. found that dropping hidden units with probability 0.5 worked well across a wide range of networks and tasks, while input units do best with retention closer to 1, and the original Transformer used p = 0.1. Too high a rate slows convergence and can cause underfitting, and placing dropout directly before batch normalization can hurt accuracy through a train-to-test variance shift. Many convolutional neural networks rely mainly on batch normalization, data augmentation, and weight decay, keeping dropout for the classifier head. Ultralytics YOLO26 classification models follow that pattern: they contain one dropout layer, between the pooled 1,280-channel features and the final linear classifier, whose rate the dropout training argument sets (0.0 by default).
from ultralytics import YOLO
# Load a YOLO26 classification model, whose head contains the dropout layer
model = YOLO("yolo26n-cls.pt")
# Train with 10% dropout in the classification head on a small MNIST subset
results = model.train(data="mnist160", epochs=10, imgsz=64, dropout=0.1)Real-World Applications#
- Medical Image Analysis: Labeled scans are expensive, so diagnostic classifiers are often fine-tuned from a pretrained backbone on a few thousand images. Dropout in the classifier head limits how much the head memorizes individual cases from such a small set.
- Natural Language Processing: Transformer encoders such as BERT apply dropout with probability 0.1 on all layers, including the attention weights, during pre-training and fine-tuning.
Dropout vs. Related Techniques#
- Batch Normalization: Batch normalization standardizes each layer's inputs to stabilize training and adds only mild noise from batch statistics, without removing any units.
- Label Smoothing: Label smoothing regularizes through the training targets, softening one-hot labels, and leaves every activation intact.
- Pruning: Pruning permanently removes low-importance weights to make a model smaller, while dropout's zeroing lasts a single training step and leaves the parameter count unchanged.










