Search

Search papers and lessons

Delving Deep into Rectifiers (He initialization, PReLU)

Kaiming He, Xiangyu Zhang, Shaoqing Ren et al. · 2015

Kaiming He et al. (2015) add PReLU, a ReLU with a learned negative slope, and a starting-weight rule that accounts for ReLU, so 30-layer networks train from scratch.

On this page

  • Colour = topic mix
  • Neural network basics
  • Calculus
  • Probability
  • Linear algebra
  • Losses & regularization
  • Optimizers
  • Sign in to see your progress

TL;DR

Kaiming He, Xiangyu Zhang, Shaoqing Ren and Jian Sun made two changes to rectifier networks in 2015. The first is the parametric ReLU (PReLU): a ReLU whose negative-side slope is a number the network learns, one per channel, at almost no extra cost. The second is a starting-weight rule that accounts for the fact that a ReLU throws away the negative half of its input. With that rule, a 30-layer network trains from scratch. Their ensemble reached 4.94% top-5 error on ImageNet, below the 5.1% human figure reported by the dataset authors.

Where you'll see it: the He-normal initializers (kaiming_normal_ in PyTorch, HeNormal in Keras) that set the starting weights of almost every ReLU network, and PReLU layers available as drop-in activations in the major frameworks.

The problem

By 2014 the rectifier had replaced sigmoid-like units in most deep networks. A ReLU is cheap to compute, speeds up training, and leads to better solutions than the older units. Two problems were still open.

The first was the shape of the activation. A ReLU sets every negative input to zero. The slope on the negative side is fixed at zero, and nothing lets the network choose a different response.

The second was getting very deep networks to start learning at all. The authors observed that a convolutional network whose weights are drawn from a Gaussian with a fixed standard deviation of 0.01 has trouble converging once it has more than about 8 convolutional layers. The VGG team worked around this by pre-training a shallow network and using it to initialize a deeper one, which costs training time and may land in a poorer local optimum. Other groups added auxiliary classifiers to middle layers to help gradients reach the early layers.

The principled alternative was Xavier (Glorot) initialization, which scales the weight variance by the layer's fan-in and fan-out (the paper compares against the forward-only form, nlVar⁡[wl]=1n_l \operatorname{Var}[w_l] = 1). Its derivation assumes the activations are linear. A ReLU is not linear, and the paper argues that this assumption breaks for rectifier networks. The field needed a starting-weight rule derived for rectifiers, so that networks of 20 to 30 layers could be trained directly.

Key idea

The paper makes two observations, and each one leads to a piece of the method.

The first is that the negative slope of the rectifier should be learned. If the slope is a parameter, training can move it anywhere between zero (a ReLU) and one (a plain linear unit). The network decides, layer by layer and channel by channel, how much negative signal to keep. Figure 1 of the paper shows the two shapes side by side: ReLU is a hard corner at zero, while PReLU has a learned tilt on the negative side.

The second is that initialization has to respect the fact that a ReLU keeps only about half of its signal. When you track how the variance of the activations changes from layer to layer, that halving is a factor of 1/2 at every layer. Over 30 layers that factor compounds. The paper derives the starting variance that cancels it, and the derivation gives a scale that is larger than Xavier's by a factor of 2\sqrt{2} per layer.

The method

The PReLU activation

For the input yiy_i on channel ii, the activation is

f(yi)={yi,\mboxifyi>0ai yi,\mboxifyi≤0f(y_{i})=\begin{cases}y_{i},&\mbox{if }y_{i} \gt 0\\ a_{i}\,y_{i},&\mbox{if }y_{i} \le 0\end{cases}

Equivalently, f(yi)=max⁡(0,yi)+aimin⁡(0,yi)f(y_i) = \max(0, y_i) + a_i \min(0, y_i). Here aia_i is the slope on the negative side. When ai=0a_i = 0 this is a ReLU. A fixed ai=0.01a_i = 0.01 is the leaky ReLU studied by Maas et al. The PReLU makes aia_i a parameter that is trained with the rest of the network.

There are two ways to share the parameter. The channel-wise version has one aia_i per channel, so a layer with 64 channels has 64 extra parameters. The channel-shared version has one aa for the whole layer. Either way the number of extra parameters is tiny compared with the weights of the convolution filters, so the authors expect little risk of overfitting.

Learning the slope

The gradient of the loss E\mathcal{E} with respect to the slope is found by the chain rule. The derivative of the activation with respect to aia_i is zero where yi>0y_i \gt 0 and equal to yiy_i where yi≤0y_i \le 0. So the gradient is a sum over every position of the feature map,

∂E∂ai=∑yi∂E∂f(yi) ∂f(yi)∂ai.\frac{\partial \mathcal{E}}{\partial a_{i}}=\sum_{y_{i}}\frac{\partial \mathcal{E}}{\partial f(y_{i})}\,\frac{\partial f(y_{i})}{\partial a_{i}}.

The authors update aia_i with momentum, Δai:=μΔai+ϵ ∂E/∂ai\Delta a_i := \mu \Delta a_i + \epsilon \, \partial \mathcal{E} / \partial a_i, where μ\mu is the momentum and ϵ\epsilon is the learning rate. Two choices in this update matter.

First, there is no weight decay on aia_i. Weight decay pulls parameters toward zero, and for aia_i that means pulling the unit back toward a ReLU. The paper says that even without regularization the learned values rarely exceed 1 in magnitude.

Second, aia_i is not constrained to be positive or below one. The activation can become non-monotonic if training pushes the slope below zero. The paper initializes every aia_i to 0.25.

Starting-weight rule for the forward pass

The layer response is yl=Wlxl+bl\mathbf{y}_l = \mathrm{W}_l \mathbf{x}_l + \mathbf{b}_l, where xl=f(yl−1)\mathbf{x}_l = f(\mathbf{y}_{l-1}). A filter with k×kk \times k spatial size over cc input channels sees nl=k2cn_l = k^2 c inputs. The derivation assumes that the weights are independent with zero mean, and that the inputs are independent of the weights. Then the variance of one output element is

Var⁡[yl]=nlVar⁡[wl] E[xl2].\operatorname{Var}[y_l] = n_l \operatorname{Var}[w_l] \, \mathbb{E}[x_l^2].

The step that differs from Xavier is the second moment E[xl2]\mathbb{E}[x_l^2]. For a zero-mean input, E[x2]=Var⁡[x]\mathbb{E}[x^2] = \operatorname{Var}[x]. A ReLU output is not zero-mean, so the two quantities differ. If wl−1w_{l-1} is symmetric around zero and bl−1=0b_{l-1} = 0, then yl−1y_{l-1} is symmetric around zero. A ReLU then satisfies E[xl2]=12Var⁡[yl−1]\mathbb{E}[x_l^2] = \tfrac{1}{2}\operatorname{Var}[y_{l-1}], which gives

Var⁡[yl]=12nlVar⁡[wl]Var⁡[yl−1].\operatorname{Var}[y_l] = \tfrac{1}{2} n_l \operatorname{Var}[w_l] \operatorname{Var}[y_{l-1}].

Chaining this over LL layers gives Var⁡[yL]=Var⁡[y1]∏l=2L12nlVar⁡[wl]\operatorname{Var}[y_L] = \operatorname{Var}[y_1] \prod_{l=2}^{L} \tfrac{1}{2} n_l \operatorname{Var}[w_l]. The signal stays at a sensible scale if every factor in the product is 1, so the rule is

12nlVar⁡[wl]=1⇒wl∼N ⁣(0,2nl).\tfrac{1}{2} n_l \operatorname{Var}[w_l] = 1 \quad \Rightarrow \quad w_l \sim \mathcal{N}\!\left(0, \tfrac{2}{n_l}\right).

The standard deviation is 2/nl\sqrt{2/n_l}. Biases start at zero. Xavier's rule has nlVar⁡[wl]=1n_l \operatorname{Var}[w_l] = 1 instead, which is off by exactly the factor of 2 that ReLU removes.

Starting-weight rule for the backward pass

Gradients flow backward through the transposed filters. Writing n^l=kl2dl\hat{n}_l = k_l^2 d_l for the number of outputs that touch one gradient element, with dld_l the number of filters, the same argument gives

12n^lVar⁡[wl]=1⇒std=2/n^l.\tfrac{1}{2} \hat{n}_l \operatorname{Var}[w_l] = 1 \quad \Rightarrow \quad \text{std} = \sqrt{2/\hat{n}_l}.

The two rules differ only in nln_l versus n^l\hat{n}_l. The paper notes that either one is enough to keep the signal from exploding or vanishing, because if the forward pass is scaled correctly, the backward pass is too in most architectures. For the ImageNet experiments the authors used the backward version, Eq. (14) in the paper.

Generalizing to PReLU

If the starting value of the PReLU slope is aa, the ReLU factor 12\tfrac{1}{2} becomes 12(1+a2)\tfrac{1}{2}(1 + a^2):

12(1+a2) nlVar⁡[wl]=1.\tfrac{1}{2}(1 + a^2)\, n_l \operatorname{Var}[w_l] = 1.

When a=0a = 0 this is the ReLU rule. When a=1a = 1 the unit is linear and the rule reduces to Xavier's.

Checking the scale on a real model

The paper checks the rule against the VGG team's model B, which has 10 convolutional layers with 3×33 \times 3 filters. The filter counts are 64, 128, 256 and 512 across four groups of layers. With n^l=9dl\hat{n}_l = 9 d_l, the rule gives standard deviations of about 0.059, 0.042, 0.029 and 0.021. A fixed standard deviation of 0.01 is much too small for the deeper groups. The paper estimates that the gradient reaching conv2 is then smaller than the derived value by a factor of about 1/(1.7×104)1/(1.7 \times 10^4). That is consistent with the diminishing gradients seen in the VGG experiments.

Results

PReLU on a small network

The first experiment uses a 14-layer model, model E of the authors' earlier constrained-cost paper. The baseline uses ReLU and reaches 33.82% top-1 and 13.34% top-5 error on ImageNet 2012, with 10-view testing. Replacing every ReLU with a PReLU and training from scratch gives the following.

Activationtop-1 errortop-5 error
ReLU33.8213.34
PReLU, channel-shared32.7112.87
PReLU, channel-wise32.6412.75

The channel-shared version adds only 13 parameters to the whole network, and it still gains 1.1 points of top-1 error (the channel-wise version gains 1.18, which the paper rounds to 1.2). The paper reads this as evidence that learning the shape of the activation matters even when the number of parameters is small.

The learned slopes are informative. In the channel-wise version the first convolution layer ends with slopes of about 0.6 to 0.7. The authors read this as the filters, which look like edge and texture detectors, keeping both the positive and negative responses. The slopes in deeper layers are generally smaller, which suggests that the network becomes more nonlinear as depth increases.

PReLU on a large network

On the 19-layer model A, the paper reports the following ImageNet 2012 validation results with dense testing over multiple scales.

Model Atop-1 errortop-5 error
ReLU, multi-scale24.026.51
PReLU, multi-scale22.976.28

PReLU lowers top-1 error by 1.05 points and top-5 error by 0.23 points, at almost no extra computational cost.

Initialization on deep networks

Training a 22-layer model with the new initialization and with Xavier's both converges, but the new initialization starts reducing error earlier. On the 14-layer ReLU model the accuracies are close: 33.82/13.34 for the new rule and 33.90/13.44 for Xavier.

The difference appears with depth. The paper builds a 30-layer model, 27 convolutional and 3 fully connected layers, by adding up to sixteen 256-filter convolutions to the 14-layer model. Xavier's initialization stalls completely and the gradients diminish. The new initialization converges. The 30-layer model reaches 38.56% top-1 and 16.59% top-5 error, which is worse than the 14-layer model. The authors say this is not a fault of the initialization. They suspect that depth alone does not help on ImageNet, or that the task is not complex enough to reward it.

Single models and the ensemble

Single models are tested with multi-scale and multi-view or dense testing. The baseline model A with ReLU reaches 6.51% top-5 error. The best single model, model C with PReLU, reaches 5.71% top-5 error (24.27% top-1 and 7.38% top-5 with plain 10-view testing, against 9.33% top-5 for VGG-16 under the same test), which the authors state is better than all the earlier multi-model results. Model C is a wider version of model B, with about 2.3 times the computational cost. The authors chose width over depth because they observed that very deep models degraded in early training.

The final result is an ensemble of six models, evaluated by the ILSVRC test server because the test labels are not published. It reaches 4.94% top-5 error. The 2014 winner GoogLeNet had 6.66%, so the result is about 26% relative better. The authors also compare it with a later Baidu result at 5.98%.

Comparison with humans

Russakovsky et al. reported a human top-5 error of 5.1% on ImageNet. That figure comes from a single annotator who was trained on the validation images and given a special test interface, on a random subset of 1500 test images. The authors say their 4.94% is the first published result on this challenge to beat that figure. They are careful about what it means. The errors humans make are mostly fine-grained classes such as dog breeds, and the network does well there, but the network still makes mistakes that are easy for humans, especially ones that need context. The paper does not claim that machines see better than humans in general.

Error analysis

The per-class breakdown is also useful. The ensemble has zero top-5 error on 113 classes. The hardest three are "letter opener" at 49%, "spotlight" at 38% and "restaurant" at 36%, mostly because of multiple objects, small objects, or large variation within a class. Compared with the authors' own 2014 entry at 8.06% average top-5 error, the error fell in 824 classes, stayed the same in 127, and rose in 49.

Why it mattered

PReLU is a small change to an activation function, and it became a standard option. Its main lesson is that a few learned parameters, placed in the right spot, can improve accuracy with almost no cost. Most later activations take this further by making the nonlinearity itself adaptive or by changing its shape.

The initialization rule had a larger and more lasting effect. It became the default starting scale for ReLU networks in the major frameworks, and the factor of 2 is now the rule most practitioners use without thinking about it. The paper also showed that the choice of initialization can decide whether a deep network trains at all, which shaped how later architectures were designed.

The paper left one problem open. A 30-layer plain network trained, but it did not do better than a shallower one. The authors said the initialization "paves a foundation" for studying depth and hoped it would help on harder tasks. A later paper by the same first author, on residual networks, addressed exactly that problem by adding identity shortcut connections so that extra layers do not have to learn anything to be harmless. See residual connections for the idea.

Reading guide

Read the paper in this order and use these lessons as the prerequisites for each part.

  1. Section 1, Introduction. Needs Convolutional Neural Network, Activation Function and Rectified Linear Unit (ReLU). The only vocabulary is the rectifier and the overfitting trade-off.
  2. Section 2.1, Parametric Rectifiers. Needs Parametric ReLU (PReLU), Backpropagation for the chain rule that gives the slope gradient, Stochastic Gradient Descent, and Momentum for the update rule on aia_i.
  3. Section 2.2, Forward propagation case. Needs Mean and Variance and Gaussian (Normal) Distribution for the variance argument and for the Gaussian initialization. The idea is in He (Kaiming) Initialization.
  4. Section 2.2, Backward propagation case. Same prerequisites, plus Vanishing Gradient Problem, because this is the reason the backward factor matters.
  5. Section 2.2, Comparisons with Xavier. Needs Xavier (Glorot) Initialization, which is the baseline the paper is correcting.
  6. Section 2.3 and Section 3. Needs Convolutional Neural Network, Dropout (the 50 percent dropout in the first two fully connected layers) and Stochastic Gradient Descent for the training schedule.
  7. Section 4, Experiments. Only the error metrics are needed. Top-5 error is the fraction of test images whose correct label is not among the five highest-scoring predictions.

Check yourself

QuestionWhat is the negative-side slope of a PReLU when a is 0, when a is 0.01, and when a is 1?Show answer

When a=0a = 0 it is a ReLU, which sets all negative inputs to zero. When a=0.01a = 0.01 it is a leaky ReLU with a small fixed slope. When a=1a = 1 it is the identity on the negative side, so the unit is linear.

QuestionA convolution layer has 3 by 3 filters and 256 input channels. Using the forward-pass rule with n=k2cn = k^2 c, what standard deviation should its weights start with?Show answer

The number of inputs is n=32×256=2304n = 3^2 \times 256 = 2304. The rule gives a standard deviation of 2/2304=0.000868≈0.029\sqrt{2/2304} = \sqrt{0.000868} \approx 0.029. Xavier's rule would give 1/2304≈0.021\sqrt{1/2304} \approx 0.021.

QuestionIf the PReLU slope starts at a = 0.25, what variance should the weights start with, compared with the ReLU rule of 2 over n?Show answer

The generalized rule is 12(1+a2)nVar⁡[w]=1\tfrac{1}{2}(1 + a^2) n \operatorname{Var}[w] = 1. With a=0.25a = 0.25, 12(1+0.0625)=0.53125\tfrac{1}{2}(1 + 0.0625) = 0.53125, so Var⁡[w]=1/(0.53125 n)≈1.88/n\operatorname{Var}[w] = 1/(0.53125\, n) \approx 1.88/n. That is slightly smaller than the ReLU value of 2/n2/n, because the PReLU passes a little signal through its negative side.

QuestionWhy does the paper not apply weight decay to the PReLU slopes, and why is that a sensible choice?Show answer

Weight decay pulls each parameter toward zero. For a slope, zero means a ReLU, so weight decay would push every PReLU back toward the ReLU it was meant to generalize. Leaving the slopes unregularized lets the data decide the shape of each activation. The paper reports that the learned values rarely exceed 1 in magnitude even without regularization.

QuestionXavier's initialization stalled on the 30-layer model while the new rule trained. Using the paper's argument, roughly how much does a ReLU-only network under Xavier shrink the signal over 30 layers?Show answer

Each ReLU layer roughly halves the variance that Xavier's derivation assumed it would keep. The paper puts it as Xavier's weight standard deviation being 1/2L1/\sqrt{2}^{L} of the derived one, so over L=30L = 30 layers the signal is scaled by about 2−15≈3×10−52^{-15} \approx 3 \times 10^{-5}. The signal and its gradients fade to almost nothing, so the deep network cannot learn. The new rule cancels the factor of 1/2 at each layer, so the scale stays roughly constant. Note that the same paper found Xavier still converged for models up to 22 layers (a factor of 2−112^{-11}), only more slowly at the start, so this estimate is an order-of-magnitude argument rather than a sharp threshold.

Sources

Read the full paper

Kaiming He, Xiangyu Zhang, Shaoqing Ren et al., 2015. arXiv:1502.01852