TL;DR
He (Kaiming) initialization sets the random starting weights of a layer with variance , where is the number of inputs to the layer. The factor of 2 is there because a ReLU throws away every negative value, which on average removes half of the signal's energy. Scaling the weights up by that amount keeps the signal from shrinking as it passes through a deep ReLU network.
The same reasoning applies to the gradients flowing backwards, so the rule can also be written with the number of outputs. In practice the input-width version is the usual default.
Where you'll see it: as the default initializer for convolutional and dense layers followed by ReLU in deep vision networks, and as the ReLU counterpart of Xavier initialization.
Intuition
Half the crowd leaves
Picture a line of people passing a message down a corridor. At each step, each person hears a number and repeats it, but anyone who hears a negative number stays silent and passes on nothing. On average half of the people stay silent at every step. If nobody compensates, the message gets quieter and quieter, and after ten steps almost nothing gets through.
ReLU does exactly this to a signal. It keeps positive values and sets negative ones to zero. Half the values disappear, but the layer's weights still act as if all of them were present. The fix is to make each active value louder before the next layer, by a factor that exactly cancels the loss. He initialization chooses that factor.
Why this matters for a deep stack
Xavier initialization was designed with symmetric activations like in mind, which pass both signs through. A ReLU network breaks its assumptions. The result is that with Xavier weights, a ReLU network's activations shrink by a roughly constant factor per layer. That factor is small, so after a few dozen layers the signal is effectively zero. The gradients then vanish too, which is the vanishing gradient problem in its most direct form.
flowchart LR A["Layer input with variance v"] --> B["Weights with variance 2 over n_in"] B --> C["Pre-activation variance is n_in times 2 over n_in times v, which is 2v"] C --> D["ReLU halves the second moment"] D --> E["Next layer input has second moment v"]
The math
Setting up the forward pass
Consider one fully connected layer with inputs. Its pre-activation for output unit is
where are the inputs and are the weights. Assume the weights are independent of each other and of the inputs, with mean zero and variance . The inputs are treated as independent of each other and of the weights. Because the weights have zero mean, the input mean does not matter, and only the input's second moment enters.
Under these assumptions the variance of the pre-activation is
The cross terms vanish because each product has mean zero, and the variance of a sum of independent terms is the sum of their variances. The term is the second moment of the input, which is the mean of its squared values. For a zero-mean signal it equals the variance, but a ReLU output is never negative, so the second moment is the quantity to track.
The ReLU step
The inputs to this layer are the outputs of the previous ReLU, , where is the previous layer's pre-activation. If is symmetric around zero, then half its mass is negative and gets set to zero. Hence
Substituting into the first equation, the variance of the layer's pre-activation becomes
Choosing the weight variance
To keep the variance from one layer to the next unchanged, we need the factor in front of to equal 1. That gives
This is the He rule. The factor 2 is the reciprocal of the ReLU's halving. Over layers the variance of the pre-activation is multiplied by , so the rule keeps this product at 1 instead of letting it drift towards 0 or infinity.
For a layer followed by ReLU, draw each weight independently from a distribution with mean 0 and variance . A normal distribution gives He normal initialization, and a uniform distribution on , which has variance , gives He uniform initialization.
The backward pass
Gradients flow backwards through the transposed weight matrices. The same argument applied to the backward pass gives a variance condition in terms of the number of outputs ,
Forward and backward conditions cannot both hold exactly unless . He et al. use the forward version by default, because keeping the activations' scale stable is what matters most for the forward pass. Keras uses the fan-in version for its he_normal initializer by default, and PyTorch's kaiming_normal_ uses fan-in as well, with a mode argument to choose fan-out.
Relation to Xavier
Xavier initialization sets , which averages the two conditions above. It assumes an activation with unit slope at zero, such as near its linear region, and does not account for the halving. ReLU needs the extra factor of 2. The forward pass depends only on the input width, so the He rule uses alone.
Worked examples
Let a layer have inputs. Suppose the previous layer's pre-activation has variance , so it has standard deviation 2. Compare two weight choices.
- Compute the input's second moment after ReLU: .
- With LeCun-style weights, . The pre-activation variance is . The variance halved, from 4 to 2.
- With He weights, . Then . The variance is unchanged.
- Interpretation: the choice of weight variance decides whether each layer halves the signal's energy or preserves it. Over ten layers, halving every time multiplies the variance by , which means the standard deviation shrinks by about times. The He choice keeps it at 4 throughout.
Take a 10-layer fully connected ReLU network that is wide enough for the independence assumptions to hold. The input has unit variance. Using at each layer, the expected root-mean-square (RMS) of the activations after each ReLU is as follows.
| Weight variance | After layer 1 | After layer 5 | After layer 10 |
|---|---|---|---|
| (LeCun) | 0.71 | 0.18 | 0.03 |
| (He) | 1.00 | 1.00 | 1.00 |
- With variance , the pre-activation variance in layer 1 is , and the ReLU halves the second moment to , so the RMS is . Each further layer halves it again, so after layer the RMS is : at layer 5 and at layer 10.
- With He weights, layer 1 has pre-activation variance , and the ReLU halves the second moment back to 1. Every later layer repeats this, so the RMS stays at 1. In a real finite-width network it fluctuates around 1 rather than matching it exactly.
- Interpretation: at ten layers, the LeCun network carries about 3 percent of the signal's scale, and the He network carries all of it. The gradients in the early layers of the LeCun network are scaled down by the same factor on the way back, so those layers learn very slowly.
Tradeoffs and failure modes
| Situation | Problem | Better choice |
|---|---|---|
| ReLU or leaky ReLU followed by a dense or convolutional layer | Default init with variance halves the signal each layer | He initialization |
| or sigmoid activations | He's factor of 2 overestimates the signal, so the activations saturate | Xavier initialization |
| Residual networks | The residual branch adds to the input, so variance grows with depth even under He init | Zero-initialize the last layer of each residual branch, or scale the branch down |
| Transformers with layer normalization | Normalization already rescales activations, so the init matters less for the forward pass | Standard init for the model family, such as a truncated normal with a small standard deviation |
| Very narrow layers | The approximation of many independent terms breaks down | Check the activation scale empirically at the first step of training |
Failure modes to watch for. If the activations shrink or grow by a constant factor per layer, the init does not match the activation function: check whether a ReLU or a symmetric activation is used. A common bug is to apply He init to a layer whose output does not go through a ReLU, such as the final classifier, where it inflates the logits. Another is mixing fan-in and fan-out conventions between frameworks, which changes the scale for layers whose input and output widths differ.
History
In 2010 Xavier Glorot and Yoshua Bengio analysed how the scale of signals and gradients changes through a deep network and proposed the averaged rule that now carries their names. The rule worked well for networks.
Rectified linear units became the common activation in the following years, because they were cheap and reduced the saturation problem. Kaiming He, Xiangyu Zhang, Shaoqing Ren and Jian Sun, at Microsoft Research, noticed in 2015 that the Xavier rule did not fit ReLU networks. Their paper, Delving Deep into Rectifiers, derived the factor of 2 and introduced the PReLU activation. They reported that a 30-layer network converged with the new initialization where the Xavier-initialized version struggled to train. The rule then became the default for ReLU networks in the major deep-learning frameworks.
Check yourself
QuestionRecall: why does a ReLU layer need a larger weight variance than a symmetric activation does?Show answer
A ReLU sets every negative input to zero, so on average it removes half of the signal's second moment. The next layer receives only half the energy. Doubling the weight variance, so that instead of , compensates for this halving and keeps the variance stable from layer to layer.
QuestionComputation: a ReLU layer has inputs, and the input signal has second moment . What variance should the weights have, and what is the resulting pre-activation variance?Show answer
He initialization gives . The pre-activation variance is . This is twice the value that the next ReLU sees after halving, so the scheme is consistent: the pre-activation variance is the input's second moment multiplied by 2, and the ReLU then takes half of it back.
QuestionWhy: explain why the He rule uses only the number of inputs, while Xavier uses the average of inputs and outputs.Show answer
The He derivation tracks the forward pass, where the variance of each output depends on how many inputs are summed, . Xavier averages the forward condition with the backward condition, which depends on , so that both directions keep roughly the same scale. He et al. judge the forward pass to matter most for ReLU networks, so they use alone, although the backward version is also valid.
QuestionApplied: you are training a 30-layer ReLU network with dense layers, and the loss does not move in the first few hundred steps. Suggest a diagnosis involving initialization.Show answer
Check the scale of the activations at each layer right after initialization. If the root-mean-square falls steadily with depth, the initialization is probably too small for ReLU, and the early layers get tiny gradients. Switching the weights to He initialization, with variance , and re-measuring the scales is the usual fix. A residual connection, or a normalization layer, can also be added if the depth must stay.