Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Parts that vote on wholes
A face is a face only if its eyes, nose and mouth are in the right places relative to one another. Ordinary CNNs detect parts but, after pooling, partly forget where they were. Capsule networks represent each part by a small vector, its pose. Each part predicts where the whole should be. If several parts’ predictions agree, the whole is probably there, and those parts send their output to it. This “routing by agreement” was Geoffrey Hinton’s proposal for networks that understand spatial relationships.
Capsules address a real weakness, viewpoint and part–whole structure, that matters for recognising objects from unusual angles, as robots and aerial cameras must. They also show how an appealing idea can struggle to scale.
- 1. A capsule's length represents…
- 2. A capsule's direction encodes…
- 3. Routing by agreement sends outputs to…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
-
Squash: v = (‖s‖²/(1 + ‖s‖²))·s/‖s‖. It keeps the direction and maps length l to l²/(1 + l²), so 1 → 0.5, 3 → 0.9 and 5 → 0.96.
-
Predictions: û_(j|i) = W_ij u_i, where child i predicts parent j’s pose through a learned matrix.
-
Routing (r iterations):
- Coupling c_ij = softmax_j(b_ij).
- s_j = Σ_i c_ij û_(j|i), and v_j = squash(s_j).
- b_ij ← b_ij + û_(j|i)·v_j.
With b = 0, every child splits equally: c = 1/3 for 3 parents.
-
Margin loss: Σ_k T_k max(0, 0.9 − ‖v_k‖)² + 0.5(1 − T_k) max(0, ‖v_k‖ − 0.1)². A true-class length of 0.5 costs 0.16.
-
CapsNet on MNIST:
- a 9 × 9 conv with 256 channels;
- PrimaryCaps: 32 maps × 6 × 6 = 1,152 capsules of 8 dimensions;
- DigitCaps: 10 capsules of 16 dimensions, with 1,152·10·16·8 = 1,474,560 routing weights.
- 1. Squashed length of a vector of length 3:
- 2. Initial coupling to each of 3 parents:
- 3. Number of PrimaryCaps in CapsNet:
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Capsules in code
Exercise 1.
- Squash kept the direction (0.6, 0.8) of (3, 4) and gave length 25/26.
- The margin loss was 0 for a confident correct output.
- The prediction tensor had shape (children, parents, 16).
Practice.
- CapsNet trains with Adam and 3 routing iterations.
- A decoder reconstructs the input from the true class’s capsule, with loss weight 0.0005, as a regulariser.
- Routing is iterative and per example, so it is slow. Memory grows with the number of children × parents × dimensions, which makes large images expensive.
- Matrix capsules with EM routing (Hinton, Sabour and Frosst, 2018) use 4 × 4 pose matrices and an EM-based routing.
def route(u_hat, iters=3): # u_hat: (batch, children, parents, dim)
b = torch.zeros(u_hat.shape[:3])
for _ in range(iters):
c = b.softmax(dim=2); v = squash((c[..., None] * u_hat).sum(1))
b = b + (u_hat * v[:, None]).sum(-1)
return v- 1. CapsNet's reconstruction loss weight:
- 2. Routing iterations in CapsNet:
- 3. Matrix capsules use…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Equivariance instead of invariance. Max pooling discards exact positions, building some invariance. Capsules aim for equivariance: when the viewpoint changes, pose vectors change predictably while presence (length) stays the same. The learned matrices W_ij encode part–whole geometry, which in principle lets a network generalise to new viewpoints.
Routing as clustering. Each iteration raises the coupling of child i to parent j in proportion to the agreement û_(j|i)·v_j, a soft clustering of predictions. Agreement among many independent predictions is unlikely by chance, so it is strong evidence that the parent is present.
Evidence.
- On MNIST, CapsNet reached 0.25% error.
- On affNIST (MNIST digits under affine transforms, not seen in training) it reached 79% accuracy, against 66% for a CNN with similar MNIST accuracy.
- It segmented highly overlapping digits (MultiMNIST).
Limits.
- Routing is costly, and capsule networks did not scale competitively to ImageNet.
- Later analyses (e.g. Paik et al., 2019) found that routing often adds little over uniform coupling, and that coupling can become uniform or collapse.
- Exercise 2 shows a related point: plain summation of agreeing predictions already favours the present parent, and routing mainly sharpens it.
Attention mechanisms now fill much of the role capsules aimed at.
- 1. Capsules aim for…
- 2. Routing resembles…
- 3. On affNIST CapsNet reached…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.What does routing actually do?
History.
- G. Hinton, A. Krizhevsky and S. Wang (2011) introduced “transforming auto-encoders” with capsules.
- S. Sabour, N. Frosst and G. Hinton (2017) introduced dynamic routing between capsules (CapsNet).
- G. Hinton, S. Sabour and N. Frosst (2018) introduced matrix capsules with EM routing.
- I. Paik, T. Kwak and I. Kim (2019) questioned the routing algorithm’s benefit.
Exercise 2. Each of 200 synthetic scenes has 10 child capsules and 3 parents, with 8-dimensional poses:
- 7 children predict nearly the same pose for parent 0 (the “present” entity);
- the other predictions are random.
Dynamic routing is run for 1, 2, 3 and 5 iterations:
| iterations | coupling of agreeing children to parent 0 | of other children | length of parent 0 | of absent parents |
|---|---|---|---|---|
| 1 | 0.333 | 0.333 | 0.589 | 0.206 |
| 2 | 0.392 | 0.335 | 0.664 | 0.196 |
| 3 | 0.464 | 0.337 | 0.735 | 0.182 |
| 5 | 0.634 | 0.344 | 0.839 | 0.147 |
- Routing works as designed. Agreeing children shift their output to the present parent, while the others stay near 1/3. The present parent’s length grows and the absent parents’ shrink.
- But the present parent already stands out with uniform coupling (0.59 against 0.21, 2.9 times). Agreeing predictions add up, random ones cancel. Routing sharpens the contrast (4.0 times after 3 iterations, 5.7 after 5) rather than discovering it.
- So routing’s benefit depends on whether sharper contrast matters for the task. That is consistent with later findings that routing often adds little in practice.
Capsules in AI, robotics and aerospace
- Viewpoint robustness: part–whole reasoning is attractive for recognising objects from unusual viewpoints, such as aerial and satellite views, and capsule variants have been tried on remote-sensing data.
- Pose estimation: capsule-style pose vectors relate to object pose estimation for robotic grasping.
- Research lesson: a principled idea needs careful ablation (does routing help over uniform coupling?) before adoption.
References
- S. Sabour, N. Frosst, G. E. Hinton (2017). “Dynamic routing between capsules.” Advances in NeurIPS.
- G. E. Hinton, S. Sabour, N. Frosst (2018). “Matrix capsules with EM routing.” Proc. ICLR.
- G. E. Hinton, A. Krizhevsky, S. D. Wang (2011). “Transforming auto-encoders.” Proc. ICANN.
- I. Paik, T. Kwak, I. Kim (2019). “Capsule networks need an improved routing algorithm.” Proc. ACML.