FromZero2AI
CoursesPlaygroundBlog
Support on Ko-fi
Neural Networks & Deep Learning • Module B: Seeing the World (Computer Vision)Lesson 4: Convolutional Neural Networks (CNNs)
PreviousNext

Lesson 4: Convolutional Neural Networks (CNNs)

Learn how filters and pooling layers extract visual features from images.

Built with AI for beginners. Free forever.

Support on Ko-fi•About•Blog•Privacy Policy•Terms of Service

Standard fully connected networks fail when processing high-dimensional data like images because they ignore spatial relationships. Convolutional Neural Networks (CNNs) solve this by looking at local pixel blocks.

The Convolutional Layer

The core of a CNN is the Convolutional Layer. Instead of connecting every pixel to every neuron, a sliding matrix called a Kernel (or filter) traverses the image. As it slides, it performs dot products on local region matrices, highlighting spatial features like edges, textures, or shapes.

Kernel Properties: Stride and Padding

  • Kernel Size: The spatial dimensions of the filter (commonly 3×3 or 5×5).
  • Stride: The step size of the kernel as it slides across the image. A stride of 1 moves the kernel one pixel at a time; a stride of 2 skips one pixel, shrinking the output dimensions.
  • Padding: Adding border pixels (usually zeros) around the image to allow the kernel to inspect edge pixels without shrinking the output image size.
Interactive: Sliding Kernel Simulator
Output size formula:
O = ((I − K + 2·P) / S) + 1 = ((5 − 3 + 2·0) / 1) + 1 = 3
Output feature map: 3 × 3
Input 5×5
2
7
3
1
5
0
4
8
6
2
9
1
5
3
7
4
6
0
8
1
3
2
9
4
6
Kernel 3×3
Click cells to edit
Output 3×3
·
·
·
·
·
·
·
·
·

Downsampling with Pooling

Pooling layers reduce the spatial size of representation matrices to cut down parameters and computational load. The most popular method is Max Pooling, which slides a filter across the output and selects the maximum value from each block, keeping only the most dominant features.

Interactive: Max Pooling Visualizer

A 2×2 pooling window with stride 2 slides across the 4×4 input, selecting the maximum value in each region.

Input 4×4
6
3
2
8
1
9
4
5
7
2
6
1
3
8
0
4
→
Output 2×2
·
·
·
·

Exercise: Convolutional Math

Calculate the output spatial size (O) for a convolution operation with the following settings:

Input size (I): 32 × 32
Kernel size (K): 3 × 3
Stride (S): 1
Padding (P): 0
Formula: O = ((I − K + 2·P) / S) + 1
  • 32 × 32
  • 30 × 30
  • 28 × 28

Next, we will apply convolutional concepts in a project where we train a model on real images!