Convolutional Neural Networks Explained: From Parameter Explosion to ResNet

This article explains convolutional neural networks from first principles, detailing convolution operations, pooling, key parameters, and a PyTorch implementation, while tracing historic models from LeNet to ResNet that shaped modern computer vision.

Code Archaeology
Code Archaeology
Code Archaeology
Convolutional Neural Networks Explained: From Parameter Explosion to ResNet

1. Convolutional Neural Networks

1.1 The Problem with Fully Connected Networks

The previous section introduced fully connected neural networks, where every neuron in one layer connects to all neurons in the next. In computer vision, this causes a parameter explosion. For example, a 4096×3424 RGB image from a Mate60 camera yields 42,074,112 input features. With just 1,000 hidden neurons, the parameter count exceeds 42 billion. Converting to grayscale or compressing images only patches the problem.

1.2 Convolution Operation

In computer vision, input is a three-dimensional tensor : width, height, and channels (1 for grayscale, 3 for RGB). The learnable parameters are convolution kernels and biases , also called filters.

Convolution visualization
Convolution visualization

Convolution acts like a scanner: the kernel slides over the input, and at each position it computes a weighted sum of the covered pixels plus bias, then applies an activation function to produce one output pixel. Intuitively, each output pixel represents a larger, more abstract receptive field than a single input pixel.

The computation is not matrix multiplication but element-wise multiplication of kernel weights with corresponding input pixels, summation across all channels and spatial positions, addition of bias, and activation . For multi-channel input, the kernel must have matching depth. To produce multiple output channels, define multiple filters — each adds another dimension of abstract features.

Deep networks gain representational power from depth; CNNs also gain breadth by increasing channel count.

1.3 Key Parameters

Kernel size : typically 3×3, also 5×5 or 7×7.

Stride : step size of kernel sliding, usually 1.

Padding : zeros added around the border to mitigate reduced computation at edges.

With these defined, output spatial dimensions can be calculated.

1.4 Pooling Layers

Besides convolutional layers, CNNs use pooling layers . Max pooling takes the maximum value in each window ; stride typically equals window size. Pooling reduces spatial size and suppresses noise without changing the number of channels . Average pooling computes the window mean instead.

2. A PyTorch Example

Combining the above elements yields a CNN. The following CNNModel processes a 128×128×3 input:

class CNNModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.model = nn.Sequential(
            nn.Conv2d(in_channels=3, out_channels=16, kernel_size=3, padding=1),
            nn.ReLU(),
            nn.MaxPool2d(kernel_size=2, stride=2),

            nn.Conv2d(in_channels=16, out_channels=32, kernel_size=3, padding=1),
            nn.ReLU(),
            nn.MaxPool2d(kernel_size=2, stride=2),

            nn.Conv2d(in_channels=32, out_channels=64, kernel_size=3, padding=1),
            nn.ReLU(),
            nn.MaxPool2d(kernel_size=2, stride=2),

            nn.Conv2d(in_channels=64, out_channels=128, kernel_size=3, padding=1),
            nn.ReLU(),
            nn.MaxPool2d(kernel_size=2, stride=2),

            nn.Conv2d(in_channels=128, out_channels=1, kernel_size=1),  # 1x1 convolution
            nn.AdaptiveAvgPool2d((1, 1)),  # global average pooling
            nn.Flatten(),
            nn.Sigmoid()
        )

    def forward(self, x):
        return self.model(x)

Conv2d: 16 kernels 3×3, padding 1 → 128×128×16

MaxPool2d: 2×2 kernel, stride 2 → 64×64×16

Conv2d: 32 kernels 3×3, padding 1 → 64×64×32

MaxPool2d: 2×2 kernel, stride 2 → 32×32×32

Conv2d: 64 kernels 3×3, padding 1 → 32×32×64

MaxPool2d: 2×2 kernel, stride 2 → 16×16×64

Conv2d: 128 kernels 3×3, padding 1 → 16×16×128

MaxPool2d: 2×2 kernel, stride 2 → 8×8×128

Conv2d: 1 kernel 1×1 → 8×8×1 (1×1 convolution)

AdaptiveAvgPool2d: global average pooling → 1×1×1, flattened to scalar

Sigmoid for binary classification

The 1×1 convolution and global average pooling adapt the output to match the final activation's input requirements . For 10-class classification, use 10 1×1 kernels followed by Softmax.

3. Historic Models

LeNet (Yann LeCun): First successful real-world CNN application, developed for US Postal Service.

AlexNet (Geoffrey Hinton): Its success moved deep learning from academia to industry, prompting Google, Facebook, etc. to adopt neural networks.

GoogLeNet (Google): Introduced multi-scale parallel convolutions and 1×1 convolutions.

VGGNet (Google): Standardized 3×3 kernels and 2×2 max pooling.

ResNet (Kaiming He): Residual learning enabled training of extremely deep networks.

Geoffrey Hinton and Yann LeCun received the 2018 Turing Award.

References: AlphaGo project: https://deepmind.google/research/projects/alphago/ Turing Award: https://simple.wikipedia.org/wiki/Turing_Award
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Computer VisionDeep LearningPyTorchResNetAlexNetConvolutional Neural NetworksLeNetPooling Layers
Code Archaeology
Written by

Code Archaeology

Learn from the past to understand the present

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.