Skip to content
IT glossary
Data and MLUpdated December 3, 2026

Convolutional neural network

Свёрточная нейросеть

This type of neural network learns filters that detect patterns in small regions of its input. It reuses each filter across locations, so it can pick up a feature such as an edge wherever it appears in an image.

Also known as: CNN

What is a convolutional neural network?

Imagine building a model that recognizes handwritten digits. A useful clue, such as a short vertical stroke, might be near the left edge of one image and in the middle of another. A convolutional neural network (CNN) can look for that clue in both places with the same filter. The model learns the filter weights during training rather than relying on a programmer to write a detector for each kind of stroke.

From input pixels to feature maps

A convolutional layer takes a small window of the input, multiplies its values by the corresponding filter weights, and adds up the products, typically along with a learned bias. It repeats this calculation at each window position. In a standard convolution on an RGB image, a filter with a 3 × 3 spatial footprint has weights for all three color channels. One filter produces one feature map: a grid showing how strongly that filter responds at each position.

Stride is the distance between successive window positions. Padding adds values, often zeros, around the input so the layer can place windows closer to the edges. A CNN typically applies a nonlinear activation such as ReLU after convolution. It may also reduce the size of feature maps through pooling or a convolution with a larger stride. As layers are stacked, a unit can draw on a larger part of the original input, known as its receptive field. That lets deeper layers combine responses to simple patterns into features that describe larger shapes.

Worked example: reading a layer's output

import torch
from torch import nn

layer = nn.Conv2d(3, 16, kernel_size=3, stride=1, padding=1)
images = torch.randn(8, 3, 32, 32)
features = layer(images)  # shape: (8, 16, 32, 32)

PyTorch's Conv2d reads this tensor as batch size, channels, height, and width. The batch still has eight images, but each now has 16 feature maps instead of three color channels. With a 3 × 3 kernel, one pixel of padding on each side and a stride of one preserve the spatial dimensions. Running this snippet does not train a model; it only shows what the layer outputs for a given input shape.

Uses and common misconceptions

CNNs can classify a whole image, locate objects with bounding boxes, or label individual pixels in a segmentation mask. The same idea works in one dimension: a filter can slide along an audio waveform or a time series. Sharing weights does not make a CNN automatically invariant to translation. Shifting an object can shift the corresponding response on a feature map, and the final prediction can still change, especially near image boundaries or when the network downsamples the input. Rotation and scale invariance are not guaranteed either.

What interviewers ask

A common follow-up is to count the parameters in the example layer. Each output channel has 3 × 3 × 3 weights and one bias, so the total is 16 × (27 + 1) = 448. The key distinction is that weights are shared across positions, not across filters. A larger image therefore does not add weights to this layer, but it does require more work because the layer evaluates each filter at more positions.