Dynamic Routing Between Capsules
- Paper: Dynamic Routing Between Capsules
- Authors: Sara Sabour, Nicholas Frosst, Geoffrey E. Hinton
- Lab, year: Google Brain Toronto, 2017 (NIPS 2017)
- Video: YouTube Short coming on 17 Dec 2026 on Backprop Daily
Summary
The paper builds a network out of capsules: groups of neurons whose output is a vector. The length of the vector is the probability that an entity (such as a digit or a part of one) is present, and its direction encodes the entity’s properties. Capsules in one layer send their output to capsules in the next layer through an iterative “routing-by-agreement” procedure. A three-layer CapsNet reached 0.25% test error on MNIST with 3 routing iterations and a reconstruction loss, against 0.39% for a CNN baseline with 35.4M parameters (CapsNet has 8.2M; Section 5, Table 1). It also reached 5.2% error on MultiMNIST, where two digits overlap heavily (Table 1).
What Problem Does It Solve
In a CNN, max-pooling lets a layer “ignore all but the most active feature detector in a local pool in the layer below”, which the authors call a “very primitive form of routing” (Section 1). Capsules keep the properties of what they detect in a vector, and routing-by-agreement decides which higher-level capsule each lower-level capsule should send its output to. The paper shows this helps with heavily overlapping digits (Section 6) and with affine transformations not seen in training: on affNIST, a CapsNet scored 79% against 66% for a CNN with similar MNIST accuracy (Section 5.2).
Core Idea
Each lower-level capsule i multiplies its output u_i by a weight matrix W_ij to predict the output of each higher-level capsule j: û_j|i = W_ij u_i. Capsule j takes a weighted sum s_j = Σ_i c_ij û_j|i and squashes it with v_j = (‖s_j‖² / (1 + ‖s_j‖²)) · s_j / ‖s_j‖, so its length lies between 0 and 1 (Section 2, Eqs. 1–2). The coupling coefficients c_ij are a softmax over logits b_ij, which start at zero and are increased by the agreement û_j|i · v_j at each routing iteration (Procedure 1, Eq. 3).
Key Method Details
- Architecture: Conv1 has 256 9×9 kernels with stride 1 and ReLU; PrimaryCapsules has 32 channels of 8D capsules on a 6×6 grid (9×9 kernels, stride 2); DigitCaps has one 16D capsule per class (Section 4).
- Margin loss: L_k = T_k max(0, m⁺ − ‖v_k‖)² + λ (1 − T_k) max(0, ‖v_k‖ − m⁻)² with m⁺ = 0.9, m⁻ = 0.1 and λ = 0.5 (Section 3, Eq. 4).
- Routing: no routing between Conv1 and PrimaryCapsules; logits start at zero (Section 4). The appendix suggests 3 routing iterations for all experiments.
- Reconstruction regulariser: all digit capsules except the correct one are masked out; a decoder of 3 fully connected layers reconstructs the image, and the sum of squared differences is scaled by 0.0005 (Section 4.1).
- Training: Adam with TensorFlow defaults and an exponentially decaying learning rate (Section 4); MNIST images shifted by up to 2 pixels, no other augmentation (Section 5).
- Other datasets: 10.6% error on CIFAR10 with an ensemble of 7 models, and 2.7% on smallNORB (Section 7).
Simplifications in This Notebook
- Smaller network, on a CPU: Conv1 has 64 channels (paper: 256); PrimaryCaps has 8 types of 4D capsules (paper: 32 of 8D); digit capsules are 8D (paper: 16D); 2 routing iterations (paper: 3). 799,408 parameters in total.
- Less data and training: 20,000 training images and the first 5,000 test images, 5 epochs, Adam with a fixed learning rate of 10⁻³, no 2-pixel shifts.
- Decoder input: the decoder gets only the 8D vector of the selected class capsule, not the masked vector of all 10 capsules, so it is not told which class it is reconstructing.
- Not done: MultiMNIST, affNIST, CIFAR10, smallNORB and the CNN baseline.
What the Notebook Result Shows
- The model trains: test accuracy rose every epoch, from 95.62% to 98.12% (test error 1.88%) after 5 epochs, and was still improving when training stopped.
- Not comparable with the paper: the paper’s 0.25% comes from a much larger model trained on all 60,000 shifted images, and the notebook has no CNN baseline.
- Reconstructions: the 10 test digits shown are all classified correctly and reconstructed as blurry but recognisable digits; the mean sum of squared error is 33.13 per image.
- Perturbations: for one digit 7, changing dimensions 2 and 3 visibly changes stroke thickness and size; the other dimensions change the image only slightly.
Influence
The authors’ TensorFlow code is in Sarasra/models. Aurélien Géron’s video Capsule Networks (CapsNets) – Tutorial and Max Pechyonkin’s series Understanding Hinton’s Capsule Networks explain the paper. OpenAlex lists about 4,500 citations (4,501 when checked on 3 December 2026).
Resources
| File | Description |
|---|---|
| README.md | This overview — a 5-minute read covering the paper’s summary, core idea, key method details, influence, and a plain-English explanation of the problem it solves |
| solution.ipynb | Scaled-down CapsNet in PyTorch with squashing, routing-by-agreement, margin loss, a reconstruction decoder and capsule-dimension perturbations, trained on CPU |
| CODE_ARCHITECTURE.md | Section-by-section breakdown of the notebook — what each cell does, data flow, tensor shapes, and key design decisions |
| TALK.md | Press coverage, Q&A (answers from the paper), citations, and common misconceptions about the paper |