Search Knowledge

© 2026 LIBREUNI PROJECT

Machine Learning / Deep Learning

Convolutional Neural Networks

Convolutional Neural Networks

Convolutional Neural Networks (CNNs) are specialized neural architectures designed to process grid-structured data, such as images, by exploiting spatial hierarchies.

Convolutional Layers

Unlike fully connected layers where neurons connect to all inputs, convolutional layers connect only to a local receptive field.

Filters and Feature Maps

A layer applies learnable filters (kernels). As a filter slides, it computes dot products, producing a feature map.

Output Dimension Formula

Given input height HinH_{\text{in}}, filter size FF, padding PP, and stride SS, the output height HoutH_{\text{out}} is:

Hout=HinF+2PS+1H_{\text{out}} = \lfloor \frac{H_{\text{in}} - F + 2P}{S} \rfloor + 1

  • Padding (PP): Adding zero-pixels around the border to preserve spatial dimensions.
  • Stride (SS): The step size of the filter as it slides across the input.

Translation Invariance

CNNs build translation invariance: if a pattern (like a cat’s ear) is learned in one part of the image, the convolutional filters can recognize it anywhere else. This parameter sharing significantly reduces model parameter counts compared to MLPs.

Pooling Layers

Pooling layers reduce the spatial size of feature maps to decrease parameter counts and build translation invariance.

  • Max Pooling: Extracts the maximum value from each receptive patch.
  • Average Pooling: Computes the average value of each patch.

ResNet and Residual Connections

Deep CNNs suffer from vanishing gradients. ResNet resolves this using Residual Connections (skip connections) that bypass layers:

a(l)=ϕ(W(l)a(l1)+b(l)+a(l1))a^{(l)} = \phi(W^{(l)} a^{(l-1)} + b^{(l)} + a^{(l-1)})

This allows gradients to flow directly backward, enabling the training of deep networks.

Example: Output Shapes

The following example calculates the output dimensions of a convolutional layer:

python

Interactive Lab

Calculate the output dimensions of a Convolutional Layer based on input dimension, filter size, padding, and stride. Edit these parameters to see how layer sizes transition.

Step 1
Inspect the idea
Step 2
Edit the program
Step 3
Run and compare

Exercise

Test your understanding of CNN operations:

What is the primary purpose of pooling layers in a CNN?

Receptive Fields and Hierarchies

Early layers detect simple edges, while deeper layers combine these features to recognize complex shapes and objects, building a hierarchical spatial representation.

References & Further Reading