Explain ResNet Architecture and Its Variants

Title: This figure is taken from “Deep Residual Learning for Image Recognition” which compares VGG-19 and a 34-layer plain neural network to the proposed residual network

Source: He et al., 2016
Title: Comparing VGG-19 (19.6 billion FLOPS), 34-parameter layer plain neural network (3.6 billion FLOPS) and 34-parameter layer (3.6 billion FLOPS) residual network. The dotted shortcuts increase dimensions
Source: “Deep Residual Learning for Image Recognition” Paper by He et al., 2016

Introduction

ResNet (Residual Network) is a convolutional neural network architecture introduced by Kaiming He et al. at Microsoft Research in their 2015 paper “Deep Residual Learning for Image Recognition” [1]. The architecture won first place in the ImageNet Large Scale Visual Recognition Challenge (ILSVRC) 2015 with a 3.57% top-5 error rate, using a network with 152 layers, eight times deeper than VGG nets [2] but with lower computational complexity.

Before ResNet, training very deep networks was considered impractical. Networks with more than 20-30 layers would often perform worse than their shallower counterparts, not due to overfitting, but due to optimization difficulties. ResNet solved this problem with a simple yet profound innovation: skip connections (also called residual connections) that allow gradients to flow directly through the network.

The influence of ResNet extends far beyond image classification. The residual connection design has become a fundamental building block in modern deep learning, appearing in architectures as diverse as Transformers [3], BERT, GPT, and diffusion models. Understanding ResNet is essential for anyone working with deep neural networks.

The Degradation Problem

Before examining ResNet’s solution, we must understand the problem it solves. In theory, a deeper network should perform at least as well as a shallower one. If the additional layers are not needed, they could simply learn the identity function (output equals input), effectively reducing to the shallower network.

In practice, this does not happen. Researchers observed a counterintuitive phenomenon: adding more layers to a network often made it perform worse, even on training data. This is not overfitting, since training error also increases. He et al. termed this the degradation problem.

Title: The degradation problem. A 56-layer plain network has higher training error than a 20-layer network, despite having more capacity. 
Source: He et al., 2016
Title: The degradation problem. A 56-layer plain network has higher training error than a 20-layer network, despite having more capacity. 
Source: “Deep Residual Learning for Image Recognition” Paper by He et al., 2016

This finding was surprising because it contradicted the intuition that more layers should provide more representational power. ResNet’s key insight was that the problem was not with depth itself, but with how deep networks were being optimized.

Residual Learning: The Core Innovation

ResNet addresses the degradation problem by reformulating the learning objective. Instead of asking each layer to learn a desired mapping H(x), ResNet asks layers to learn the residual F(x) = H(x) – x. The output becomes:

y = F(x)+x

This is implemented by adding a skip connection that bypasses one or more layers and adds the input directly to the output. If the optimal transformation is close to identity, the network only needs to learn F(x) ≈ 0, which is much easier than learning a full identity mapping.

For a detailed explanation of how residual connections solve the vanishing gradient problem, see the article on residual connections.

ResNet Architecture Variants

ResNet comes in several sizes, distinguished by the number of layers: ResNet-18, ResNet-34, ResNet-50, ResNet-101, and ResNet-152. The architecture follows a consistent pattern across all variants, differing primarily in the number of residual blocks at each stage.

The BasicBlock (ResNet-18 and ResNet-34)

ResNet-18 and ResNet-34 use the BasicBlock as their fundamental building unit. Each BasicBlock contains two 3×3 convolutional layers with batch normalization:

Python
class BasicBlock(nn.Module):
    """Basic residual block for ResNet-18/34."""
    expansion = 1

    def __init__(self, in_channels, out_channels, stride=1, downsample=None):
        super().__init__()
        self.conv1 = nn.Conv2d(in_channels, out_channels, kernel_size=3,
                              stride=stride, padding=1, bias=False)
        self.bn1 = nn.BatchNorm2d(out_channels)
        self.conv2 = nn.Conv2d(out_channels, out_channels, kernel_size=3,
                              stride=1, padding=1, bias=False)
        self.bn2 = nn.BatchNorm2d(out_channels)
        self.downsample = downsample

    def forward(self, x):
        identity = x

        out = F.relu(self.bn1(self.conv1(x)))
        out = self.bn2(self.conv2(out))

        if self.downsample is not None:
            identity = self.downsample(x)

        out += identity  # The skip connection
        return F.relu(out)

The downsample parameter handles cases where the input and output dimensions differ. When the number of channels increases or spatial dimensions decrease (via stride > 1), a 1×1 convolution projects the input to match the output dimensions, allowing the addition to proceed.

The Bottleneck Block (ResNet-50 and deeper)

The bottleneck design reduces computational cost while maintaining representational capacity, making very deep networks practical.

Block TypeLayersParameters (64 channels)Computational Cost
BasicBlock2 x 3x3 conv73,72873,728 multiplies
Bottleneck1x1 + 3x3 + 1x169,63269,632 multiplies
Title: Comparision of the proposed ResNet block types
Source: Deep Residual Learning for Image Recognition Paper by He et al.

ResNet-18 Layer Organization

ResNet-18 consists of an initial convolution followed by four stages of residual blocks:

StageOutput SizeStructureChannels
Conv1112 x 1127x7 conv, stride 264
MaxPool56 x 563x3 max pool, stride 264
Stage 156 x 562 BasicBlocks64
Stage 228 x 282 BasicBlocks128
Stage 314 x 142 BasicBlocks256
Title: ResNet-18 architecture breakdown showing the progression of spatial dimensions and channel counts through each stage.
Source: Deep Residual Learning for Image Recognition Paper by He et al.

The total layer count comes from: 1 (initial conv) + 16 (eight BasicBlocks, each with 2 conv layers) + 1 (fully connected) = 18 layers. Hence the name ResNet-18.

Plain Network vs ResNet: Experimental Evidence

The original paper included a critical experiment comparing plain networks (without skip connections) to ResNets of equivalent depth. The results demonstrated the degradation problem and ResNet’s solution:

Plain Networks:

  • 18-layer plain network: achieves reasonable performance 
  • 34-layer plain network: higher training AND test error than 18-layer
  • Demonstrates degradation problem in action

Residual Networks: 

  • 18-layer ResNet: comparable to 18-layer plain 
  • 34-layer ResNet: lower error than 18-layer ResNet 
  • Deeper networks consistently improve performance

Performance on ImageNet

ModelLayersTop-1 ErrorTop-5 ErrorParameters
VGG-191924.40%7.10%144M
ResNet-181827.90%9.00%11.7M
ResNet-343424.50%7.40%21.8M
ResNet-505022.90%6.70%25.6M
ResNet-15215221.40%5.70%60.2M
Title: Comparison of ResNet variants on ImageNet classification.
Note that ResNet-152 achieves better performance than VGG-19 with fewer parameters.
Source: Deep Residual Learning for Image Recognition Paper by He et al.

This experiment proved that skip connections, not just careful initialization or batch normalization, were essential for training very deep networks. The plain networks used the same training procedures, learning rates, and regularization as the ResNets, isolating the effect of the residual connections.

Legacy and Impact

ResNet’s influence extends far beyond image classification:

Training Ultra-Deep Networks: ResNet enabled training of networks with 100, 200, and even 1000+ layers, demonstrating that depth could be scaled almost arbitrarily with proper architecture design.

Foundation for Modern Architectures: The residual connection design appears in virtually every modern deep learning architecture. Transformers [3] use residual connections around both self-attention and feed-forward layers. Without these connections, training large language models like GPT and BERT would be impractical.

Transfer Learning Backbone: Pre-trained ResNet models became the standard backbone for transfer learning in computer vision. Features learned on ImageNet transfer effectively to tasks ranging from medical imaging to autonomous driving.

Architectural Experimentation: ResNet inspired numerous variants including ResNeXt (grouped convolutions), Wide ResNet (wider layers, fewer depth), DenseNet (dense connections), and SE-ResNet (channel attention).

Summary

The ResNet (Residual Network) architecture, introduced in 2015, revolutionized deep learning by enabling the practical training of ultra-deep convolutional neural networks. 

The core problem ResNet solved was the degradation problem, where simply adding more layers to a network led to worse performance, even on training data. ResNet addressed this through the introduction of residual connections. Instead of forcing layers to learn a difficult direct mapping, ResNet reformulates the objective to learn a residual mapping F(x) = H(x) – x. If optimal learning is close to the identity function, the network only needs to learn $F(x) \approx 0$, which is significantly easier to optimize. 

The architecture comes in various depths (e.g., ResNet-18, ResNet-50) utilizing either a BasicBlock (for shallower nets) or a more computationally efficient Bottleneck Block (for deeper nets). ResNet achieved state-of-the-art performance on ImageNet and its foundational residual connection design has since been integrated into nearly every modern deep learning model, including Transformers, making it an essential building block in modern AI.

Video Explanations

  • This video, “ResNet – Explained!” by CodeEmporium provides a visual walkthrough of the ResNet architecture, the degradation problem, and how skip connections solve it. (Runtime: 16 mins)
YouTube video
“ResNet – Explained!” by CodeEmporium
  • This video, “Deep Residual Learning for Image Recognition (Paper Explained)” by Yannic Kilcher offers an in-depth 31-minute walkthrough of the original paper, covering experimental results and architectural details. (Runtime: 31 mins)
YouTube video
“Deep Residual Learning for Image Recognition (Paper Explained)” by Yannic Kilcher

References

  1. He, K., Zhang, X., Ren, S., & Sun, J. (2016). “Deep Residual Learning for Image Recognition”. CVPR 2016. arXiv:1512.03385
  2. Simonyan, K., & Zisserman, A. (2015). “Very Deep Convolutional Networks for Large-Scale Image Recognition” (VGG). ICLR 2015. arXiv:1409.1556
  3. Vaswani, A., et al. (2017). “Attention Is All You Need”. NeurIPS 2017. arXiv:1706.03762

Author

Help us improve this post by suggesting in comments below:

– modifications to the text, and infographics
– video resources that offer clear explanations for this question
– code snippets and case studies relevant to this concept
– online blogs, and research publications that are a “must read” on this topic

Leave the first comment

Partner Ad
Find out all the ways that you can
Contribute