TL;DR
In a deep network, the training signal is computed at the output and passed backwards one layer at a time, so the layers near the input can receive weak or distorted updates. Deep supervision adds a small prediction head and a loss term at one or more intermediate layers, so those layers are trained directly against the target. The total training loss is the output loss plus these auxiliary losses.
Builds on: Vanishing Gradient Problem, Backpropagation, Loss Function · Leads to: Hierarchical Reasoning Model
Where it's used
Image classification networks from 2014. GoogLeNet, a deep convolutional network with many parallel blocks, added two auxiliary classifiers partway through the network. They were trained with their own loss during training, and they were removed at inference time, so the final model used only the main output. The authors used them to help gradients reach the earlier layers of a very deep model.
Deeply-supervised nets for classification. Lee and colleagues added a companion objective to each hidden layer of a Convolutional Neural Network, alongside the output loss. The paper reports that this makes the hidden layers more discriminative and helps training when gradients explode or vanish.
Recurrent and iterative reasoning models. When a Recurrent Neural Network is unrolled over many steps, the signal from the final answer has to travel through all of them. Some recent models for multi-step reasoning place a supervised loss at each step as well, and Hierarchical Reasoning Model builds on this idea. The reader will meet the same mechanism there: the intermediate outputs are trained, not only the last one.
How it works
Take a tiny Feedforward Neural Network with one neuron per layer and no non-linear activation, so every number can be checked by hand. The input is and the target is . There are three weights, , and , all starting at . The first hidden value is , the second is , and the output is .
- Forward pass. . Then . Then .
- Final loss. The output loss is . Training will try to make this smaller.
- Gradient along the output path. Backpropagation sends the error back from to . The gradient reaching through is , and since , the gradient for is . Each layer multiplied the signal by a factor of on the way back, so the first layer receives a small update.
- Add an auxiliary head at . Put a small head on the first hidden layer, here one multiplication with ,, and give it its own loss . Here , so .
- Gradient from the auxiliary loss. The auxiliary loss depends directly on . Its gradient at is . This term does not have to pass through and , so it is not shrunk by them.
- Total gradient for . Add the two paths: . The first layer now gets a gradient more than three times as large as in step 3.
- Update. With a learning rate of and Gradient Descent, the new is . Without the auxiliary head it would have been .
The output layer of the network is unchanged in the sense that it still receives its own loss. The only new thing is a second route for the gradient to reach the early layer, and the early layer can now learn from a target close to it.
The math
Step 1 in symbols: the forward pass
For a network with layers , each layer computes , where is the layer's function and is the input. The output is , and the output loss is , where is the target and is any Loss Function.
Step 3 in symbols: the chain rule along the output path
The gradient of the output loss with respect to the first layer's weights is found by the Chain Rule:
In the example, , , , and . The product is .
In a deep network with many factors, each one often below 1 in magnitude, the product shrinks quickly. This is the Vanishing Gradient Problem in the form the example shows.
Steps 4 and 5 in symbols: the auxiliary term
Let the network have an auxiliary head on layer , with prediction and auxiliary loss . The total training objective is
where is the set of layers with heads and is a weight for each auxiliary loss. In the example, , , and .
The gradient of the auxiliary term with respect to is , as in step 5.
Step 6 in symbols: the total gradient
Because the total loss is a sum, its gradient with respect to is the sum of the two gradients:
Step 7 in symbols: the update
Each weight moves against its gradient, , with learning rate . With , the new value is .
Worked examples
Keep the network and the auxiliary head from the walkthrough, but set the auxiliary weight to .
- The output-path gradient for is still , because the output loss is unchanged.
- The auxiliary gradient at is .
- The total gradient is .
- With learning rate , the update is .
Interpretation: halving halves the extra push on the early layer. The auxiliary weight is a knob that trades the early layer's training against the output loss, and it is set by hand or tuned.
Use a network with inputs , weights , target , and an auxiliary head with and .
- Forward pass: , , .
- Output loss: .
- Output gradient: .
- Output path to : .
- Output path to : .
- Auxiliary loss: , so .
- Auxiliary gradient at : .
- Auxiliary gradient to : .
- Total gradient for : .
Interpretation: the auxiliary head doubled the gradient on the first layer in this case. The total objective is , and both terms point the first layer in the same direction. When the two terms disagree, they partly cancel, and that is one reason the auxiliary weight matters.
Suppose a model refines an answer over steps, and the answer at step is . Let the target be . The model is trained with the loss , so every step is supervised, not just the last.
- Suppose the four answers are , , and .
- Step losses: , , , and .
- Total loss: .
- Without deep supervision, only would be used, and the gradient would have to reach step 1 by passing through three more steps.
- With deep supervision, the step-1 answer receives a gradient from its own loss of , which is a direct signal.
- The early steps also learn to move toward on their own, and the final step learns to refine rather than to do all the work.
Try it: in step 5, suppose the target were and step 1 gave instead of . What would the direct gradient at step 1 be, and would it push the answer up or down? Answer: . The gradient is negative, so gradient descent would increase , toward the target.
Common mistakes and tradeoffs
It is tempting to think that auxiliary heads are free. They add parameters and compute during training. The head's weights also change what the early layer learns, so an auxiliary head placed in the wrong place can make the intermediate features less useful for the final output. In fact, the cost is small for a linear head, but the choice of location and weight can matter a lot, because the early layer now serves two objectives.
It is tempting to think that deep supervision replaces residual connections. It does not. A Residual Connection gives the gradient a direct path through a block, which helps every layer. Deep supervision gives an intermediate layer its own target. The two address related problems in different ways, and they are often used together.
It is tempting to think that the auxiliary heads should be used at test time. In most image classifiers they are removed after training, because the goal is a single final prediction. In some dense-prediction models, the side outputs are combined into the final prediction on purpose. The design must decide which one applies.
When to use it: deep networks that train slowly or fail to train, models with a natural set of intermediate predictions, and unrolled or iterative models where the intermediate answers have a meaning. When not to use it: shallow networks where the vanishing gradient is not a problem, and tasks where an intermediate output has no defined target, since the auxiliary loss then has nothing sensible to match.
Alternatives: residual connections, normalisation layers, and careful initialisation and choice of Activation Function address the same problem without new loss terms. A common table for comparison:
| Approach | What it changes | Cost | Main limit |
|---|---|---|---|
| Deep supervision | Adds losses at intermediate layers | Extra heads, one weight per head | Needs a meaningful intermediate target |
| Residual connections | Adds a shortcut path inside blocks | Almost none | Does not give intermediate targets |
| Better initialisation and normalisation | Keeps signal sizes stable | Almost none | Does not guarantee learning in very deep models |
History
The vanishing gradient was understood as a practical problem in the 1990s, when networks deeper than a few layers were hard to train with gradient methods. The usual response then was to use fewer layers or better initialisation.
In 2014, Szegedy and colleagues described GoogLeNet, which used auxiliary classifiers at intermediate points. They reported that these helped the gradient reach the early layers during training, and they removed the classifiers when the network was used for prediction. The same year, Lee and colleagues proposed deeply-supervised nets, which add a companion objective to each hidden layer, and they reported better classification performance. The method needs no new layer types, only extra loss terms.
Later, residual connections became the more common fix for depth, and deep supervision became one tool among several. It still returns whenever a model has a meaningful intermediate output.
Recap
- A deep network's output loss sends a training signal backward through every layer, and the signal can shrink on the way.
- Deep supervision adds a head and a loss at an intermediate layer, so that layer receives a direct gradient.
- The training objective becomes the output loss plus weighted auxiliary losses, and the gradient is the sum of the paths.
- The auxiliary weight and the placement of the heads are design choices with real effects.
- Residual connections and normalisation solve related problems and are often used alongside it.
Read next: Hierarchical Reasoning Model uses this idea in a recurrent setting, where the intermediate answers are trained as well as the last one.
Check yourself
QuestionIn one sentence, what does deep supervision add to the training objective?Show answer
It adds an auxiliary loss, computed from a prediction head on an intermediate layer, to the output loss. The total is a weighted sum, so the intermediate layer receives a direct training signal.
QuestionIn the tiny network with , all weights and , the output-path gradient for is . If an auxiliary head on with and weight contributes to the gradient at , what is the total gradient for ?Show answer
The total is , since means the gradient at carries straight through to .
QuestionWhy does deep supervision not replace residual connections, even though both help deep networks train?Show answer
They address different problems. A residual connection gives the gradient a direct path through a block without adding any targets. Deep supervision gives an intermediate layer its own target and loss. The first changes how the signal flows, the second changes what the intermediate layer is asked to learn. They can be used together.
QuestionA model with four steps uses the loss with target . Step 2 outputs . What is that step's loss, and what is the direct gradient of its loss with respect to ?Show answer
The loss is . The gradient is , which means increasing would reduce the loss.
QuestionYou are training a classifier whose intermediate layers have no natural target. Would you add deep supervision, and why?Show answer
Probably not. Deep supervision needs a target for each auxiliary head, and without a meaningful intermediate target the auxiliary loss would push the layer toward an arbitrary goal. Residual connections or normalisation are better first choices in that case.