Weight Initialization › He Initialization for ReLU Networks

Michael BrenndoerferApril 25, 20256 min read
Language AI HandbookAll chapters
Part 10 of 67Neural Network Foundations
Chapter 70Weight Initialization › He Initialization for ReLU Networks
Reading section 7 of 19 · He Initialization for ReLU Networks · 6 minSection 7 of 19 · 6 min

Book contents

Section 7 of 19 · 6 min read

Weight Initialization › He Initialization for ReLU NetworksOne section · Sections in this chapter7 / 19 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Xavier initialization was a breakthrough for networks with tanh or sigmoid activations. But by the mid-2010s, ReLU (Rectified Linear Unit) had become the dominant activation function due to its simplicity and its resistance to the vanishing gradient problem. Unfortunately, Xavier initialization performs poorly in ReLU networks.

The problem is fundamental. Xavier's derivation assumes the activation function is approximately linear near zero, so it does not systematically distort variance. Tanh and sigmoid satisfy this: near zero, both behave approximately like the identity function. ReLU does not. It zeros all negative inputs, keeping only the positive half of the distribution. This asymmetry means ReLU is far from linear around zero, and the linear approximation underlying Xavier's derivation breaks down completely.

The practical consequence is severe. A deep ReLU network initialized with Xavier will see its activations slowly collapse toward zero as the depth increases, because each ReLU layer systematically discards half the information by zeroing all negative values. The network can still learn, but it starts from a much worse position than necessary.

ReLU's Variance Halving Effect

Consider a pre-activation zz drawn from a symmetric distribution centered at zero with variance σ2\sigma^2. ReLU applies ReLU(z)=max⁡(0,z)\text{ReLU}(z) = \max(0, z), zeroing all negative values while keeping positive values unchanged. Since the distribution is symmetric around zero, approximately half the values are negative and become zero.

The variance of the ReLU output is:

Var(ReLU(z))≈σ22\text{Var}(\text{ReLU}(z)) \approx \frac{\sigma^2}{2}

where:

  • ReLU(z)=max⁡(0,z)\text{ReLU}(z) = \max(0, z): the rectified linear unit function that passes positive inputs and zeros negative ones
  • σ2\sigma^2: the variance of the input pre-activation zz before applying ReLU
  • 12\frac{1}{2}: the variance reduction factor, because ReLU eliminates roughly half the distribution (all values below zero)

To see this more carefully, consider the expected squared output of ReLU applied to z∼N(0,σ2)z \sim \mathcal{N}(0, \sigma^2):

E[ReLU(z)2]=E[z2⋅1z>0]=12E[z2]=σ22\mathbb{E}[\text{ReLU}(z)^2] = \mathbb{E}[z^2 \cdot \mathbf{1}_{z > 0}] = \frac{1}{2}\mathbb{E}[z^2] = \frac{\sigma^2}{2}

The indicator 1z>0\mathbf{1}_{z > 0} is 1 when zz is positive and 0 when negative. Since zz has zero mean, E[ReLU(z)]=E[z⋅1z>0]=σ/2π\mathbb{E}[\text{ReLU}(z)] = \mathbb{E}[z \cdot \mathbf{1}_{z > 0}] = \sigma / \sqrt{2\pi}, which is nonzero. The variance therefore equals E[ReLU(z)2]−(E[ReLU(z)])2\mathbb{E}[\text{ReLU}(z)^2] - (\mathbb{E}[\text{ReLU}(z)])^2. For large networks where the number of neurons is large, the mean contribution to variance is much smaller than σ2/2\sigma^2/2, and the approximation Var(ReLU(z))≈σ2/2\text{Var}(\text{ReLU}(z)) \approx \sigma^2/2 holds well.

This variance halving has severe consequences for deep networks. After LL ReLU layers, variance shrinks by a factor of 2L2^L. A 10-layer ReLU network reduces activation variance by 210=10242^{10} = 1024. A 20-layer network reduces it by over a million. Xavier initialization, calibrated assuming no such reduction, produces vanishing activations in deep ReLU networks.

Deriving He Initialization

Kaiming He and colleagues addressed this in their 2015 paper "Delving Deep into Rectifiers: Surpassing Human-Level Performance on ImageNet Classification." Their derivation modifies the Xavier variance equation to include ReLU's variance reduction factor.

Starting from the variance propagation equation with the ReLU correction:

Var(a)=12⋅nin⋅Var(w)⋅Var(x)\text{Var}(a) = \frac{1}{2} \cdot n_{\text{in}} \cdot \text{Var}(w) \cdot \text{Var}(x)

where:

  • Var(a)\text{Var}(a): variance of the activation output, that is, the distribution after applying ReLU
  • 12\frac{1}{2}: the variance reduction factor from ReLU zeroing all negative pre-activation values
  • ninn_{\text{in}}: fan-in (number of input connections)
  • Var(w)\text{Var}(w): variance of the weights in this layer
  • Var(x)\text{Var}(x): variance of the input activations from the previous layer

To maintain Var(a)=Var(x)\text{Var}(a) = \text{Var}(x), we set:

Var(x)=12⋅nin⋅Var(w)⋅Var(x)\text{Var}(x) = \frac{1}{2} \cdot n_{\text{in}} \cdot \text{Var}(w) \cdot \text{Var}(x)

Dividing both sides by Var(x)\text{Var}(x):

1=12⋅nin⋅Var(w)1 = \frac{1}{2} \cdot n_{\text{in}} \cdot \text{Var}(w)

Solving for the weight variance:

Var(w)=2nin\text{Var}(w) = \frac{2}{n_{\text{in}}}

This is He initialization (also called Kaiming initialization). The factor of 2 compensates precisely for ReLU's variance-halving effect. Notice that He uses only ninn_{\text{in}} rather than averaging ninn_{\text{in}} and noutn_{\text{out}} as Xavier does. He et al. found that matching forward pass variance was the more critical constraint for deep ReLU networks in practice, and empirical results confirmed that omitting the fan-out term worked better for the very deep convolutional networks they were studying.

He/Kaiming Initialization

A weight initialization scheme where weights are drawn from a distribution with variance 2/nin2/n_{\text{in}}. Designed specifically for ReLU networks, the factor of 2 in the numerator exactly compensates for the variance-halving effect of setting negative activations to zero.

Converting to distribution parameters:

Normal distribution:

w∼N ⁣(0,2nin)w \sim \mathcal{N}\!\left(0, \sqrt{\frac{2}{n_{\text{in}}}}\right)

where 2/nin\sqrt{2/n_{\text{in}}} is the standard deviation (the square root of the target variance).

Uniform distribution: Using the same derivation as for Xavier, where the variance of U[−a,a]U[-a, a] equals a2/3a^2/3, we solve a2/3=2/nina^2/3 = 2/n_{\text{in}} to obtain a=6/nina = \sqrt{6/n_{\text{in}}}:

w∼U ⁣[−6nin,6nin]w \sim U\!\left[-\sqrt{\frac{6}{n_{\text{in}}}}, \sqrt{\frac{6}{n_{\text{in}}}}\right]

Implementation and Comparison

In[14]:
Code
def he_normal(shape):
    """He initialization with normal distribution."""
    fan_in, fan_out = shape
    std = np.sqrt(2 / fan_in)
    return np.random.randn(*shape) * std


def he_uniform(shape):
    """He initialization with uniform distribution."""
    fan_in, fan_out = shape
    limit = np.sqrt(6 / fan_in)
    return np.random.uniform(-limit, limit, shape)
Out[15]:
Console
Comparing Xavier and He initialization on ReLU network:
------------------------------------------------------------

Xavier normal:
  Layer  0: std = 0.9990
  Layer  1: std = 0.5859
  Layer  2: std = 0.4019
  Layer  3: std = 0.2649
  Layer  4: std = 0.1818
  Layer  5: std = 0.1210
  Layer  6: std = 0.0794
  Layer  7: std = 0.0576
  Layer  8: std = 0.0443
  Layer  9: std = 0.0320
  Layer 10: std = 0.0238

He normal:
  Layer  0: std = 1.0011
  Layer  1: std = 0.8270
  Layer  2: std = 0.8115
  Layer  3: std = 0.8722
  Layer  4: std = 0.9080
  Layer  5: std = 0.9697
  Layer  6: std = 0.9750
  Layer  7: std = 1.0024
  Layer  8: std = 1.0809
  Layer  9: std = 1.1509
  Layer 10: std = 1.1800

He initialization maintains stable activation magnitudes in ReLU networks, while Xavier causes activations to decay layer by layer because it does not account for the variance reduction from ReLU.

Out[16]:
Visualization
Line plot showing activation standard deviation across 10 layers, with He initialization stable and Xavier decaying in a ReLU network.
Activation standard deviation across 10 layers for Xavier and He initialization in a ReLU network. Xavier initialization causes activations to progressively decay because it does not account for ReLU's variance-halving effect. He initialization compensates exactly for this reduction and maintains stable activation magnitudes throughout the entire network.