Firoj Paudel

Deep Residual Learning for Image Recognition: A Fresh Look

Analyzing ResNet skip connections, residual formulation F(x) + x, and how identity mappings enable training deep architectures without degradation.

xweight layerreluweight layerF(x)F(x) + xxidentityforwardbackward∂L/∂x ∝ 1 + ∂F/∂x

Originally published on Medium by Firoj Paudel.

Before He et al. introduced Residual Networks (ResNet) in 2015, stacking more layers onto a deep network caused a surprising paradox: training accuracy began to degrade rather than improve, even when overfitting was ruled out.

The Degradation Paradox

If a shallow network achieves a certain performance, a deeper network ought to perform at least as well, because the extra layers could theoretically learn identity mappings. In practice, standard feedforward layers struggle to learn identity functions using unconstrained weight matrices.

Error increasing as the number of layers increases.
Error increasing as the number of layers increases.

The Residual Learning Formulation

Instead of fitting an underlying mapping directly, ResNet reformulates the target as a residual function:

Through shortcut / skip connections, the network only needs to learn the residual error . If an identity mapping is optimal, the optimizer simply drives weights towards zero ().

python
import torchimport torch.nn as nn class ResidualBlock(nn.Module):    def __init__(self, in_channels, out_channels, stride=1):        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.relu = nn.ReLU(inplace=True)        self.conv2 = nn.Conv2d(out_channels, out_channels, kernel_size=3, stride=1, padding=1, bias=False)        self.bn2 = nn.BatchNorm2d(out_channels)                self.shortcut = nn.Sequential()        if stride != 1 or in_channels != out_channels:            self.shortcut = nn.Sequential(                nn.Conv2d(in_channels, out_channels, kernel_size=1, stride=stride, bias=False),                nn.BatchNorm2d(out_channels)            )     def forward(self, x):        residual = self.shortcut(x)        out = self.relu(self.bn1(self.conv1(x)))        out = self.bn2(self.conv2(out))        out += residual  # Skip connection addition        return self.relu(out)
Residual learning: the building block (skip connection).
Residual learning: the building block (skip connection).

Why Skip Connections Change Gradient Highway Dynamics

During backpropagation, the gradient with respect to activation is:

Notice the constant term 1. It guarantees that gradients can flow unimpeded directly from layer to layer , preventing vanishing gradients even in networks exceeding 1,000 layers.

Left: simple identity mapping. Right: projection shortcut.
Left: simple identity mapping. Right: projection shortcut.
Read the full articleon Medium