Residual Networks (ResNet)
A residual network (ResNet) adds each block's input to its output through a skip connection so very deep networks train. Covers blocks, variants, and code.
A residual network (ResNet) is a deep convolutional neural network (CNN) built from residual blocks, in which a shortcut connection adds each block's input to the block's output. Each block therefore learns only a correction to its input, which lets networks with 50, 152, or more than 1,000 layers train reliably. Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun of Microsoft Research introduced ResNet in the 2015 paper Deep Residual Learning for Image Recognition, and an ensemble of residual networks won the ILSVRC 2015 classification task with a 3.57% top-5 error on ImageNet. Residual connections have since become a standard part of most deep architectures, including transformers and real-time object detectors.
The Degradation Problem#
Before ResNet, adding layers to a plain stack of convolutions eventually made results worse. The ResNet authors showed that a 56-layer plain network had higher training error than a 20-layer one, so overfitting could not explain the drop. The deeper network could match the shallow one by setting its extra layers to the identity, yet gradient descent did not find that solution. The authors called this the degradation problem. The vanishing gradient problem had already been largely addressed by normalized weight initialization and batch normalization, so deep plain networks did converge, only to worse solutions.
How Residual Blocks Work#
A residual block computes y = F(x) + x, where x is the block's input and F is a small stack of layers, typically two or three convolutions with batch normalization and ReLU. If the best mapping for the block is close to an identity mapping, the layers only need to push F toward zero, which is far easier than learning the identity from scratch. The shortcut also gives gradients a direct path backward through every block. Identity shortcuts add no parameters and almost no computation. When a block changes the number of channels or downsamples with a stride of 2, x no longer matches the shape of F(x), and a 1×1 convolution projects the shortcut to the new shape.
ResNet-18 and ResNet-34 stack this basic two-convolution block. ResNet-50, ResNet-101, and ResNet-152 use a bottleneck block of three convolutions: a 1×1 convolution reduces the channels, a 3×3 convolution processes them, and a second 1×1 convolution restores them, which keeps deep models affordable. ResNet-50 has about 25.6 million parameters. The original paper also trained a 1,202-layer network on CIFAR-10 to under 0.1% training error, although its 7.93% test error was worse than the 6.43% of a 110-layer network, a gap the authors attributed to overfitting on the small dataset.
Variants of ResNet#
- Pre-activation ResNet: A 2016 follow-up by the same authors moved batch normalization and ReLU before each convolution, leaving the shortcut path as a pure identity, and trained a 1,001-layer network on CIFAR-10.
- ResNeXt: Splits each bottleneck into many parallel low-width paths, called cardinality, which raises accuracy at the same computational cost.
- Wide ResNet: Uses fewer, wider blocks, showing that width can substitute for some depth.
- Modernized ResNets: ConvNeXt (2022) updated the ResNet design with larger kernels, layer normalization, and GELU activations to compete with vision transformers.
Using a Pretrained ResNet#
Pretrained ResNets remain common baselines and backbones for transfer learning. The torchvision ResNet models ship with ImageNet weights and matching preprocessing, so classifying an image takes a few lines:
import urllib.request
import torch
from torchvision.io import decode_image
from torchvision.models import ResNet50_Weights, resnet50
# Load ResNet-50 with ImageNet weights and its matching preprocessing
weights = ResNet50_Weights.DEFAULT
model = resnet50(weights=weights).eval()
preprocess = weights.transforms()
# Download and decode a sample image
data = urllib.request.urlopen("https://ultralytics.com/images/bus.jpg").read()
image = decode_image(torch.frombuffer(bytearray(data), dtype=torch.uint8))
# Classify the image and report the most likely ImageNet class
with torch.no_grad():
probs = model(preprocess(image).unsqueeze(0)).softmax(dim=1)
score, index = probs.max(dim=1)
print(f"{weights.meta['categories'][index.item()]}: {score.item():.2f}")It prints minibus: 0.25, the closest of ImageNet's 1,000 classes to the city bus in the photo. For a custom task, replacing the final fully connected layer and fine-tuning on new labels reuses the features the residual stages learned on ImageNet.
ResNet vs. Related Architectures#
- Plain networks such as VGG: VGG stacks 3×3 convolutions without shortcuts and tops out at 19 weight layers. ResNet-152 is eight times deeper with lower complexity than VGG-19.
- Highway networks: Developed concurrently with ResNet, they add learned gates that can close the shortcut. ResNet's identity shortcuts are never closed and add no parameters.
- DenseNet: Concatenates the outputs of all earlier layers in a block instead of adding one shortcut, which reuses features at the cost of growing channel counts.
- U-Net: Its skip connections carry encoder feature maps across to the decoder and concatenate them there, linking distant stages instead of wrapping individual blocks.
- Vision transformers (ViT): Replace convolutions with self-attention but keep residual connections around every attention and feed-forward sublayer, as every transformer does.
Residual Connections in Modern Models#
The residual idea outlived the specific ResNet architectures. Every layer of a large language model (LLM) adds its attention and feed-forward outputs back to a running residual stream, and most CNN detectors build their backbones from residual blocks. In YOLO26, the C3k2 blocks are built from bottleneck modules that return x + F(x) whenever input and output channels match, and the Ultralytics package also includes configurations of Baidu's RT-DETR with ResNet-50 and ResNet-101 backbones. The ResNet paper won the CVPR 2016 Best Paper Award, and a 2025 Nature analysis ranked it the most-cited paper of the twenty-first century.










