Deep Learning

Convolutional Neural Networks

How small sliding convolutional filters extract spatial features from images.

🟡 intermediate5 min readarchitecturesvision
Convolutional Neural Networks (CNNs) are specialized deep learning architectures designed for 2D and 3D grid data like images and video. Instead of using dense fully connected layers that flatten spatial layouts, CNNs slide small feature filters over input pixels to extract local spatial patterns. Key building blocks include Convolutional Layers for feature extraction, Activation Layers for non linearity, Pooling Layers for spatial downsampling, and Dense Layers for final predictions.

What is a Convolutional Neural Network?

If you flatten a $1024 \times 1024 \times 3$ color image into a 1D vector, you get 3,145,728 numbers.

Connecting this vector to a simple dense layer with 1000 neurons requires over 3 billion weight parameters for a single layer!

Worse, flattening destroys 2D spatial relationships. An eye in the top left corner becomes completely disconnected from neighboring cheek pixels.

Convolutional Neural Networks (CNNs) solve this using sliding local filters that preserve 2D spatial relationships while reusing weight parameters across the entire image.

  Input Image (32x32x3) ──► [ Sliding 3x3 Filter ] ──► Feature Map (32x32x64) ──► [ Max Pool 2x2 ] ──► (16x16x64)

How 2D Convolution Works

A Convolutional Layer slides a small 2D weight matrix (like a 3x3 filter) across the input image.

At each position:

  1. Multiply filter weights by overlapping image pixels.
  2. Sum the results together.
  3. Write the sum to a single spot in the output Feature Map.
  3x3 Image Subregion             3x3 Convolution Filter          Output Value
  ┌───┬───┬───┐                   ┌───┬───┬───┐
  │ 1 │ 0 │ 1 │                   │ 1 │ 0 │-1 │
  ├───┼───┼───┤         *         ├───┼───┼───┤         ──►       ( 1*1 + 0*0 + 1*-1 ... ) = 4
  │ 0 │ 1 │ 0 │                   │ 1 │ 0 │-1 │
  └───┴───┴───┘                   └───┴───┴───┘

Because the exact same 3x3 filter weights slide across the entire image, the layer uses very few parameters while detecting patterns wherever they appear (Translation Invariance).

The Core CNN Layers

  1. Convolutional Layer: Extracts local features like edges, lines, textures, and shapes.
  2. Activation Layer (ReLU): Applies non linear activation to feature maps.
  3. Pooling Layer (Max Pooling): Downsamples spatial width and height to reduce memory and provide small spatial translation tolerance.
  4. Dense Output Layer: Takes final flattened feature maps to output class predictions.

Feature Hierarchy

CNN layers naturally build a hierarchical understanding of visual data:

  1. Early Layers: Detect simple low level features like horizontal edges, color contrasts, and diagonal lines.
  2. Middle Layers: Combine simple edges to detect complex textures, curves, corners, and object parts like wheels or eyes.
  3. Deep Layers: Combine object parts to recognize full concepts like cars, dogs, or human faces.

Say this out loud

CNNs process images using sliding local filters that preserve 2D spatial relationships while sharing weight parameters across the image. Early layers detect simple edges, middle layers combine edges into textures and shapes, and deep layers recognize full objects. Convolutional layers provide local spatial locality and translation invariance.

Followups to expect

  1. What is Stride in convolution? Stride is the step size the filter moves as it slides across the image. Stride 1 moves 1 pixel at a time; stride 2 skips every other pixel, downsampling spatial output dimensions by half.
  2. What is Padding? Adding zero pixels around image borders so edge pixels receive equal filtering and output spatial dimensions match input size.

Check yourself

Question 1 of 3

Why are standard fully connected Dense layers unsuitable for processing high resolution input images like 1024x1024 pixels?

More in Deep Learning

See all →
Activation Functions4 minDropout4 minBackpropagation5 min