convolutional layer
A convolutional layer is the basic building block of a CNN: a bank of many small learnable filters that all slide over the same input, each producing its own output grid. If one filter is a single pattern detector, a convolutional layer is a whole committee of detectors — one might fire on horizontal edges, another on a particular color blob, another on a corner — and the layer stacks all their answers together. Early layers learn simple patterns (edges, textures); deeper layers, fed by the answers of earlier ones, learn compound patterns (eyes, wheels, text).
Precisely, a 2D convolutional layer maps an input tensor of shape (C_in, H, W) — C_in channels, height H, width W — to an output of shape (C_out, H_out, W_out). It holds C_out filters, each of shape (C_in, k, k), plus one bias per filter. Each filter spans all input channels and produces exactly one output channel (one feature map). The number of learnable parameters is C_out times (C_in times k times k) plus C_out biases — crucially independent of H and W, because the same filter is reused at every spatial position. The spatial output size follows H_out = floor((H + 2P - d(k-1) - 1) / S) + 1, where P is padding, S is stride, and d is dilation (same formula for width).
A layer's behaviour is set by a handful of hyperparameters: kernel size k (how big a neighbourhood each filter sees), number of output channels C_out (how many distinct features to learn), stride S (how far the filter hops, which downsamples), padding P (border handling, which controls output size), and dilation d (gaps in the kernel, which enlarge the receptive field). A convolutional layer is almost never used alone: it is typically followed by a normalization step (such as batch normalization) and a nonlinearity (such as ReLU), and this conv-norm-activation triple is the unit that gets stacked dozens or hundreds of times in architectures like VGG and ResNet.
A Conv2d(in=3, out=16, kernel=3, stride=1, padding=1) on a 3x224x224 RGB image outputs 16x224x224: 16 feature maps, same spatial size (padding 1 with kernel 3 preserves it), and 3*16*9 + 16 = 448 parameters.
Why it matters: parameter count is independent of input resolution. A 3x3 layer with 64 input and 128 output channels has 64*128*9 + 128 = 73,856 parameters whether the image is 32x32 or 4000x3000. This weight sharing is what lets one trained CNN run on images of many sizes and is the root of its data efficiency compared with fully-connected networks.