AI, But Simple

Convolutional Neural Networks, Explained Mathematically

Free editionPRO edition

Convolutional Neural Networks (CNNs) are a special type of neural network designed to process grid-like data, such as images.

They have revolutionized the computer vision space with their high performance and efficient architecture.

They are particularly effective for image classification tasks due to their ability to capture patterns through convolutional layers.

We’ve gone through the concept, terms, and basics of CNNs in previous issues, so in this one, we’ll focus more on the mathematical process (explained simply).

If you want to read those issues (which are highly recommended), you can find them here:

To explain how the math behind a CNN works, we’ll go through a worked example using the CIFAR-10 dataset for image classification.

CIFAR-10 consists of 60,000 color images, each of size 32×32 pixels with 3 color channels (RGB), categorized into 10 distinct classes such as airplanes, cars, birds, cats, etc.

The CNN architecture we will cover today is picked quite arbitrarily, but with some purpose. We’ll shape the CNN into blocks (convolution, activation, pooling), which is quite effective.

The CNN architecture we’re using has the following layers:

  1. Input Layer: 32×32×3 RGB image.

  2. Block 1

    1. Convolutional Layer 1 (Conv1)

    2. Activation Function: ReLU.

    3. Pooling Layer 1 (Pool1): Max pooling.

  3. Block 2

    1. Convolutional Layer 2 (Conv2)

    2. Activation Function: ReLU.

    3. Pooling Layer 2 (Pool2): Max pooling.

  4. Flatten Layer: Converts the 3D tensor to a 1D vector.

  5. Fully Connected Layer (FC): 512 neurons.

  6. Activation Function: ReLU.

  7. Output Layer: 10 neurons (one for each class) with softmax activation.

If you remember from a previous issue, the standard CNN block contains convolutional layers with a stride of 1 and a padding of 1 (which maintains the resolution), followed by a nonlinearity (activation function, usually ReLU), then a pooling layer to reduce the resolution.

  • In our CNN, we use the same type of block to better fit the data.

Let’s get started with the forward propagation.

The input is composed of a tensor of size 32×32×3 (height, width, and depth). We’ll call this tensor X.

This edition is for PRO members.

More in Architecture

Architecture 30
  1. #120 Architecture

    Recursive Self-Improvement, Ternary 27B Model for Laptops, Jev Architecture

  2. #117 Architecture PRO edition

    How DeepSeek’s Architecture Actually Works

  3. #115 Architecture PRO edition

    BDH-CQ: A 150M model just broke the ARC-AGI cost curve