ResNet Explained: Solving Deep Neural Network Problems with Residual Learning
How Skip Connections Enabled Ultra-Deep Neural Networks to Train Effectively
To overcome the challenges of training very deep neural networks. Residual Networks (ResNet) was introduced, which uses skip connections that allow the model to learn residual mappings instead of direct transformations make deep neural networks easier to train
- It helps prevent vanishing gradient problems in very deep models.
- Skip connections let information flow directly across layers
- ResNet enables building networks with hundreds or even thousands of layers.
- It is widely used in computer vision tasks like image classification and object detection

A residual block lets the network skip layers by adding the original input to the processed output, making deep networks easier to train.
Challenges in Deep Neural Networks
Deep Neural Networks are useful models but they also come with several traning challenges, especially as the network depth increases.
Two major issues are
1. Vanishing/Exploding Gradient Problem: As the number of layers in a neural network increases, the gradients of the loss function with respect to the weights can become extremely small or excessively large during backpropagation.
2. Degradation Problem: The degradation problem occurs when increasing the network depth does not improve performance and may even worsen it. This problem has two aspects:
- Performance Plateau: Training error saturates after a certain depth meaning additional layers do not significantly reduce the error.
- Accuracy Degradation: Beyond a certain depth validation error increases and the model performs poorly on unseen data.
Understanding ResNet
ResNet is a deep learning architecture designed to train very deep networks efficiently using residual connections. Here are the key features of ResNet:
- Residual Connections: Enable very deep networks by allowing gradients to flow through identity shortcuts, reducing the vanishing gradient problem.
- Identity Mapping: Simplifies training by learning residual functions instead of full mappings.
- Depth: Supports extremely deep architectures for improved image recognition performance.
- Fewer Parameters: Achieves high accuracy with fewer parameters hence improving computational efficiency.
- Results: Delivers top performance on benchmark image recognition tasks.
- Effective Approach: Residual connections provide a reliable way to train deeper networks effectively, enabling networks to learn mode complex features.

- Left graph (training error): The 56 layer network reduces error slowly and shows strong fluctuations due to vanishing gradients, whereas the 20-layer network learns smoothly and reaches a much lower training error.
- Right graph (test error): The 56-layer network maintains a higher test error (degradation problem), while the 20-layer network generalizes better showing why ResNet skip connections are essential for training deep models.
ResNet-34
ResNet-34 is a deep residual network built on a 34-layer plain network inspired by VGG-19, with shortcut connections forming 16 residual blocks.

Here are the different stages of the ResNet-34 architecture, showing its structured arrangement of residual blocks.
- First set: 3 residual blocks each with 2 convolution layers of 64 filters and identity skip connections.
- Second set: 4 residual blocks each with 2 convolution layers of 128 filters uses zero-padding or 1x1 projections for dimension changes.
- Third set: 6 residual blocks, each with 2 convolution layers of 256 filters.
- Fourth set: 3 residual blocks with 2 convolution layers of 512 filters each.
- Feature map: Passed through Global Average Pooling a dense layer with 1000 neurons and softmax for classification.
How ResNet Works
Conventional networks try to learn the full mapping H(x)H(x). ResNet instead learns a residual function and combines it with the input via a skip connection.
where:
- x: input to the block
- H(x): desired mapping
- F(x): residual function to be learned
Learning the simpler residual F(x) makes optimization easier.
1. Residual Block: A Residual Block contains:
- One or more convolutional layers
- A skip connection that bypasses these layers
- Addition of input to convolution output
- This ensures uninterrupted flow of information and gradients

2. Skip (Shortcut) Connection
- Bypasses one or more layers
- Adds input directly to output
- Prevents vanishing gradients
- Improves parameter updates
3. Handling Dimension Mismatch: When input and output dimensions differ
- Zero Padding: Adds extra zeros to the input to match output dimensions in a residual block
- Linear Projection: Uses a learnable 1x1 convolution to match input and output dimensions for the skip connection.
3. Stacking Residual Blocks : Multiple residual blocks can be stacked to create deep architectures. This allows networks to go very deep without suffering from degradation.
4. Global Average Pooling (GAP): Before the final fully connected layer ResNet uses GAP:
- Converts each feature map to a single value by averaging
- Reduces parameters less overfitting
- Produces compact feature representation
Step-By-Step Implementation
Here we implement ResNet (v1 and v2) for CIFAR-10. We will cover data preprocessing, model creation, training and plotting graphs step by step.
Step 1: Import Libraries
Step 2: Set Hyperparameters
- Set batch_size, epochs, num_classes and data_augmentation
- Choose ResNet version and number of residual blocks
- Compute depth based on CIFAR ResNet rules
Step 3: Load and Preprocess CIFAR-10 Data
- Load CIFAR-10 dataset using Keras.
- Normalize pixel values to range [0, 1].
- Optionally subtract the dataset mean for zero-centered input.
- Convert labels to one hot vectors.
Step 4: Defining Learning Rate
Here we will define learning rate for our model.
Step 5: Define a ResNet Layer Function
- Defines a single convolutional layer optionally followed by BatchNorm and ReLU.
- conv_first applies convolution first
Step 6: Define ResNet v1
- Uses 2 layer residual blocks for each residual unit
- Computes number of residual blocks
- Adds identity or projection shortcuts when feature map dimensions change
- Ends with Global Average Pooling and Dense softmax layer
Step 7: Define ResNet v2
- Uses 3 layer bottleneck residual blocks.
- Handles identity or projection shortcuts for dimension matching.
- Ends with BatchNorm ,ReLU, GAP, Dense, softmax.
Step 8: Compile the Model
- Instantiate v1 or v2 based on version.
- Compile with Adam optimizer, categorical_crossentropy and accuracy metric.
Step 9: Setup Callbacks
- ModelCheckpoint saves the best model.
- LearningRateScheduler adjusts learning rate during training.
- ReduceLROnPlateau reduces LR if validation performance plateaus.
Step 10: Data Augmentation & Training
- Uses ImageDataGenerator for real time augmentation if enabled.
- history variable stores training metrics for plotting.
Output:

The model shows smooth convergence with increasing training accuracy, stable validation accuracy and decreasing losses. A small accuracy gap suggests mild overfitting but overall performance on CIFAR-10 is strong.
ResNet Results on ImageNet and COCO
On the ImageNet dataset, the authors used a 152-layer ResNet, which is 8 times deeper than VGG-19 but still has fewer parameters. An ensemble of these ResNets achieved only 3.7% error on the ImageNet test set. On the COCO object detection dataset ResNet also produced a 28% relative improvement due to its very deep feature representation.

The results show that shortcut connections effectively address the problems caused by increasing network depth as increasing layers from 18 to 34 leads to a decrease in error rate on the ImageNet validation set unlike plain networks.

Below are the results on ImageNet Test Set. The 3.57% top-5 error rate of ResNet was the lowest and thus ResNet architecture came first in ImageNet classification challenge in 2015.

Advantages
- Eases Training of Deep Networks: Skip connections allow gradients to flow directly through the network, reducing vanishing gradient problems.
- Enables Very Deep Architectures: ResNet can train networks with 50, 100 or even 152+ layers effectively.
- Improves Accuracy: Residual learning helps the network achieve higher performance on tasks like image classification and object detection.
- Reduces Degradation: Adding more layers does not increase training error unlike plain deep networks.
- Fewer Parameters for Better Efficiency: Deep ResNets can have fewer parameters than traditional deep networks but performing better.
Challenges
- High Computation: Requires high computational power due to deep architecture.
- Dimension Mismatch: Dimension mismatch in skip connections needs extra projection layers.
- Overfitting Risk: Risk of overfitting on small datasets because of large model capacity.
- Training Instability: Training can become unstable without proper batch normalization.
- Redundant Updates: Residual blocks may learn only small or redundant updates.
- Deep Network Degradation: Gradient flow improves but may still degrade in extremely deep networks.
First Lesson
You are at the beginning of this curriculum.
Latest Tutorial
More chapters coming soon to this topic.
Leave a Reply
Share your insights, questions, or solutions with the developer community.

Discussion
0No comments yet
Be the first to share your thoughts, question a concept, or provide additional tips!