liveBook · Manning

Translation invariance

As explained in Deep Learning with PyTorch, Second Edition

The property of a model or representation whose output is unchanged, or changes minimally, when an input object shifts position.

An image classifier should recognize an airplane whether it appears near the top or bottom of an image. Translation invariance is the desired insensitivity to that shift: the pattern should still count as an airplane when its position changes. section 7.2.6

Figure 7.16 Translation invariance, or the lack thereof, with fully connected layers
figure

Compare the airplane at different positions to see why a fully connected layer must learn new pixel relationships after a shift. section 7.2.6

A fully connected layer gives each pixel position its own place in a large set of weights. Move the same airplane, and the useful relationships now involve different positions. Randomly translating training images can expose the model to more positions, but the model still needs capacity to store those translated patterns. section 7.2.6

Convolution takes a more direct approach. A small kernel computes a weighted sum over a neighborhood, then uses the same weights at other locations. A local pattern can therefore be detected wherever it appears, without learning a separate set of weights for every position. section 8.1 section 8.1.1

Figure 8.2 Convolution and the equivalent linear operations. The linear weights will be sparse (only a few nonzero values) and tied (the same values appear in multiple places).
figure

The equivalent linear operation makes the two ingredients visible: sparse weights restrict attention to nearby pixels, and tied weights reuse the same pattern across locations. section 8.1.1

From a small pattern to a larger one

A 3 × 3 kernel sees only a small neighborhood. Stacking convolutions with downsampling lets later layers account for relationships across larger parts of an image. For example, `nn.MaxPool2d(2)` reduces an image tensor from shape `[1, 3, 32, 32]` to `[1, 3, 16, 16]`. section 8.2.3 section 8.2.3

How Deep Learning with PyTorch, Second Edition covers it

How deep it goes
Explains the failure of fully connected layers and the shared local weights of convolution, then extends the intuition to pooling.
Examples
Uses an airplane shifted within an image, a shared-kernel diagram, and a max-pooling tensor-shape example.
What it assumes
Assumes familiarity with image pixels and neural-network layers while building the convolution intuition from local weighted sums.
What you can do after
Evaluate/understand why convolution better handles shifted image patterns than a fully connected layer.
How it connects
Connects translation invariance to locality, convolution, data augmentation, fully connected layers, and pooling.

Also explained in

Compare how 5 books explain translation invariance →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with PyTorch, Second Edition. The section links point to the parts of the book it draws on.