Convolutional layer

Also known as: convolution layer

On this page 8

A convolutional layer is a neural network layer that applies a set of small learnable filters across its input, computing at every position a weighted sum of a local neighborhood to produce output feature maps. In neural networks, it is the defining building block of the convolutional neural network and one of the core components of artificial intelligence for images, audio and other data with a grid-like structure.

Two properties make the convolutional layer powerful: weight sharing, because the same filter is reused at every location, and local connectivity, because each output depends only on a small region of the input. Together they give the layer far fewer parameters than a fully connected layer and a built-in sensitivity to spatial patterns wherever they appear. The term convolution layer is used as a synonym.

How a convolutional layer computes its output

A convolutional layer computes its output by sliding each filter over the input and taking a dot product between the filter weights and the input values beneath it, then adding a bias. For a color image, the input has three channels, and every filter spans all input channels at once, so a 3 x 3 filter on an RGB image actually holds 3 x 3 x 3 weights.

Each filter produces one feature map, and the layer stacks the maps of all its filters into an output tensor whose depth equals the number of filters. Strictly speaking, most deep learning libraries implement cross-correlation rather than mathematical convolution, because the filter is not flipped; since the weights are learned, the distinction has no practical effect.

The output is usually passed through an activation function such as ReLU and, in many architectures, a normalization step. Without the nonlinearity, stacked convolutional layers would collapse into a single linear operation and lose their expressive power.

Key hyperparameters of a convolutional layer

The behavior of a convolutional layer is controlled by a small set of hyperparameters that determine output size, receptive field and computational cost. The table below lists them with typical values in image models.

HyperparameterTypical valuesEffect on the layer
Kernel size1 x 1, 3 x 3, 5 x 5, 7 x 7Size of the local region each output sees
Number of filters32 to 2,048Depth of the output and capacity of the layer
Stride1 or 2Step between positions; 2 halves the spatial size
PaddingValid or sameWhether borders are padded to keep spatial size
Dilation1, 2, 4 or moreGaps inside the kernel that widen its reach
Groups1 up to the channel countSplits channels into independent filter groups
Main hyperparameters and their effects

The spatial output size follows a simple rule: output = (input + 2 x padding – kernel) / stride + 1, rounded down. The number of weights equals kernel height x kernel width x input channels x filters, plus one bias per filter, which does not depend on the image resolution at all.

Variants of the convolutional layer

Several variants of the convolutional layer trade accuracy, cost and flexibility in different ways. They share the core idea of a sliding learnable filter but change its dimensionality or the way channels are combined.

VariantHow it differsTypical use
1D convolutionSlides along a single axisAudio, sensor signals, text sequences
2D convolutionSlides over height and widthImages and spectrograms
3D convolutionAdds a depth or time axisVideo and volumetric medical scans
Pointwise convolutionUses a 1 x 1 kernel to mix channelsChanging channel count cheaply
Depthwise separable convolutionSplits spatial and channel mixingEfficient mobile networks
Transposed convolutionIncreases spatial resolutionDecoders, segmentation, image generation
Dilated convolutionSpaces kernel elements apartLarge context without extra weights
Common variants and where they are used

Depthwise separable convolution illustrates the efficiency gains well. For a 3 x 3 kernel, it needs roughly eight to nine times fewer multiplications than a standard convolution with the same input and output channels, at a modest cost in accuracy.

Convolutional layers compared with other layer types

Convolutional layers differ from fully connected and attention layers mainly in their inductive bias, meaning the assumptions about the data that are built into the architecture. Convolution assumes that nearby values are related and that a useful pattern can appear anywhere.

PropertyConvolutional layerFully connected layerSelf-attention layer
ConnectivityLocal neighborhoodEvery input to every outputEvery position to every position
Weight sharingSame filter at all positionsNoneShared projections, input-dependent weights
ParametersIndependent of input sizeGrow with input sizeIndependent of sequence length
Cost with input sizeLinear in positionsQuadratic in featuresQuadratic in sequence length
Built-in biasLocality and translation equivarianceNoneWeak; relies on positional encoding
Convolutional, fully connected and attention layers

The convolutional layer is translation equivariant: shifting the input shifts the feature map by the same amount. A pooling layer or strided convolution adds partial translation invariance, which helps classification but discards exact position. Vision transformers can outperform convolutional networks with very large datasets, while convolutions remain more data-efficient on smaller ones.

Receptive field and stacking depth

The receptive field of a unit is the region of the original input that can influence it, and it grows as convolutional layers are stacked. Two stacked 3 x 3 layers see a 5 x 5 region, and three see a 7 x 7 region, while using fewer weights and more nonlinearities than a single large kernel.

This stacking explains the hierarchy of features in deep networks. Early layers detect edges and color contrasts, middle layers combine them into textures and parts, and deep layers respond to whole objects. Very deep stacks depend on residual connections and normalization to train reliably, because otherwise gradients weaken as they pass backward through many layers.

Common mistakes when designing convolutional layers

Most problems with convolutional layers come from mismatched shapes, aggressive downsampling or misplaced assumptions about the data. The following table links frequent symptoms to their causes and fixes.

SymptomLikely causeFix
Shape mismatch errorsWrong padding or stride arithmeticRecompute output size with the formula
Small objects missedToo much early downsamplingReduce stride or add skip connections
Checkerboard artifactsUneven overlap in transposed convolutionUse resize followed by convolution
Slow inference on devicesMany full 3 x 3 convolutionsUse depthwise separable layers
Poor results on tabular dataNo spatial structure to exploitUse a multilayer perceptron or tree model
Symptoms, causes and fixes

In everyday language

A convolutional layer works like a small magnifying glass that scans a picture one patch at a time. At each spot it asks the same question. Is there a vertical edge here? It writes the answer onto a new map.

The network uses many such magnifying glasses at once. Each one looks for a different pattern. The same glass is reused everywhere, so the network can recognize a pattern no matter where it appears. It also needs far fewer settings to learn than if it looked at every pixel separately.

Seen in the real world

A manufacturer of printed circuit boards uses a camera on its assembly line to catch defects such as missing components and solder bridges. The inspection model receives 512 x 512 grayscale images and starts with a convolutional layer of 32 filters of size 3 x 3, followed by further layers that double the filter count while halving the resolution with stride 2.

The first trained layers respond to edges and small bright spots, and deeper layers recognize whole solder joints. Because the factory computer has no large graphics card, the engineers replace most standard layers with depthwise separable convolutions, cutting computation substantially with only a small drop in validation accuracy.

The result is an inspection step that processes each board in well under a second and flags suspicious areas for a human operator, reducing the number of defective boards that reach final testing.