Simple Algorithm
Deep Learning · Emergence · 28 min

Rotation-Equivariant & Steerable CNNs

Building rotations and reflections into convolution, from group convolutions to steerable filters.

A convolutional layer detects an edge anywhere in the image, but at only one orientation per filter: rotate the input and nothing in the architecture makes the features follow. Microscope slides, satellite images and tissue samples have no preferred "up", so it pays to build rotations into the layers themselves. The mathematics that does it, group convolution, steerable filters and one linear constraint on the kernel, also explains why convolution itself was inevitable.

What you’ll learn

  • Define the groups p4 and p4m, describe how they act on images and on feature maps over the group, and prove that the lifting correlation is equivariant.
  • Implement group convolution by filter transformation and account for its planes, parameters and multiply–adds at a matched parameter budget.
  • Derive the steering property of circular harmonics, [Wm⋆Fθ]=eimθ[Wm⋆F][W_m\star F^\theta]=e^{im\theta}[W_m\star F], and the arithmetic of rotation orders in harmonic networks.
  • Derive the steerable kernel constraint κ(gx)=ρout(g) κ(x) ρin(g)−1\kappa(g\mathbf x)=\rho_{\text{out}}(g)\,\kappa(\mathbf x)\,\rho_{\text{in}}(g)^{-1}, solve it in simple cases, and state the theorems that make equivariant linear layers convolutions.
  • Judge when built-in rotation equivariance helps relative to augmentation, and when exact invariance hurts.

Group convolution on the square grid

Write a stack of feature maps as f:Z2→RKf:\Z^2\to\R^K and a transformation gg of the plane as acting by [Lgf](x)=f(g−1x)[L_gf](\mathbf x)=f(g^{-1}\mathbf x). Ordinary cross-correlation commutes with translations, but for a rotation rr one only has [Lrf]⋆ψ=Lr[f⋆Lr−1ψ][L_rf]\star\psi=L_r\big[f\star L_{r^{-1}}\psi\big] (Cohen & Welling, 2016): a rotated image correlated with ψ\psi gives the rotated result of correlating the original image with the counter-rotated filter. A CNN whose filter bank happens to contain all rotated copies of each filter is therefore equivariant as a whole, but it has to learn every copy separately, from data showing every orientation.

A group convolution hard-wires the copies instead. Rotations by multiples of 90∘90^\circ map the pixel grid onto itself exactly, which makes them the natural first target.

DerivationThe lifting layer is equivariant
  1. [(Luf)⋆ψ](g)=∑yf(u−1y) ψ(g−1y)=∑y′f(y′) ψ(g−1u y′)[(L_uf)\star\psi](g)=\sum_{\mathbf y}f(u^{-1}\mathbf y)\,\psi(g^{-1}\mathbf y)=\sum_{\mathbf y'}f(\mathbf y')\,\psi(g^{-1}u\,\mathbf y')

    Transform the input by any u∈p4u\in\text{p4}, which permutes Z2\Z^2, and substitute y=uy′\mathbf y=u\mathbf y':

  2. [(Luf)⋆ψ](g)=[f⋆ψ](u−1g)=[Lu(f⋆ψ)](g)[(L_uf)\star\psi](g)=[f\star\psi](u^{-1}g)=\big[L_u(f\star\psi)\big](g)

    Since g−1u=(u−1g)−1g^{-1}u=(u^{-1}g)^{-1}, the last sum is the original output evaluated at u−1gu^{-1}g:

  3. [LrF](t,s)=F(r−1t,  r−1s)[L_rF](\mathbf t,s)=F\big(r^{-1}\mathbf t,\;r^{-1}s\big)

    Read off what LuL_u does to the output when u=ru=r is the 90∘90^\circ rotation about the origin: r−1(t,s)=(r−1t, r−1s)r^{-1}(\mathbf t,s)=(r^{-1}\mathbf t,\,r^{-1}s). Every plane is rotated and the four planes shift cyclically by one orientation. A rotated input produces the same features, moved to rotated positions and relabeled to the next orientation.

Implementation by filter transformation. Nothing new is needed at run time. Before each forward pass, build the expanded filter bank, rotating each filter spatially and, from the second layer on, also cyclically shifting its orientation axis, then call an ordinary conv2d with 4×4\times as many input and output channels. Pointwise nonlinearities commute with the permutation of planes, so ReLUs keep the equivariance. For an invariant prediction, pool over the orientation axis at the end, after the last group convolution: Cohen & Welling found that pooling over rotations early, "premature invariance", discards relative orientations that later layers need.

What it costs and what it buys

A p4 layer with CinC_{\text{in}} input and CoutC_{\text{out}} output fields stores CoutCin⋅4⋅k2C_{\text{out}}C_{\text{in}}\cdot4\cdot k^2 weights, because each filter spans the 4 orientation planes of every input field, but it runs as a convolution from 4Cin4C_{\text{in}} to 4Cout4C_{\text{out}} planes. Sharing each filter across the four rotations is extra weight sharing, just as convolution shares across positions.

Cohen & Welling compared networks at a matched parameter count, dividing the number of fields by 4=2\sqrt4=2 for p4 and by about 8\sqrt8 for p4m. For a 3×33\times3 layer that a plain CNN runs with KK channels, p4 with K/2K/2 fields has exactly the same K2k2K^2k^2 weights, yet carries 2K2K planes and costs (2K)2k2(2K)^2k^2, four times the multiply–adds; p4m carries about 2.8K2.8K planes for eight times the multiply–adds. Equivariance buys a larger, structured representation per parameter, paid for in compute and activation memory.

Predict before you look

A p4m group-convolution layer has 24 output fields. How many two-dimensional feature planes does it produce?

Show the answer

192 planes

Each p4m field is a function on the 8 symmetries of the square at every pixel: 4 rotations, each with or without a reflection. So 24×8=19224\times8=192 planes. This is the regular representation of the point group: each field consumes ∣H∣|H| channels, HH being the group of rotations and reflections that fix a point.

Network (Cohen & Welling, 2016)GroupTest error, plain / augmentedParameters
All-CNN on CIFAR-10Z2\Z^2 (ordinary)9.44% / 8.86%1.37M
All-CNN on CIFAR-10p48.84% / 7.67%1.37M
All-CNN on CIFAR-10p4m7.59% / 7.04%1.22M
ResNet-44 on CIFAR-10Z2\Z^2 / p4m9.45% → 6.46% / 5.61% → 4.94%2.64M / 2.62M
7-layer CNN on rotated MNISTp4 (P4CNN)2.28%, against 3.98% for the best earlier methodabout the baseline's
"Augmented" means horizontal flips and small translations. CIFAR-10 is not rotation-symmetric, since objects appear upright, yet the group convolutions helped, so the data need not have a full symmetry; a likely reason is that low-level patterns such as edges and textures occur at every orientation even when whole objects do not.

Rotations by 90∘90^\circ are exact on a pixel grid; any other angle needs interpolation, so a network built for NN orientations with N>4N>4 is equivariant only up to discretization error. Weiler & Cesa (2019) swept NN on rotated digits and found accuracy improving with the number of orientations and saturating at around 8 to 12.

Steerable filters and circular harmonics

Storing one copy of a filter per orientation does not scale to fine angles. Freeman & Adelson (1991) noticed that some filters can be rotated to any angle by mixing a few fixed basis filters. The derivative of the Gaussian G=e−(x2+y2)G=e^{-(x^2+y^2)} in direction θ\theta is the directional derivative

G1θ=cos⁡θ G10∘+sin⁡θ G190∘,G_1^\theta=\cos\theta\,G_1^{0^\circ}+\sin\theta\,G_1^{90^\circ},

so two filters, ∂xG\partial_xG and ∂yG\partial_yG, give an edge detector at every orientation. In general, expand a filter in polar coordinates as an angular Fourier series f(r,φ)=∑n∈San(r) einφf(r,\varphi)=\sum_{n\in S}a_n(r)\,e^{in\varphi}. Rotating it by θ\theta gives ∑n∈Se−inθan(r) einφ\sum_{n\in S}e^{-in\theta}a_n(r)\,e^{in\varphi}, a combination of the same ∣S∣|S| functions: a filter with ∣S∣|S| nonzero angular harmonics is steerable with ∣S∣|S| basis filters. Such a filter is a steerable filter.

DerivationWhy the response just picks up a phase
  1. [Wm⋆Fθ]=∫0∞ ⁣ ⁣∫02πR(r) ei(mφ+β) F(r,φ−θ) r dφ dr[W_m\star F^\theta]=\int_0^\infty\!\!\int_0^{2\pi}R(r)\,e^{i(m\varphi+\beta)}\,F(r,\varphi-\theta)\,r\,d\varphi\,dr

    Rotate the image about the filter's center by θ\theta: Fθ(r,φ)=F(r,φ−θ)F^\theta(r,\varphi)=F(r,\varphi-\theta). Correlating at that center (without complex conjugation, as harmonic networks do):

  2. [Wm⋆Fθ]=eimθ∫0∞ ⁣ ⁣∫02πR(r) ei(mφ′+β) F(r,φ′) r dφ′ dr=eimθ [Wm⋆F][W_m\star F^\theta]=e^{im\theta}\int_0^\infty\!\!\int_0^{2\pi}R(r)\,e^{i(m\varphi'+\beta)}\,F(r,\varphi')\,r\,d\varphi'\,dr=e^{im\theta}\,[W_m\star F]

    Substitute φ=φ′+θ\varphi=\varphi'+\theta, which shifts the angle of integration over a full period:

  3. eim1θ eim2θ=ei(m1+m2)θe^{im_1\theta}\,e^{im_2\theta}=e^{i(m_1+m_2)\theta}

    The response to the rotated patch is the original response times eimθe^{im\theta}: order m=0m=0 is rotation-invariant, m=1m=1 turns with the input. Chaining filters of orders m1m_1 and m2m_2 multiplies the phases, so rotation orders add along any path; nonlinearities that act on magnitudes only preserve the phase. To make an output MM-equivariant, every path into it must have orders summing to MM.

The payoff is equivariance to continuous 360∘360^\circ rotations of local patches, with one complex filter per order instead of one real filter per angle. Worrall et al. reported 1.69% test error on rotated MNIST with 33,000 parameters, below the earlier group-convolutional result.

Feature fields and the kernel constraint

Group convolutions and harmonic networks are two instances of one idea (Cohen & Welling, 2017; Weiler & Cesa, 2019). Give every feature a type: a representation ρ\rho of the rotation group GG, saying how its cc channels mix when the input rotates. A field f:R2→Rcf:\R^2\to\R^c of type ρ\rho transforms under a rotation gg and translation t\mathbf t as

[π(t,g)f](x)=ρ(g) f(g−1(x−t)).[\pi(\mathbf t,g)f](\mathbf x)=\rho(g)\,f\big(g^{-1}(\mathbf x-\mathbf t)\big).

A grayscale image is a scalar field (ρ=1\rho=1); optical flow is a vector field (ρ(g)=g\rho(g)=g, the arrows turn as they move); the orientation planes of a p4 network form a regular field (ρ\rho permutes the four planes cyclically); a harmonic network's order-mm response is an irrep field, rotating its two real components by mθm\theta.

DerivationDeriving the kernel constraint
  1. [κ⋆πin(g)f](x)=∫κ(gz−x) ρin(g) f(z) dz[\kappa\star\pi_{\text{in}}(g)f](\mathbf x)=\int\kappa(g\mathbf z-\mathbf x)\,\rho_{\text{in}}(g)\,f(\mathbf z)\,d\mathbf z

    A layer is a correlation [κ⋆f](x)=∫κ(y−x) f(y) dy[\kappa\star f](\mathbf x)=\int\kappa(\mathbf y-\mathbf x)\,f(\mathbf y)\,d\mathbf y with a matrix-valued kernel κ:R2→Rcout×cin\kappa:\R^2\to\R^{c_{\text{out}}\times c_{\text{in}}}; it commutes with translations automatically. Apply it to a rotated input field and substitute y=gz\mathbf y=g\mathbf z (rotations and reflections preserve area):

  2. [πout(g)(κ⋆f)](x)=ρout(g)∫κ(z−g−1x) f(z) dz[\pi_{\text{out}}(g)(\kappa\star f)](\mathbf x)=\rho_{\text{out}}(g)\int\kappa(\mathbf z-g^{-1}\mathbf x)\,f(\mathbf z)\,d\mathbf z

    Equivariance demands that this equal the rotated output field:

  3. κ(gu) ρin(g)=ρout(g) κ(u)⟺κ(gu)=ρout(g) κ(u) ρin(g)−1∀g∈G, u∈R2\kappa(g\mathbf u)\,\rho_{\text{in}}(g)=\rho_{\text{out}}(g)\,\kappa(\mathbf u)\quad\Longleftrightarrow\quad\kappa(g\mathbf u)=\rho_{\text{out}}(g)\,\kappa(\mathbf u)\,\rho_{\text{in}}(g)^{-1}\quad\forall g\in G,\ \mathbf u\in\R^2

    For this to hold for every input ff, the integrands must agree for all z\mathbf z and x\mathbf x. Put u=z−g−1x\mathbf u=\mathbf z-g^{-1}\mathbf x, so that gz−x=gug\mathbf z-\mathbf x=g\mathbf u:

The constraint is linear, so the admissible kernels form a subspace, and its consequences are concrete:

  • Scalar to scalar, G=SO(2)G=\mathrm{SO}(2): κ(gu)=κ(u)\kappa(g\mathbf u)=\kappa(\mathbf u) for every rotation, so the kernel is isotropic, a function of ∥u∥\lVert\mathbf u\rVert alone. A rotation-equivariant layer between scalar fields can only apply isotropic filters, such as blurs and center–surround (Laplacian-like) filters, and cannot detect the orientation of an edge, which is why equivariant networks need richer field types in their hidden layers.
  • Regular fields of C4C_4: rotating the kernel spatially must equal cyclically shifting its input and output orientation axes, which is exactly the filter transformation of a group convolution.
  • Irreps of SO(2)\mathrm{SO}(2): the admissible kernels are angular harmonics whose frequencies are fixed by the input and output orders, with free radial profiles; the circular harmonics of harmonic networks are such a solution.

Weiler & Cesa (2019) reduced the constraint for any representation to constraints between irreducible representations and solved it for every subgroup of O(2)\mathrm{O}(2): cyclic and dihedral groups, SO(2)\mathrm{SO}(2) and O(2)\mathrm{O}(2). The constraint fixes only the angular part of a kernel and leaves its radial profile free. Their library, e2cnn, gave notable gains on CIFAR-10, CIFAR-100 and STL-10 as a drop-in replacement for ordinary convolutions.

Check your understanding

A 5×55\times5 kernel maps a scalar field to a scalar field and must commute with rotations by 90∘90^\circ (G=C4G=C_4), so κ(gu)=κ(u)\kappa(g\mathbf u)=\kappa(\mathbf u). How many free weights does it have?

  1. 25
  2. 7
  3. 6
  4. 1
Show the answer

B. 7

The constraint ties together the weights at positions in one orbit of C4C_4. The center is its own orbit; the 4 edge neighbors, the 4 diagonal neighbors, the 4 points at (0,±2),(±2,0)(0,\pm2),(\pm2,0) and the 4 corners are one orbit each; and the 8 knight-move positions such as (1,2)(1,2) split into two orbits of 4. That is 1+1+1+1+1+2=71+1+1+1+1+2=7.

When symmetry helps, and when it hurts

Equivariant CNNs earn their keep where the data really have no preferred orientation: tissue slides, cells under a microscope, aerial and satellite images, astronomical images. Veeling et al. (2018) showed that rotation equivariance significantly improves tumor detection in lymph-node histopathology, and released the PatchCamelyon benchmark for such comparisons. The gain is largest in sample efficiency: the network never has to learn an orientation it has already seen in another guise.

On upright natural images, global rotation invariance is wrong: a 6 is not a 9 and the sky is above the ground. The evidence favors local equivariance with the symmetry released near the output. On upright MNIST, Weiler & Cesa found that fully invariant CNC_N and DND_N models did not beat a plain CNN, while models equivariant in early layers and restricted to no symmetry in the last ones did. Their dihedral models were also blind to the difference between a digit and its mirror image.

Between the extremes sit softer options. Augerino learns a distribution over augmentations jointly with the weights, so the training data decide how much invariance to keep (Benton et al., 2020). Relaxed group convolutions replace the single shared kernel by a few kernels mixed with weights that depend on the group element, so a network is biased toward equivariance without being forced into it; on turbulence and jet-flow data with imperfect symmetry they beat both strictly equivariant and unconstrained baselines (Wang, Walters & Yu, 2022). Equivariance and augmentation also combine: G-CNNs still improved when trained with flips and translations from a larger group than the one built in. A Theory of Data Augmentation analyzes the augmentation side, and Equivariant Networks for 3D Geometry carries the same constraint to rotations in three dimensions.

Key takeaways

  • Group convolutions for p4 and p4m correlate with every rotated (and reflected) copy of each filter; feature maps become functions on the group, on which a rotation rotates each plane and cyclically shifts the orientation axis. They run as ordinary convolutions on a transformed filter bank.
  • At a matched parameter count a p4 layer carries twice the planes and four times the multiply–adds of a plain layer; Cohen & Welling found consistent gains on rotated MNIST and even on upright CIFAR-10.
  • Steerable filters rotate by mixing a few basis filters; circular harmonics R(r)ei(mφ+β)R(r)e^{i(m\varphi+\beta)} respond to a rotation with a phase eimθe^{im\theta}, and rotation orders add along paths.
  • Equivariance between fields of types ρin,ρout\rho_{\text{in}},\rho_{\text{out}} is the linear constraint κ(gu)=ρout(g)κ(u)ρin(g)−1\kappa(g\mathbf u)=\rho_{\text{out}}(g)\kappa(\mathbf u)\rho_{\text{in}}(g)^{-1}, solved for all subgroups of O(2)\mathrm{O}(2); equivariant linear maps between such fields are exactly these convolutions.
  • Built-in symmetry pays most for data without a preferred orientation; for upright images, release it near the output, or learn how much to impose.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

A p4 group-convolutional network receives an input rotated by 90∘90^\circ. What happens to a hidden p4 feature map, which has 4 orientation planes per field?

  1. Each plane is rotated by 90∘90^\circ, and nothing else changes
  2. The planes are cyclically permuted, but none is rotated
  3. Each plane is rotated by 90∘90^\circ and the four planes are cyclically shifted by one orientation
  4. Nothing changes: p4 feature maps are rotation-invariant
Show the answer

C. Each plane is rotated by 90∘90^\circ and the four planes are cyclically shifted by one orientation

The group acts by [LrF](t,s)=F(r−1t,r−1s)[L_rF](\mathbf t,s)=F(r^{-1}\mathbf t,r^{-1}s): positions rotate and the orientation index advances by one, cyclically. Invariance appears only after pooling over orientations at the end.

Question 2

For G=SO(2)G=\mathrm{SO}(2) and scalar input and output fields, what does the kernel constraint κ(gu)=ρout(g)κ(u)ρin(g)−1\kappa(g\mathbf u)=\rho_{\text{out}}(g)\kappa(\mathbf u)\rho_{\text{in}}(g)^{-1} allow?

  1. Any kernel, since scalars do not transform
  2. Only radially symmetric (isotropic) kernels
  3. Only the zero kernel
  4. Kernels symmetric under 90∘90^\circ rotations, but nothing more restrictive
Show the answer

B. Only radially symmetric (isotropic) kernels

With ρin=ρout=1\rho_{\text{in}}=\rho_{\text{out}}=1 the constraint reads κ(gu)=κ(u)\kappa(g\mathbf u)=\kappa(\mathbf u) for every rotation gg, so κ\kappa depends on ∥u∥\lVert\mathbf u\rVert only. Such layers cannot detect oriented features, which is why hidden layers use regular or irrep fields.

Question 3

In a harmonic network, one path through three layers uses filters of rotation orders 11, −1-1 and 22. Rotating the input patch by θ\theta multiplies that path's contribution by what?

  1. e4iθe^{4i\theta}
  2. e−2iθe^{-2i\theta}
  3. 11
  4. e2iθe^{2i\theta}
Show the answer

D. e2iθe^{2i\theta}

Each filter multiplies the phase by eimθe^{im\theta}, so orders add: 1−1+2=21-1+2=2. Every other path into the same output must also sum to order 2, or the output would not be equivariant.

Question 4

You classify upright street-scene photos, where the sky is always at the top. Which use of rotation equivariance is most likely to help?

  1. Full rotation invariance from the first layer on, so orientation can never matter
  2. Equivariance in the early layers, with the symmetry restricted or released near the output
  3. None: equivariance never helps on data without a global symmetry
  4. p4m invariance in every layer, to add reflections as well
Show the answer

B. Equivariance in the early layers, with the symmetry restricted or released near the output

Low-level patterns such as edges and textures occur at every orientation even in upright scenes, so early equivariance shares statistical strength. The final decision may depend on absolute orientation, so the symmetry should be released near the output, as in Weiler & Cesa's restricted models and in the CIFAR-10 gains of G-CNNs.

Further reading

  • T. S. Cohen & M. Welling, "Group equivariant convolutional networks," ICML (2016).
  • W. T. Freeman & E. H. Adelson, "The design and use of steerable filters," IEEE Transactions on Pattern Analysis and Machine Intelligence 13(9) (1991).
  • D. E. Worrall, S. J. Garbin, D. Turmukhambetov & G. J. Brostow, "Harmonic networks: Deep translation and rotation equivariance," CVPR (2017).
  • M. Weiler & G. Cesa, "General E(2)-equivariant steerable CNNs," NeurIPS (2019).
  • T. S. Cohen, M. Geiger & M. Weiler, "A general theory of equivariant CNNs on homogeneous spaces," NeurIPS (2019).