Notes

Convolutional Layer

A convolutional layer is a pattern detector that scans across structured data using a small window. Instead of treating every input position as unrelated, it looks for the same useful pattern wherever that pattern appears—an edge, a corner, a short sequence motif, or another local arrangement of values.

How the layer computes features

A layer contains learnable kernels (also called filters): small grids of weights, such as 3×3. Each kernel slides across the input and computes a weighted sum at every location, producing a feature map. A kernel that becomes sensitive to a particular pattern produces strong activations where that pattern occurs. For multi-channel input, such as an RGB image or the output of an earlier layer, each kernel spans all input channels; its results are summed before adding a bias.

  • Stride controls the step size of the scan. Larger strides reduce output size and computation.
  • Padding adds border values, usually zeros, so edge information is not discarded and spatial size can be preserved.
  • The number of kernels determines the number of output channels: more channels let the layer learn more kinds of features.
Why shared weights matter

Unlike a fully connected layer, a convolutional layer reuses one kernel at every position. This weight sharing sharply reduces parameter count and gives translation equivariance: shifting an input pattern shifts the corresponding activation rather than requiring the network to relearn it elsewhere. Stacking layers expands the receptive field, so later units combine local detections into larger structures. In PyTorch, this is typically torch.nn.Conv2d.

Training consequences

During backpropagation, every location where a kernel was applied contributes to the gradient for its shared weights. This makes each update draw evidence from many positions, which is efficient but can amplify unstable activations when learning rates are too high. A practical convolution block commonly combines Conv2d, normalization, and a nonlinearity; without the nonlinearity, stacked convolutions collapse into a single linear operation. Excessive stride or repeated downsampling can erase fine detail, while too little downsampling raises memory and compute costs because large feature maps must be stored for gradients.

A convolutional layer applies a set of learnable kernels across an input’s spatial or grid dimensions, producing feature maps that detect local patterns. Each kernel shares the same weights at every position, while stride, padding, and channel mixing determine output shape and receptive field. This parameter sharing makes networks efficient and enables learned features to remain responsive when patterns shift position.

Imagine looking at a large photo through a small movable window. At each spot, you ask a simple question: “Do I see an edge here? A corner? Part of an eye?” A convolutional layer gives an AI many such tiny windows, each trained to notice a particular visual clue.

Because the same window checks every part of the image, it can recognize a feature wherever it appears: a cat’s ear in the top corner or the middle of the picture. Early layers often spot basic shapes and colors. Later layers combine those clues into bigger ideas, such as faces, cars, or animals. This makes image-reading AI far more practical and efficient.