- Introduced by
- Sabour, S., Frosst, N. & Hinton, G. E.
- Year
- 2017
- Type
- Deep learning architecture (vector capsules with dynamic routing)
What does it do?
A Capsule Network (CapsNet) is a deep learning architecture introduced by Sara Sabour, Nicholas Frosst and Geoffrey Hinton in 2017.
It replaces scalar neuron activations with vector-valued capsules, so that the presence of an entity and its pose are represented explicitly rather than discarded. It was proposed to address the sensitivity of convolutional networks to changes in viewpoint, and the original evidence concerns image recognition.
The intuition behind the method
A convolutional network detects whether a feature is present, but its pooling operations largely discard how the detected features are positioned relative to one another. This makes recognition fragile when an object is rotated or seen from a new angle. A capsule replaces a single scalar output with a vector: its length is read as the probability that an entity is present, and its direction encodes properties such as pose. Because these richer descriptions are passed up the hierarchy, the network can test whether the parts agree on a consistent whole, not only whether the parts appear.
History
Capsule Networks were introduced by Sara Sabour, Nicholas Frosst and Geoffrey Hinton in the 2017 NeurIPS paper Dynamic Routing Between Capsules, motivated by the limitations of convolutional networks in handling viewpoint variation. In 2018 Hinton, Sabour and Frosst extended the idea at ICLR with Matrix Capsules with EM Routing, replacing the original routing scheme with an expectation-maximisation procedure over matrix-valued capsules.
When to use it
Consider a Capsule Network for image-like data with spatial structure when robustness to changes in viewpoint, rotation or pose matters for the task. The cited literature evaluates it on image recognition benchmarks; use on other structured or tabular data is untested there. Capsule networks have generally been evaluated on large labelled image sets, and the original papers give no general minimum sample size. The required size depends on the task and should be checked on validation data. For small datasets, or data without spatial or part-whole structure, a classical classifier such as a random forest or a support vector machine is a safer starting point. A GPU is recommended because iterative routing is computationally demanding.
Limitations and considerations
- Dynamic routing may need a fairly large sample; with small training sets the routing may be unreliable and the risk of overfitting higher, which should be checked against validation performance.
- Iterative routing is more demanding than a feed-forward pooling step, which makes training slow without GPU acceleration and costly in memory and time on larger inputs.
- The routing procedure adds settings, such as the number of routing iterations, that affect training and have to be chosen for each task.
- Reported advantages over convolutional networks were shown on specific benchmarks and should not be assumed to transfer to other tasks.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Keeps pose and part-to-whole information that convolutional pooling discards, which is the stated motivation for the architecture.
- Routing-by-agreement is designed to let higher-level capsules draw on agreeing part predictions, instead of discarding spatial relationships through pooling.
- Vector outputs carry an entity's orientation and position alongside its presence, instead of a single scalar activation.
Applications
- Image recognition in which the same object must be identified across changes in viewpoint, rotation or pose, the setting that motivated the original work.
- Recognition tasks where keeping pose information is expected to help generalisation to new orientations, to be confirmed against a CNN baseline.
How it works
How it works
Units are grouped into capsules, which are short vectors rather than scalars. The length of a capsule's vector is used as a score for the presence of an entity, and its orientation encodes instantiation parameters such as pose. Lower-level capsules typically correspond to parts and higher-level capsules to the wholes those parts form.
Formula
c_{ij} = \frac{\exp(b_{ij})}{\sum_k \exp(b_{ik})},\quad b_{ij} \leftarrow b_{ij} + \hat{u}_{j|i}\cdot v_jEach lower-level capsule produces a prediction for every higher-level capsule by transforming its output with a learned matrix W_ij. Coupling coefficients c_ij weight these predictions; they are a softmax over routing logits b_ij and are refined iteratively by routing-by-agreement. The logits are increased when a prediction agrees (has a large dot product) with the output of the higher-level capsule, so capsules whose predictions align receive more weight. The weighted sum s_j is the input to each higher-level capsule, and this iterative routing takes the place of pooling in a convolutional network. The original work used a small number of routing iterations (typically three); the best value should be checked on validation data.
Formula
\hat{u}_{j|i} = W_{ij}\,u_i,\quad s_j = \sum_i c_{ij}\,\hat{u}_{j|i}The squashing function rescales s_j so that the length of the output vector lies between zero and one: short vectors are shrunk towards zero and long vectors towards unit length. The length can therefore serve as a presence score, while the direction retains the entity's properties. In the final layer, the lengths of the class capsules give the predicted class. In the original work the network is trained with a margin loss on these lengths, together with an optional reconstruction decoder that acts as a regulariser. The length is a bounded score, not a calibrated probability, and should not be interpreted as one without separate calibration checks.
Formula
v_j = \frac{\lVert s_j\rVert^2}{1+\lVert s_j\rVert^2}\,\frac{s_j}{\lVert s_j\rVert}Common pitfalls
- Training on very small datasets, where routing may not settle on reliable coupling coefficients and overfitting is more likely; monitor validation performance.
- Keeping the number of routing iterations at an arbitrary default without checking on validation data whether results and coupling coefficients are stable.
- Interpreting capsule lengths as calibrated probabilities.
- Assuming benchmark gains carry over: always compare against a well-tuned CNN baseline on your own data and report validation or test performance with variation across random seeds.
- Applying the architecture to non-spatial inputs with no part-to-whole structure, where routing has little to model; a classical model is usually more appropriate there.
- Underestimating the memory and time cost of routing on larger images.
Frequently asked questions
How is a capsule different from a normal neuron?
A normal neuron outputs a single scalar activation. A capsule outputs a vector whose length serves as a presence score and whose direction encodes that entity's properties, such as pose and orientation, so it carries richer spatial information.
What is dynamic routing?
Dynamic routing-by-agreement is the algorithm that connects lower-level capsules to higher-level ones. Each lower capsule predicts the output of higher capsules, and coupling coefficients are refined iteratively so that predictions which agree reinforce each other, replacing the pooling step of a convolutional network.
How much data and compute do I need?
The original papers give no general minimum sample size; capsule networks have mainly been evaluated on large labelled image sets, and the needed amount depends on the task and should be checked on validation data. A GPU is recommended because iterative routing is computationally demanding. With small datasets, a classical classifier such as a random forest or an SVM is often the safer choice.
Why use a capsule network instead of a CNN?
CapsNet was proposed to address a CNN's sensitivity to viewpoint changes. Rather than pooling away pose information, it keeps it in the capsule vectors. Whether this improves generalisation on a particular task has to be tested empirically against a well-tuned CNN.
Related methods
Sources
Sabour, S., Frosst, N. & Hinton, G. E. (2017). Dynamic Routing Between Capsules. Advances in Neural Information Processing Systems (NeurIPS).
Open publication referenceHinton, G. E., Sabour, S. & Frosst, N. (2018). Matrix Capsules with EM Routing. International Conference on Learning Representations (ICLR).
Open publication reference