Paper commentary
Dynamic Routing Between Capsules
- Problem Max-pooling passes on only the strongest detector in a local pool and discards precise position, which the authors argue is a weak basis for segmenting overlapping objects.
- Method Replaces scalar feature detectors with vector capsules, routes outputs between capsule layers by iterative routing-by-agreement, scores digit presence by capsule length with a margin loss, and adds a reconstruction regularizer.
- Results Reached 0.25% test error on MNIST with three routing iterations and reconstruction, 79% accuracy on affNIST for an under-trained model, and 10.6% test error on CIFAR10 for an ensemble of 7 models.
Why max-pooling falls short
Convolutional networks share one learned feature detector across all positions, so knowledge about good weights carries from one place in the image to another. Max-pooling, the usual way these networks combine neighbouring detectors, keeps only the strongest response in a local pool and drops the rest, which makes it a crude form of routing.
It also discards the exact position of the entity inside the pooled region, and capsules are designed to keep that position. Separating overlapping objects needs a mechanism that can explain away evidence already accounted for by another object.
Viewpoint change is a second weakness: beyond translation, a convolutional network must either copy its detectors across a grid that grows with each added transformation dimension, or collect a labelled training set that expands at a similar exponential rate. The authors name this difficulty in generalizing to novel viewpoints as a good candidate for why convolutional nets could be replaced.
What a capsule outputs
Existence is read from the length of that vector rather than from a separate logistic unit, and the orientation of the vector carries the entity's properties. Because the length must act as a probability, the output length is kept at or below 1.
The squashing function maps the total input \(s_j\) to the capsule output \(v_j\) as follows. \[ v_j = \frac{\|s_j\|^2}{1+\|s_j\|^2}\frac{s_j}{\|s_j\|} \] The direction of \(s_j\) is kept, while short inputs shrink to almost zero length and long inputs approach a length just under 1.
PrimaryCapsules yields 32×6×6 capsule outputs of 8D each, and the capsules in the 6×6 grid share their weights.
Routing-by-agreement step by step
Each lower capsule \(i\) forms a prediction \(\hat{u}_{j|i}=W_{ij}u_i\) for every parent \(j\) by multiplying its output \(u_i\) by a weight matrix \(W_{ij}\). A parent's total input is the sum of these predictions weighted by the coupling coefficients: \[ s_j = \sum_i c_{ij}\hat{u}_{j|i} \] For each lower capsule, the coupling coefficients \(c_{ij}\) sum to one over all parents.
The coupling coefficients come from a softmax over logits \(b_{ij}\): \[ c_{ij}=\frac{\exp(b_{ij})}{\sum_k \exp(b_{ik})} \] The logits are learned log prior probabilities that depend on the locations and types of the two capsules, not on the current input image. For MNIST the authors set all of these priors equal. All routing logits start at zero, so every lower capsule first sends its output to all ten parents with equal weight.
Agreement between a parent's current output and a child's prediction is the scalar product \(a_{ij}=v_j\cdot\hat{u}_{j|i}\), which is added to the logit before the softmax is recomputed. Within the routing loop, each pass computes the coupling coefficients, forms the parent inputs, applies squashing, and then updates \(b_{ij}\leftarrow b_{ij}+\hat{u}_{j|i}\cdot v_j\) for the given number of iterations.
Routing is used only between PrimaryCapsules and DigitCaps, because Conv1 outputs have no orientation to agree on. A parent whose output agrees with a child's prediction therefore gains a larger share of that child's output on the next pass, which is the explaining-away effect the authors look for.
Margin loss and layer layout
Each digit capsule \(k\) has its own margin loss, so several digits can be detected in one image. \[ L_k = T_k\max(0, m^+-\|v_k\|)^2 + \lambda(1-T_k)\max(0,\|v_k\|-m^-)^2 \] Here \(T_k=1\) when a digit of class \(k\) is present, \(m^+=0.9\), \(m^-=0.1\), and \(\lambda=0.5\). The \(\lambda\) factor weakens the loss on absent classes so that early training does not shrink the length of every digit capsule.
The total loss is the sum of the losses over all digit capsules.
Reconstruction as a regularizer
During training only the activity vector of the correct digit capsule is kept and the others are masked out, and a decoder of three fully connected layers rebuilds the input from that vector. Figure 2 shows this decoder, which is trained by minimizing the Euclidean distance between the input and the sigmoid output, using the true label as the reconstruction target.
Figure 3 shows MNIST test reconstructions from a CapsNet with three routing iterations, labelled by label, prediction and reconstruction target. Correct classifications keep many of the digit's details while smoothing noise, and the two rightmost columns show a failure in which a 5 is confused with a 3.
MNIST error and the routing ablation
Models are trained on 28×28 MNIST images shifted by up to 2 pixels with zero padding, with no other augmentation, using 60K training and 10K test images. Each CapsNet number comes from a single model without model averaging.
Table 1 lists the baseline and four CapsNet settings, with the MNIST average and standard deviation from 3 trials. The baseline row reads 0.39, and lower values are better. With one routing iteration the error is 0.34±0.032 without reconstruction and 0.29±0.011 with it, and with three iterations it is 0.35±0.036 without reconstruction and 0.25±0.005 with it.
Reconstruction lowers the error in both routing settings, while going from one to three iterations helps only when reconstruction is used, because 0.35±0.036 is slightly above 0.34±0.032 without it.
The authors attribute the gain from reconstruction to the regularizer enforcing a pose encoding in the capsule vector. The best setting reaches 0.25% test error on a three-layer network, a result the authors say had previously required deeper networks. Wan et al. report 0.21% with ensembling and augmentation by rotation and scaling, and 0.39% without them; these are the prior work's figures, not runs of this paper.
What the digit capsule dimensions encode
Because only the correct digit's encoding is passed on, the dimensions should span the ways digits of that class are written. To check this, one component of the activity vector is perturbed at a time and the perturbed vector is fed to the decoder to see how the reconstruction changes. Each perturbation runs in steps of 0.05 over the range [-0.25, 0.25].
Robustness to affine transformations
The authors train on MNIST digits placed at random on a 40×40 black background, so translation is the only transformation seen in training. They test on affNIST, where each digit carries a random small affine transformation, and the models were never trained on affine transformations beyond translation and the natural variation of standard MNIST.
An under-trained CapsNet with early stopping reaches 99.23% accuracy on the expanded MNIST test set and 79% on affNIST. A traditional convolutional model with a similar parameter count reaches 99.22% on the expanded MNIST test set and 66% on affNIST. The two models are nearly equal on the expanded test set, and the gap appears only on affNIST, where the text gives one value per model and no variance.
The authors describe the trained CapsNet as moderately robust to small affine transformations, because handwritten digits already vary in skew, rotation and style.
Building MultiMNIST pairs
MultiMNIST overlays a digit on another digit of a different class drawn from the same split. A digit sits in a 20×20 box inside its 28×28 image, and the two boxes of a pair overlap by 80% on average. For each MNIST digit the authors generate 1K MultiMNIST examples, giving 60M training and 10M test examples.
The overlap examples show reconstructions on MultiMNIST test images, with the two digits overlaid in green and red. Two failures are shown: a (2, 8) pair in which 8 is read as 7, and a (4, 9) pair in which 9 is read as 0.
Overlapping digit results and segmentation
Trained from scratch on MultiMNIST, the three-layer CapsNet scores better than the convolutional baseline on test images. The table gives 5.2 for the same CapsNet configuration with three routing iterations and reconstruction, so the text value and the table value differ.
At test time the two most active digit capsules give the predicted classes, and reconstruction uses the activity vector of one chosen digit capsule at a time, compared with the known image of that digit. The reconstructions separate the two digits, and the authors state that the model accounts for all pixels without operating at pixel level for segmentation.
The authors interpret this as each digit capsule picking up style and position from the votes it receives from PrimaryCapsules. For segmentation, the two most active DigitCaps capsules are decoded one at a time, and any pixel with non-zero intensity is assigned to that digit.
The baseline has two convolutional layers, the first with 512 kernels of 9×9 and the second with 256 kernels of 5×5, followed by a 1024D fully connected layer and a 10-unit output layer. That baseline has 24.56M parameters, against 11.36M for CapsNet. Because the training set is larger, the decay period of the learning rate is set 10× larger than in the MNIST model.
The baseline width was chosen by growing a smaller network, from 32 and 64 kernels of 5×5 with a 512D layer, until test accuracy on a 10K subset of MultiMNIST stopped improving, and the decay step was tuned on a 10K validation set.
Results on CIFAR10, smallNORB and SVHN
On CIFAR10, an ensemble of 7 models, each with 3 routing iterations and trained on 24×24 patches, reaches 10.6% test error. Each model follows the MNIST architecture with three colour channels and 64 types of primary capsule. A none-of-the-above category was added to the routing softmaxes, because the final ten capsules are not expected to explain everything in the image.
The authors note that 10.6% is about what standard convolutional nets reached when they were first applied to CIFAR10. They attribute the weaker result to CIFAR10 backgrounds, which they consider too varied for a net of reasonable size to model.
The MNIST architecture, used unchanged, reaches 2.7% test error on smallNORB. Images are resized from 96×96 to 48×48, training uses random 32×32 crops, and testing uses the central 32×32 patch.
On a smaller SVHN training set of 73257 images, a reduced network with 64 first-layer channels, 16 primary capsules of 6D and an 8D final capsule layer reaches 4.3% test error.
Relation to earlier viewpoint work
The authors frame capsules as avoiding the exponential cost of convolution for viewpoint change, because transformation matrices that encode part-whole relations generalize to new viewpoints. They contrast this with spatial transformer networks: capsules keep activities that vary with viewpoint instead of normalizing them away, so they can handle several different affine transformations of different objects at once.
The authors also point to Hinton's 1981 work on dynamic connections and to the Olshausen et al. 1993 model as earlier routing ideas.
Limitations
The capsule model does better when it models the clutter than when it uses an extra orphan category, and CIFAR10 backgrounds are too varied for that. Segmentation is judged from reconstructions and non-zero pixel assignment, and the text reports no separate segmentation metric. The affNIST comparison uses one early-stopped CapsNet and one convolutional model with a similar parameter count.
Routing is compared only at one and three iterations, and the baseline row of the MNIST table has no standard deviation. The authors describe the design as one fairly straightforward implementation, not an exploration of the whole design space.
Paper info
- Authors
- Sara Sabour, Nicholas Frosst, Geoffrey E Hinton
- Venue
- arXiv · Preprint
- First published
- 2017-10-26
- Added
- 2026-10-20
- Updated
- 2017-11-7
- Version
- v2
- arXiv
- 1710.09829
- Category
- cs.CV
- Original paper terms
- arXiv non-exclusive 1.0
- What we show
- Paper info and commentary
AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.
Quote from the paper
Sara Sabour, Nicholas Frosst, Geoffrey E Hinton (2017). Dynamic Routing Between Capsules. arXiv:1710.09829v2. https://arxiv.org/abs/1710.09829v2
BibTeX
@misc{sabour2017dynamic,
title = {{Dynamic Routing Between Capsules}},
author = {Sara Sabour and Nicholas Frosst and Geoffrey E Hinton},
year = {2017},
eprint = {1710.09829},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/1710.09829v2}
}