Skip to main content
Informatik.uz
Master’s · Year 2Chapter 1. Deep learning

Convolutional Neural Networks (CNN)

Convolutional layers, filters, pooling and CNN architecture: how a network learns the spatial structure of images. You will meet LeNet and ResNet, data augmentation and transfer learning.

Topic 1 of 22 min readUpdated October 27, 2026
All topics (1 of 2)

If an image is fed into an ordinary fully connected network, the number of parameters becomes excessive: a 224 × 224 color image has 150528 input values, and with 1000 neurons in the first layer about 150 million weights are needed. Such a network also ignores the spatial arrangement of pixels: neighboring pixels are treated the same as distant ones. Convolutional neural networks (CNN) solve this problem with local connections and weight sharing.

A convolutional layer slides a small filter (a kernel, for example 3 × 3) across the image, multiplies the pixels by the filter weights at each position, sums them and produces a feature map. The same filter is applied to the whole image, so there are few parameters and an object can be found wherever it appears in the image. Filters are not set by hand but learned during training: the first layers detect edges and corners, deeper ones detect shapes and parts of objects. Strictly speaking, libraries implement cross-correlation, but by tradition the operation is called convolution.

The main hyperparameters of a convolution are the filter size, the stride and the padding. If the input size is n, the filter f, the padding p and the stride s, the output size equals floor((n + 2*p - f) / s) + 1; for example, with n = 32, f = 5, p = 0 and s = 1 the output is 28. A pooling layer (most often 2 × 2 max pooling) shrinks the feature map, reduces computation and increases tolerance to small shifts. The result of a convolution is usually passed through a ReLU activation.

A typical CNN stacks blocks of convolution, ReLU and pooling, and at the end a fully connected layer and softmax produce class probabilities. Yann LeCun’s LeNet-5 (1998) recognized handwritten digits; AlexNet (2012) won the ImageNet competition by a wide margin and started the era of deep learning; ResNet (2015) made it possible to train networks of hundreds of layers with residual (skip) connections. When data is scarce, data augmentation and transfer learning, that is, adapting a pretrained model to a new task, are used.

Key takeaways

  • Thanks to local connections and shared weights, a CNN uses far fewer parameters than a fully connected network.
  • A convolutional layer with learnable filters builds a feature map; features become more complex with depth.
  • The output size is found with the formula floor((n + 2*p - f) / s) + 1.
  • Pooling reduces the size and increases tolerance to small shifts.
  • When data is scarce, augmentation and transfer learning help.

Practice tasks

  1. Calculate by hand: for a 5 × 5 image and a 3 × 3 filter (padding = 0, stride = 1) find the output size, then compute the top-left element of the output with a filter of your choice.
  2. In PyTorch build a small network from Conv2d(1, 8, kernel_size=3), ReLU, MaxPool2d(2) and a linear layer, train it on MNIST for a few epochs and measure the accuracy on the test set.
  3. Load the pretrained resnet18 model (torchvision), replace the last layer and train only that layer on a small image set of two or three classes; compare the result with a network trained from scratch.

Review questions

Test yourself: think first, then reveal the answer.

  1. 1Why is a CNN preferable to a fully connected network for images?
    Thanks to local connections and shared weights, a CNN uses far fewer parameters, accounts for spatial structure and finds an object anywhere in the image.
  2. 2What is the output size if a 5 × 5 filter is applied to a 32 × 32 image with `padding = 0` and `stride = 1`?
    28 × 28, because 32 - 5 + 1 = 28.
  3. 3What is transfer learning?
    Adapting a model pretrained on a large dataset (for example, ImageNet) to a new, smaller task.

0 of 2 topics completed

Sign in to mark
Convolutional Neural Networks (CNN) | Informatik.uz