Convolutional Neural Networks (CNNs)

GATE Relevance: High

Prerequisites

🎯 Learning Objectives

  • Understand the convolution operation on 2-D inputs
  • Compute output dimensions using the formula (W−F+2P)/S + 1
  • Distinguish valid, same, and full padding
  • Count parameters in convolutional and pooling layers
  • Know the key architectures: LeNet, AlexNet, VGG, ResNet

1. Motivation: Why Not Just Use MLPs?

For a 224×224×3 colour image, a fully-connected first hidden layer with 1000 neurons would need:

224 × 224 × 3 × 1000 = 150,528,000 parameters (just in one layer!)

CNNs exploit three key ideas to drastically reduce parameters:

  • Local connectivity: Each neuron connects only to a small spatial region.
  • Parameter sharing: The same filter (kernel) slides across the whole input.
  • Translation equivariance: A feature detected in one location can be detected everywhere.

2. The Convolution Operation

2-D Discrete Convolution

(I * K)[i,j] = ∑m ∑n I[i+m, j+n] · K[m, n]

where I is the input, K is the kernel/filter, and the sums run over the kernel dimensions.

Worked Example: 3×3 Kernel on 5×5 Input

Input I (5×5):             Kernel K (3×3):
1  0  1  2  1             1   0  -1
0  1  0  1  0             0   1   0
1  0  1  0  1            -1   0   1
0  1  0  1  0
1  0  1  0  1

Output[0,0] = 1·1 + 0·0 + 1·(-1) + 0·0 + 1·1 + 0·0 + 1·(-1) + 0·0 + 1·1
            = 1 + 0 - 1 + 0 + 1 + 0 - 1 + 0 + 1 = 1

Output size: (5 - 3 + 0)/1 + 1 = 3 → 3×3 output.

3. Output Size Formula

Output Dimension Formula

O = ⌊(W − F + 2P) / S⌋ + 1

Where:
  W = input width (or height)
  F = filter/kernel size
  P = padding (number of zero-rows/cols added per side)
  S = stride

GATE-Style Calculations

Input WFilter FPadding PStride SOutput O
32501(32−5)/1 + 1 = 28
32521(32−5+4)/1 + 1 = 32 (same)
28302(28−3)/2 + 1 = 13
224732(224−7+6)/2 + 1 = 112

Padding Types

  • Valid (P=0): No padding; output shrinks.
  • Same: P chosen so output size = input size. For odd F with S=1: P = (F−1)/2.
  • Full: P = F−1; output is larger than input.

4. Parameter Counting in Conv Layers

Conv Layer Parameters

Parameters = K × (Cin × F × F + 1)

Where:
  K    = number of filters (output channels)
  Cin = input channels
  F    = filter spatial size
  +1   = bias per filter

Example: First Conv Layer of a Network

Input: 32×32×3 (RGB image). Layer: 16 filters of size 5×5.

Parameters = 16 × (3 × 5 × 5 + 1) = 16 × 76 = 1,216

Compare this to an MLP: 32×32×3 × (output neurons) would be orders of magnitude larger.

5. Pooling Layers

Pooling down-samples spatial dimensions, reducing computation and providing slight translation invariance.

  • Max Pooling: Takes the maximum value in each pooling window.
  • Average Pooling: Takes the mean value in each pooling window.
  • Global Average Pooling (GAP): Averages the entire feature map to a single value per channel.

Pooling Has Zero Learnable Parameters

Pooling layers do not have weights or biases. When asked for parameter counts, pooling always contributes 0.

Max Pool 2×2 with Stride 2

Input (4×4):        After 2×2 max pool:
 1  3  2  4            5  8
 5  6  7  8    →      9  7
 3  2  1  0
 9  8  7  3

Output size: (4 − 2)/2 + 1 = 2 (i.e., 2×2)

6. Landmark CNN Architectures

LeNet-5 (1998, LeCun)

Input 32×32 → Conv 5×5 (6 filters) → Pool 2×2 → Conv 5×5 (16 filters) → Pool 2×2 → FC 120 → FC 84 → 10
∼60K parameters. Used for handwritten digit recognition.

AlexNet (2012, Krizhevsky)

  • First CNN to win ImageNet (15.3% top-5 error).
  • Used ReLU, dropout, data augmentation, GPU training.
  • ∼60M parameters across 5 conv + 3 FC layers.

VGGNet (2014, Simonyan & Zisserman)

  • All 3×3 convolutions with stride 1, padding 1 (same padding).
  • Key insight: Two 3×3 layers have the same receptive field as one 5×5 layer, but fewer parameters (2×9C² vs 25C²).
  • VGG-16: 138M parameters.

ResNet (2015, He et al.)

Residual Connection (Skip Connection)

y = F(x, W) + x

The network learns the residual F(x) = H(x) − x instead of H(x) directly.
  • Solved the degradation problem: deeper networks paradoxically had higher training error.
  • Skip connections allow gradient to flow directly through identity mappings.
  • ResNet-50: 25.6M parameters; won ImageNet 2015 (3.57% top-5 error).

7. GATE-Style Problems

Problem 1: Full Pipeline Parameter Count

A CNN processes 28×28×1 images with:

  1. Conv: 8 filters, 3×3, stride 1, padding 0 → Output: 26×26×8. Params: 8×(1×3×3+1) = 80
  2. MaxPool 2×2 stride 2 → Output: 13×13×8. Params: 0
  3. Conv: 16 filters, 3×3, stride 1, padding 0 → Output: 11×11×16. Params: 16×(8×3×3+1) = 1,168
  4. MaxPool 2×2 stride 2 → Output: 5×5×16. Params: 0
  5. Flatten: 5×5×16 = 400
  6. FC layer to 10 outputs: Params: 400×10 + 10 = 4,010

Total parameters = 80 + 0 + 1,168 + 0 + 4,010 = 5,258

Summary

  • Output size formula: O = ⌊(W − F + 2P) / S⌋ + 1. Memorize this.
  • Conv layer params: K × (Cin × F² + 1). Pooling has zero params.
  • CNNs exploit local connectivity, weight sharing, and translation equivariance.
  • ResNet’s skip connections solve the degradation problem and enable very deep networks.
  • For GATE: practice output-size and parameter-count calculations.