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

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.

  • 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.

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