CNNs

Convolution and weight sharing — how a network learns spatial features without a separate weight per pixel

Why

A fully connected layer treats every pixel as an independent feature, so it has no notion that nearby pixels are related and no way to reuse a pattern learned in one part of the image elsewhere. CNNs fix both problems, which is why they're still the default for vision even in the transformer era. "Why does weight sharing help?" is the standard follow-up — know the parameter-count and translation-invariance argument, not just the definition.

Intuition

A filter is a small pattern detector — an edge, a curve, a texture — that slides across the image and produces a high response wherever that pattern appears. Because the same filter is reused at every position, the network learns "vertical edge" once and can detect it anywhere in the image, instead of learning it separately for the top-left corner and the bottom-right corner.

Explanation
Convolution and the feature map
Filter (kernel): a small learned matrix, e.g. 3×3 Convolution: slide the filter over the image, at each position compute a weighted sum (dot product) → one output value Output size: (n - f + 1) / stride + 1 (no padding) padding="same" keeps output size == input size

Each filter produces one 2D feature map; a conv layer stacks many filters (e.g. 64) to detect many different patterns in parallel, giving a 3D stack of feature maps as output.

Weight sharing — why it helps

A dense layer on a 224×224 image needs a separate weight per pixel per output unit — millions of parameters for one layer. A 3×3 filter has 9 weights (times channels) regardless of image size, and that same filter is applied at every position. This gives two wins at once: far fewer parameters to learn and store, and translation invariance — a cat detected in the top-left is recognized the same way as a cat in the bottom-right, because it's literally the same weights doing the detecting.

Pooling and receptive field
Max pooling (2×2, stride 2): keep the max value in each 2×2 block → halves height and width, keeps the strongest activation → adds a small amount of translation invariance, reduces compute Receptive field: the region of the original image a given neuron "sees" — grows with each conv/pool layer, so deeper layers respond to larger, more abstract patterns (edges → textures → parts → objects)

This is why CNNs are described as building a feature hierarchy: early layers learn edges, middle layers learn textures and parts, late layers learn whole objects — each stage's receptive field is large enough to see the pattern the previous stage assembled.