学习资料 理解深度学习 第 11 章 · 残差网络
学 习 资 料 · 中 英 对 照

第 11 章 · 残差网络

Understanding Deep Learning — Residual networks

残差网络
Residual networks

The previous chapter described how image classification performance improved as the depth of convolutional networks was extended from eight layers (AlexNet) to nineteen layers (VGG). This led to experimentation with even deeper networks. However, performance decreased again when many more layers were added.

This chapter introduces residual blocks. Here, each network layer computes an additive change to the current representation instead of transforming it directly. This allows deeper networks to be trained but causes an exponential increase in the activation magnitudes at initialization. Residual blocks employ batch normalization to compensate for this, which re-centers and rescales the activations at each layer.

Residual blocks with batch normalization allow much deeper networks to be trained, and these networks improve performance across a variety of tasks. Architectures that combine residual blocks to tackle image classification, medical image segmentation, and human pose estimation are described.

上一章描述了随着卷积网络的深度从八层(AlexNet)扩展到十九层(VGG),图像分类性能如何得到提升。这促使人们尝试更深的网络。然而,当添加更多层时,性能再次下降。

本章介绍残差块。在这里,每一网络层计算的是对当前表示的加性变化,而不是直接对其进行变换。这使得更深的网络可以被训练,但会导致初始化时激活值幅度呈指数增长。残差块采用批归一化来补偿这一问题,从而在每一层重新中心化并重新缩放激活值。

带有批归一化的残差块允许训练更深的网络,并且这些网络在多种任务上提升了性能。文中介绍了将残差块组合起来用于图像分类、医学图像分割和人体姿态估计的架构。

11.1 顺序处理
11.1 Sequential processing

Every network we have seen so far processes the data sequentially; each layer receives the previous layer’s output and passes the result to the next (figure 11.1). For example, a three-layer network is defined by:

到目前为止,我们见过的每个网络都是按顺序处理数据的;每一层接收上一层的输出,并将结果传递给下一层(图 11.1)。例如,一个三层网络定义为:

where h 1, h 2, and h 3 denote the intermediate hidden layers, x is the network input, y is the output, and the functions f k[•, ϕk] perform the processing. In a standard neural network, each layer consists of a linear transformation followed by an activation function, and the parameters ϕk comprise the weights and biases of the

其中 h 1, h 2, 和 h 3 表示中间隐藏层, x 是网络输入, y 是输出,函数 f k[•, ϕk] 执行处理。

linear transformation. In a convolutional network, each layer consists of a set of convolutions followed by an activation function, and the parameters comprise the convolutional kernels and biases.

Since the processing is sequential, we can equivalently think of this network as a series of nested functions:

线性变换。在卷积网络中,每一层由一组卷积后接一个激活函数组成,而参数包含卷积核和偏差。

由于处理是顺序进行的,我们可以等价地将该网络看作一系列嵌套函数:

图 11.1 顺序处理。标准神经网络将每一层的输出直接传入下一层。
图 11.1 顺序处理。标准神经网络将每一层的输出直接传入下一层。Figure 11.1 Sequential processing. Standard neural networks pass the output of each layer directly into the next layer.
11.1.1 顺序处理的局限性
11.1.1 Limitations of sequential processing

In principle, we can add as many layers as we want, and in the previous chapter, we saw that adding more layers to a convolutional network does improve performance; the VGG network (figure 10.17), which has nineteen layers, outperforms AlexNet (figure 10.16), which has eight layers. However, image classification performance decreases again as further layers are added (figure 11.2). This is surprising since models generally perform better as more capacity is added (figure 8.10). Indeed, the decrease is present for both the training set and the test set, which implies that the problem is training deeper networks rather than the inability of deeper networks to generalize.

This phenomenon is not completely understood. One conjecture is that right after initialization, the loss gradients change unpredictably when we modify parameters in early network layers. With appropriate initialization of the weights (see section 7.5), the gradient of the loss with respect to these parameters will be reasonable (i.e., no exploding or vanishing gradients). However, the derivative assumes an infinitesimal change in the parameter, whereas optimization algorithms use a finite step size. Any reasonable choice of step size may move to a place with a completely different and unrelated gradient; the loss surface looks like an enormous range of tiny mountains rather than a single smooth structure that is easy to descend. Consequently, the algorithm doesn’t make progress in the way that it does when the loss function gradient changes more slowly.

This conjecture is supported by empirical observations of gradients in networks with a single input and output. For a shallow network, the gradient of the output with respect to the input changes slowly as we change the input (figure 11.3a). However, for a deep network, a tiny change in the input results in a completely different gradient (figure 11.3b). This is captured by the autocorrelation function of the gradient (figure 11.3c). Nearby gradients are correlated for shallow networks, but this correlation quickly drops to zero for deep networks. This is termed the shattered gradients phenomenon.

原则上,我们可以添加任意多的层,并且在上一章中我们看到,向卷积网络中添加更多层确实能够改善性能;拥有十九层的 VGG 网络(图 10.17)优于拥有八层的 AlexNet (图 10.16)。然而,随着进一步添加层,图像分类性能会再次下降(图 11.2)。这令人惊讶,因为模型通常在增加更多容量时表现更好(图 8.10)。事实上,训练集和测试集上都存在这种下降,这意味着问题在于训练更深的网络,而不是更深的网络无法泛化。这种现象尚未被完全理解。一种猜想是,刚完成初始化后,当我们修改网络前几层的参数时,损失梯度会不可预测地变化。通过对权重进行适当初始化(见第 7.5 节),损失相对于这些参数的梯度会是合理的(即不会出现梯度爆炸或梯度消失)。然而,导数假设参数发生无穷小变化,而优化算法使用有限步长。任何合理的选择

步长选择可能会移动到一个梯度完全不同且无关的位置;损失面看起来像一片由无数微小山峰构成的巨大山脉,而不是一个易于下降的平滑结构。因此,算法不会像损失函数梯度变化更慢时那样取得进展。这一猜想得到了单输入单输出网络中梯度的经验观察的支持。对于浅层网络,当我们改变输入时,输出相对于输入的梯度变化缓慢(图 11.3a)。然而,对于一个

在深层网络中,输入的微小变化会导致完全不同的梯度(图 11.3b)。这可以通过梯度自相关函数来捕捉(图 11.3c)。对于浅层网络,相邻梯度是相关的,但在深层网络中,这种相关性会迅速降至零。这被称为梯度碎裂现象。

图 11.2 增加更多卷积层时性能下降。 a) 在 CIFAR-10 数据集的测试集上进行图像分类时,一个 20 层卷积网络的表现优于一个 56 层神经网络。
图 11.2 增加更多卷积层时性能下降。 a) 在 CIFAR-10 数据集的测试集上进行图像分类时,一个 20 层卷积网络的表现优于一个 56 层神经网络。 b) 在训练集上也是如此,这表明问题与原始网络的训练有关,而不是对新数据泛化失败。改编自 He 等人(2016a)。Figure 11.2 Decrease in performance when adding more convolutional layers. a) A 20-layer convolutional network outperforms a 56-layer neural network for image classification on the test set of the CIFAR-10 dataset (Krizhevsky & Hinton, 2009). b) This is also true for the training set, which suggests that the problem relates to training the original network rather than a failure to generalize to new data. Adapted from He et al. (2016a).

Shattered gradients presumably arise because changes in early network layers modify the output in an increasingly complex way as the network becomes deeper. The derivative of the output y with respect to the first layer f 1 of the network in equation 11.1 is: When we change the parameters that determine f 1, all of the derivatives in this sequence are evaluated at slightly different locations since layers f 2, f 3, and f 4 are themselves computed from f 1. Consequently, the updated gradient at each training example may be completely different, and the loss function becomes badly behaved. 1

梯度碎裂可能是由于随着网络变深,网络前几层的变化会以越来越复杂的方式改变输出。公式 11.1 中,输出 y 相对于网络第一层 f 1 的导数为:当我们改变决定 f 1, 的参数时,该序列中的所有导数都是在略有不同的位置进行求值,因为层 f 2,、 f 3, 和 f 4 本身由 f 1 计算得到。因此,每个训练样本上的更新梯度可能完全不同,损失函数会变得病态。 1

图 11.3 梯度碎裂。 a) 考虑一个具有 200 个隐藏单元、并对权重和偏差均采用 Glorot 初始化(不含因子 2 的 He 初始化)的浅层网络。标量网
图 11.3 梯度碎裂。 a) 考虑一个具有 200 个隐藏单元、并对权重和偏差均采用 Glorot 初始化(不含因子 2 的 He 初始化)的浅层网络。标量网络输出 y 对标量输入 x 的梯度 ∂y/∂x 随着我们改变输入 x 而变化相对缓慢。 b) 对于具有 24 层、每层 200 个隐藏单元的深层网络,该梯度变化非常迅速且不可预测。 c) 梯度的自相关函数表明,对于深层网络,相邻梯度变得不相关(自相关接近零)。这种梯度碎裂现象可能解释了为什么深层网络难以训练。梯度下降算法依赖于损失曲面相对平滑,因此每次更新步骤前后的梯度应当相关。改编自 Balduzzi 等人(2017)。Figure 11.3 Shattered gradients. a) Consider a shallow network with 200 hidden units and Glorot initialization (He initialization without the factor of two) for both the weights and biases. The gradient ∂y/∂x of the scalar network output y with respect to the scalar input x changes relatively slowly as we change the input x. b) For a deep network with 24 layers and 200 hidden units per layer, this gradient changes very quickly and unpredictably. c) The autocorrelation function of the gradient shows that nearby gradients become unrelated (have autocorrelation close to zero) for deep networks. This shattered gradients phenomenon may explain why it is hard to train deep networks. Gradient descent algorithms rely on the loss surface being relatively smooth, so the gradients should be related before and after each update step. Adapted from Balduzzi et al. (2017).
11.2 残差连接与残差块
11.2 Residual connections and residual blocks

Residual or skip connections are branches in the computational path, whereby the input to each network layer f[•] is added back to the output (figure 11.4a). By analogy to equation 11.1, the residual network is defined as:

where the first term on the right-hand side of each line is the residual connection. Each function f k learns an additive change to the current representation. It follows that their outputs must be the same size as their inputs. Each additive combination of the input and the processed output is known as a residual block or residual layer.

残差连接或跳跃连接是计算路径中的分支,其中每个网络层 f[•] 的输入会被加回输出(图 11.4a)。类比公式 11.1,残差网络定义为:

其中每一行右侧的第一项是残差连接。每个函数 f k 学习一个对当前表示的加性变化。因此,它们的输出必须与输入的大小相同。输入与处理后的输出的每个加性组合称为残差块或残差层。

Once more, we can write this as a single function by substituting in the expressions for the intermediate quantities h k: where we have omitted the parameters ϕ• for clarity. We can think of this equation as “unraveling” the network (figure 11.4b). We see that the final network output is a sum of the input and four smaller networks, corresponding to each line of the equation; one

再次,我们可以通过代入这些表达式将其写成单个函数对于中间量 h k: in 解释是,残差连接将原始网络变成了一个集成

公式

interpretation is that residual connections turn the original network into an ensemble of these smaller networks whose outputs are summed to compute the result.

f th 这些较小网络的输出被求和以计算结果。其中每条路径对应一项。右侧的恒等项表明,第一层中参数 ϕ1 在 f 1[ x ϕ1] 中的变化会直接影响网络输出 y 的变化。它们还会通过其他长度不同的导数链间接产生影响。通常,梯度经过较短的

图 11.4 残差连接。 a) 每个函数 f k[ x ϕk] 的输出都会被加回到其输入上,该输入经由一条称为残差连接或跳跃连接的并行计算路径传递。因此,该函数
图 11.4 残差连接。 a) 每个函数 f k[ x ϕk] 的输出都会被加回到其输入上,该输入经由一条称为残差连接或跳跃连接的并行计算路径传递。因此,该函数计算的是对表示的加性变化。 b) 在展开(解开)网络方程后,我们发现输出是输入加上四个较小网络之和(分别以白色、橙色、灰色和青色绘制,并对应公式 11.5 中的各项);我们可以将其视为一个网络集成。此外,青色网络的输出本身是另一个集成的变换 f 4[•, ϕ4],依此类推。或者,我们可以将该网络视为通过计算图的 16 条不同路径的组合。一个示例是从输入 x 到输出 y 的虚线路径,该路径在 (a) 和 (b) 面板中相同。Figure 11.4 Residual connections. a) The output of each function f k[ x , ϕk] is added back to its input, which is passed via a parallel computational path called a residual or skip connection. Hence, the function computes an additive change to the representation. b) Upon expanding (unraveling) the network equations, we find that the output is the sum of the input plus four smaller networks (depicted in white, orange, gray, and cyan, respectively, and corresponding to terms in equation 11.5); we can think of this as an ensemble of networks. the output from the cyan network is itself a transformation f 4[•, ϕ4] of another ensemble, and so on. Alternatively, we can consider the network as a combination of 16 different paths through the computational graph. One example is the dashed path from input x to output y, which is the same in panels (a) and (b). Moreover,

A complementary way of thinking about this residual network is that it creates sixteen paths with differing numbers of transformations between input and output. For example, the first function f 1[ x ] occurs in eight of these sixteen paths, including as a direct additive term (i.e., a path length of one), and the analogous derivative to equation 11.3 is:

where there is one term for each of the eight paths. The identity term on the righthand side shows that changes in the parameters ϕ1 in the first layer f 1[ x , ϕ1] contribute directly to changes in the network output y. They also contribute indirectly through the other chains of derivatives of varying lengths. In general, gradients through shorter paths will be better behaved. Since both the identity term and various short chains of derivatives will contribute to the derivative for each layer, networks with residual links suffer less from shattered gradients.

路径表现会更好。由于恒等项和各种较短的导数链都会对每一层的导数作出贡献,带有残差连接的网络受梯度破碎的影响较小。

11.2.1 残差块中的运算顺序
11.2.1 Order of operations in residual blocks

Until now, we have implied that the additive functions f[ x ] could be any valid network layer (e.g., fully connected or convolutional). This is technically true, but the order of operations in these functions is important. They must contain a nonlinear activation function like a ReLU, or the entire network will be linear. However, in a typical network layer (figure 11.5a), the ReLU function is at the end, so the output is non-negative. If we adopt this convention, then each residual block can only increase the input values.

Hence, it is typical to change the order of operations so that the activation function is applied first, followed by the linear transformation (figure 11.5b). Sometimes there may be several layers of processing within the residual block (figure 11.5c), but these usually terminate with a linear transformation. Finally, we note that when we start these blocks with a ReLU operation, they will do nothing if the initial network input is negative since the ReLU will clip the entire signal to zero. Hence, it’s typical to start the network with a linear transformation rather than a residual block, as in figure 11.5b.

到目前为止,我们一直暗示加法函数 f[ x ] 可以是任何有效的网络层(例如全连接层或卷积层)。这在技术上成立,但这些函数中的运算顺序很重要。它们必须包含一个非线性激活函数(如 ReLU),否则整个网络将变成线性的。然而,在典型的网络层(图 11.5a)中, ReLU 函数位于最后,因此输出非负。如果采用这种约定,那么每个残差块只能增加输入值。

因此,通常会调整运算顺序,先应用激活函数,再进行线性变换(图 11.5b)。有时残差块内部可能包含多层处理(图 11.5c),但这些处理通常以线性变换结束。最后,我们注意到,如果这些块以 ReLU 运算开始,当初始网络输入为负时, ReLU 会将整个信号截断为零,因此这些块将不起任何作用。所以,网络通常以线性变换而非残差块开始,如图 11.5b 所示。

11.2.2 具有残差连接的更深层网络
11.2.2 Deeper networks with residual connections

Adding residual connections roughly doubles the depth of a network that can be practically trained before performance degrades. However, we would like to increase the depth further. To understand why residual connections do not allow us to increase the depth arbitrarily, we must consider how the variance of the activations changes during the forward pass and how the gradient magnitudes change during the backward pass.

添加残差连接大致会使在性能下降之前可实际训练的网络深度加倍。然而,我们希望进一步增加深度。要理解为什么残差连接不能让我们任意增加深度,就必须考虑激活值的方差在前向传播过程中如何变化,以及梯度幅度在反向传播过程中如何变化。

11.3 残差网络中的梯度爆炸
11.3 Exploding gradients in residual networks

In section 7.5, we saw that initializing the network parameters is critical.

Without careful initialization, the magnitudes of the intermediate values during the forward pass of backpropagation can increase or decrease exponentially. Similarly, the gradients during the backward pass can explode or vanish as we move backward through the network.

在第 7.5 节中,我们看到初始化网络参数至关重要。如果不进行仔细初始化,反向传播的前向传播过程中中间值的幅度可能会指数级增大或减小。同样,当我们沿网络向后传播时,反向传播过程中的梯度也可能爆炸或消失。

Hence, we initialize the network parameters so that the expected variance of the activations (in the forward pass) and gradients (in the backward pass) remains the same between layers.

He initialization (section 7.5) achieves this for ReLU activations by initializing the biases β to zero and choosing normally distributed weights Ω with mean zero and variance 2/Dh where Dh is the number of hidden units in the previous layer.

因此,我们初始化网络参数,使得激活值(在前向传播中)和梯度(在反向传播中)的期望方差在各层之间保持一致。 He 初始化(第 7.5 节)针对 ReLU 激活实现了这一点:将偏差 β 初始化为零,并选择均值为零、方差为 2/Dh 的正态分布权重 Ω,其中 Dh 是上一层的隐藏单元数量。

Now consider a residual network. We do not have to worry about the intermediate values or gradients vanishing with network depth since there exists a path whereby each layer directly contributes to the network output (equation 11.5 and figure 11.4b). However, even if we use He initialization within the residual block, the values in the forward pass increase exponentially as we move through the network. To see why, consider that we add the result of the processing in the residual block back to the input. Each branch has some (uncorrelated) variability. Hence, the overall variance

现在考虑残差网络。由于存在一条路径,使每一层都直接对网络输出作出贡献(公式 11.5 和图 11.4b),我们不必担心中间值或梯度随网络深度而消失。然而,即使在残差块内使用 He 初始化,前向传播中的值随着在网络中逐层传播仍会指数级增长。

increases when we recombine them. With ReLU activations and He initialization, the expected variance is unchanged by the processing in each block. Consequently, when we recombine with the input, the variance doubles (figure 11.6a), growing exponentially with the number of residual blocks. This limits the possible network depth before floating point precision is exceeded in the forward pass.

A similar argument applies to the gradients in the backward pass of the backpropagation algorithm. Hence, residual networks still suffer from unstable forward propagation and exploding gradients even with He initialization. One approach that would stabilize the forward and backward passes would be to use He initialization and then multiply the combined output of each residual block by 1/

会在我们重新组合它们时增加。使用 ReLU 激活和 He 初始化时,每个块中的处理不会改变期望方差。因此,当我们与输入重新组合时,方差会加倍(图 11.6a),并随着残差块数量呈指数增长。这限制了在前向传播中超出浮点精度范围之前可能的网络深度。类似论证也适用于反向传播算法中反向传播阶段的梯度。因此,即使使用 He 初始化,残差网络仍然存在不稳定的前向传播和梯度爆炸问题。一种可以稳定前向传播和反向传播的方法是使用 He 初始化,然后将每个残差块的组合输出乘以 1/

2 to compensate for the doubling (figure 11.6b). However, it is more usual to use batch normalization.

2 以补偿加倍(图 11.6b)。然而,更常见的是使用批归一化。

公式
11.4 批归一化
11.4 Batch normalization

Batchnormalization or BatchNorm shifts and rescales each activation h so that its mean and variance across the batch B become values that are learned during training. First, the empirical mean mh and standard deviation sh are computed:

批归一化(BatchNorm)会对每个激活 h 进行平移和缩放,使其在批次 B 上的均值和方差变为训练期间学习到的值。首先,计算经验均值 mh 和标准差 sh:经过此操作后,所有激活值的均值为 δ,标准差为 γ

图 11.6 残差网络中的方差。 a) He 初始化确保经过线性加 ReLU 层 f k 后,期望方差保持不变。不幸的是,在残差网络中,每个残差块的输入会被加回
图 11.6 残差网络中的方差。 a) He 初始化确保经过线性加 ReLU 层 f k 后,期望方差保持不变。不幸的是,在残差网络中,每个残差块的输入会被加回到输出,因此方差在每一层翻倍(灰色数字表示方差)并呈指数增长。 b) 一种方法是在每个残差块之间按 1/ 2 对信号进行重新缩放。 c) 另一种方法使用批归一化(BN)作为残差块的第一步,并将相关偏移量 δ 初始化为零、缩放因子 γ 初始化为一。这使每一层的输入具有单位方差,并且采用 He 初始化后,输出方差也将为一。现在方差随残差块数量线性增长。一个副作用是,在初始化时,后面的网络层由残差连接主导,因此几乎是在计算恒等映射。Figure 11.6 Variance in residual networks. a) He initialization ensures that the expected variance remains unchanged after a linear plus ReLU layer f k. Unfortunately, in residual networks, the input of each block is added back to the output, so the variance doubles at each layer (gray numbers indicate variance) and grows exponentially. b) One approach would be to rescale the signal by 1/ each residual block. c) A second method uses batch normalization (BN) as the first step in the residual block and initializes the associated offset δ to zero and scale γ to one. This transforms the input to each layer to have unit variance, and with He initialization, the output variance will also be one. Now the variance increases linearly with the number of residual blocks. A side-effect is that, at initialization, later network layers are dominated by the residual connection and are hence close to computing the identity.
公式

where all quantities are scalars. Then we use these statistics to standardize the batch activations to have mean zero and unit variance:

公式

where ϵ is a small number that prevents division by zero if hi is the same for every member of the batch and sh= 0.

Finally, the normalized variable is scaled by γ and shifted by δ: After this operation, the activations have mean δ and standard deviation γ across all

公式

members of the batch. Both of these quantities are learned during training. Batch normalization is applied independently to each hidden unit. In a standard neural network with K layers, each containing D hidden units, there would be KD learned offsets δ and KD learned scales γ. In a convolutional network, the normalizing statistics are computed over both the batch and the spatial position. If there were K layers, each containing C channels, there would be KC offsets and KC scales. At test

批次中的成员。这两个量均在训练过程中学习。层,每层包含 C 个通道,就会有 KC 个偏移量和 KC 个缩放因子。在测试时,我们没

time, we do not have a batch from which we can gather statistics. To resolve this, the statistics mh and sh are calculated across the whole training dataset (rather than just a batch) and frozen in the final network.

有可以从中收集统计信息的批次。为了解决这个问题,统计量 mh 和 sh 是在整个训练数据集(而不是仅在一个批次)上计算的,并在最终网络中被冻结。

11.4.1 批归一化的成本与收益
11.4.1 Costs and benefits of batch normalization

Batch normalization makes the network invariant to rescaling the weights and biases that contribute to each activation; if these are doubled, then the activations also double, the estimated standard deviation sh doubles, and the normalization in equation 11.8 compensates for these changes. 2 This happens separately for each hidden unit. Consequently, there will be a large family of weights and biases that all produce the same effect. Batch normalization also adds two parameters, γ and δ, at every hidden unit, which makes the model somewhat larger.

Hence, it both creates redundancy in the weights and biases and adds extra parameters to compensate for that redundancy. This is obviously inefficient, but batch normalization also provides several benefits.

批归一化使网络在重新缩放每个激活所涉及的权重和偏差时保持不变;如果这些权重和偏差加倍,那么激活也会加倍,估计的标准差 sh 也会加倍,而式 11.8 中的归一化会补偿这些变化。 2 这种情况会对每个隐藏单元分别发生。因此,会存在一大族权重和偏差,它们都产生相同的效果。批归一化还会在每个隐藏单元处添加两个参数, γ 和 δ,这使模型稍大一些。因此,它既在权重和偏差中造成冗余,又添加额外参数来补偿这种冗余。这显然效率不高,但批归一化也带来若干好处。

Stable forward propagation:

If we initialize the offsets δ to zero and the scales γ to one, then each output activation will have unit variance. In a regular network, this ensures the variance is stable during forward propagation at initialization. In a residual network, the variance must still increase as we add a new source of variation to the input at each layer. However, it will increase linearly with each residual block; the kth layer adds one unit of variance to the existing variance of k (figure 11.6c).

At initialization, this has the side-effect that later layers make a smaller change to the overall variation than earlier ones. The network is effectively less deep at the start of training since later layers are close to computing the identity. As training proceeds, the network can increase the scales γ in later layers and can control its own effective depth.

稳定的前向传播:如果我们将偏移量 δ 初始化为零,并将缩放因子 γ 初始化为 1,那么每个输出激活值都将具有单位方差。在常规网络中,这确保了初始化时前向传播过程中的方差保持稳定。在残差网络中,由于我们在每一层都向输入添加了新的变差来源,方差仍必须增加。但是,它会随着每个残差块线性增长;第 kth 层向 k 的现有方差增加一个单位方差(图 11.6c)。

在初始化时,这会产生一个副作用:较后的层对整体变差的改变比较早的层更小。由于较后的层几乎是在计算恒等映射,因此在训练开始时,网络的有效深度实际上更浅。随着训练进行,网络可以增大较后层的缩放因子 γ,并可以控制自身的有效深度。

Higher learning rates:

Empirical studies and theory both show that batch normalization makes the loss surface and its gradient change more smoothly (i.e., reduces shattered gradients). This means we can use higher learning rates as the surface is more predictable. We saw in section 9.2 that higher learning rates improve test performance.

更高的学习率:实证研究和理论都表明,批归一化使损失面及其梯度的变化更平滑(即减少梯度破碎)。这意味着我们可以使用更高的学习率,因为损失面更可预测。我们在 9.2 节中看到,更高的学习率可改善测试性能。

Regularization:

We saw in chapter 9 that noise in the training process can improve generalization. BatchNorm injects noise because the normalization depends on the batch statistics. The activations for a given training example are normalized by an amount that depends on the other members of the batch and is different at each training iteration.

正则化:我们在第 9 章中看到,训练过程中的噪声可以提升泛化能力。 BatchNorm 会注入噪声,因为归一化依赖于批统计量。对于给定的训练样本,其激活值所进行的归一化程度取决于该批次的其他成员,并且在每次训练迭代中都不相同。

11.5 常见残差架构
11.5 Common residual architectures

Residual connections are now a standard part of deep learning pipelines. This section reviews some well-known architectures that incorporate them.

残差连接现已成为深度学习流水线的标准组成部分。本节 r 回顾了一些采用这些残差块的知名架构。

11.5.1 ResNet
11.5.1 ResNet

Residual blocks were first used in convolutional networks for image classification. The resulting networks are known as residual networks, or ResNets for short. In ResNets, each residual block contains a batch normalization operation, a ReLU activation function, and a convolutional layer. This is followed by the same sequence again before being added

back to the input (figure 11.7a). Trial and error have shown that this order of operations works well for image classification.

残差块最早被用于图像分类的卷积网络中。所得到的网络被称为残差网络,或简称为 ResNets。在 ResNets 中,每个残差块包含一个批归一化操作、一个 ReLU 激活函数和一个卷积层。随后再次执行相同的序列,然后才被相加

回到输入(图 11.7a)。反复试验表明,这种操作顺序在图像分类中效果良好。

For very deep networks, the number of parameters may become undesirably large. Bottleneck residual blocks make more efficient use of parameters using three convolutions. The first has a 1 × 1 kernel and reduces the number of channels. The second is a regular 3 × 3 kernel, and the third is another 1 × 1 kernel to increase the number of channels back to the original amount (figure 11.7b). In this way, we can integrate information over a 3 × 3 pixel area using fewer parameters.

The ResNet-200 model (figure 11.8) contains 200 layers and was used for image classification on the ImageNet database (figure 10.15). The architecture resembles AlexNet and VGG but uses bottleneck residual blocks instead of vanilla convolutional layers. As with AlexNet and VGG, these are periodically interspersed with decreases in spatial resolution and simultaneous increases in the number of channels. The resolution is decreased between adjacent ResNet blocks using convolutions with stride two. Channels are similarly added by either appending zeros to the representation or applying an extra 1 × 1 convolution. At the start of the network is a 7 × 7 convolutional layer, followed by a downsampling operation. At the end, a fully connected layer maps the block to a vector of length 1000. This is passed through a softmax layer to generate class probabilities.

对于非常深的网络,参数数量可能会变得过大。瓶颈残差块通过三次卷积更高效地利用参数。第一个采用 1 × 1 卷积核并减少通道数。第二个是常规 3 × 3 卷积核,第三个是另一个 1 × 1 卷积核,用于将通道数增加回原始数量(图 11.7b)。通过这种方式,我们可以使用更少的参数在 3 × 3 像素区域上整合信息。

ResNet-200 模型(图 11.8)包含 200 层,并曾用于 ImageNet 数据库上的图像分类(图 10.15)。该架构类似于 AlexNet 和 VGG,但使用瓶颈残差块代替普通卷积层。与 AlexNet 和 VGG 类似,这些结构会周期性地穿插空间分辨率的降低和通道数的同步增加。相邻 ResNet 模块之间使用步长为 2 的卷积来降低分辨率。通道数也通过类似方式增加,即在表示中补零或应用额外的 1 × 1 卷积。网络开头是一个 7 × 7 卷积层,随后是一个下采样操作。最后,全连接层将该模块映射为长度为 1000 的向量。该向量经过 Softmax 层生成类别概率。

The ResNet-200 model achieved a remarkable 4.8% error rate for the correct class being in the top five and 20.1% for identifying the correct class correctly. This compared favorably with AlexNet (16.4%, 38.1%) and VGG (6.8%, 23.7%) and was one of the first networks to exceed human performance (5.1% for being in the top five guesses). However, this model was conceived in 2016 and is far from state-of-the-art. At the time of writing, the best-performing model on this task has a 9.0% error for identifying the class correctly (see figure 10.21). This and all the other current top-performing models for image classification are now based on transformers (see chapter 12).

ResNet-200 模型取得了令人瞩目的成绩:正确类别出现在前五个候选类别中的错误率为 4.8%,正确识别类别的错误率为 20.1%。这一表现优于 AlexNet (16.4%、 38.1%)和 VGG (6.8%、 23.7%),并且是最早超越人类表现(前五个候选类别错误率为 5.1%)的网络之一。不过,该模型提出于 2016 年,远非当前最先进水平。截至本书撰写时,该任务上性能最佳的模型正确识别类别的错误率为 9.0% (见图 10.21)。该模型以及当前所有其他表现最佳的图像分类模型现在都基于 Transformer (见第 12 章)。

11.5.2 DenseNet
11.5.2 DenseNet

Residual blocks receive the output from the previous layer, modify it by passing it through some network layers, and add it back to the original input. An alternative is to concatenate the modified and original signals. This increases the representation size

残差块接收来自上一层的输出,通过若干网络层对其修改,再将其加回原始输入。另一种做法是将修改后的信号与原始信号拼接。这会增加表示规模

图 11.7 ResNet 残差块。 a) ResNet 架构中的标准块包含一个批归一化操作,随后是一个激活函数和一个 3 ×3 卷积层。然后,重复该序列。 b
图 11.7 ResNet 残差块。 a) ResNet 架构中的标准块包含一个批归一化操作,随后是一个激活函数和一个 3 ×3 卷积层。然后,重复该序列。 b) 瓶颈式 ResNet 残差块仍然在 3 × 3 区域内整合信息,但使用的参数更少。它包含三次卷积。第一次 1 × 1 卷积减少通道数。第二次 3 × 3 卷积应用于更小的表示。最后的 1 × 1 卷积再次增加通道数,以便将其加回输入。Figure 11.7 ResNet blocks. a) A standard block in the ResNet architecture contains a batch normalization operation, followed by an activation function, and a 3 ×3 convolutional layer. Then, this sequence is repeated. b). A bottleneck ResNet block still integrates information over a 3 × 3 region but uses fewer parameters. It contains three convolutions. The first 1 × 1 convolution reduces the number of channels. The second 3 × 3 convolution is applied to the smaller representation. A final 1 × 1 convolution increases the number of channels again so that it can be added back to the input.
图 11.8 ResNet-200 模型。应用一个步幅为 2 的标准 7 × 7 卷积层,随后是一个 MaxPool 操作。之后是一系列瓶颈式残差块(括号中的数
图 11.8 ResNet-200 模型。应用一个步幅为 2 的标准 7 × 7 卷积层,随后是一个 MaxPool 操作。之后是一系列瓶颈式残差块(括号中的数字是第一次 1 × 1 卷积后的通道数),并伴随周期性的下采样以及通道数的相应增加。网络最后对所有空间位置进行平均池化,并通过一个全连接层映射到 Softmax 前的激活值。Figure 11.8 ResNet-200 model. A standard 7 × 7 convolutional layer with stride two is applied, followed by a MaxPool operation. A series of bottleneck residual blocks follow (number in brackets is channels after first 1 × 1 convolution), with periodic downsampling and accompanying increases in the number of channels. The network concludes with average pooling across all spatial positions and a fully connected layer that maps to pre-softmax activations.

(in terms of channels for a convolutional network), but an optional subsequent linear transformation can map back to the original size (a 1 × 1 convolution for a convolutional network). This allows the model to add the representations together, take a weighted sum, or combine them in a more complex way.

The DenseNet architecture uses concatenation so that the input to a layer comprises the concatenated outputs from all previous layers (figure 11.9). These are processed to create a new representation that is itself concatenated with the previous representation and passed to the next layer. This concatenation means there is a direct contribution from earlier layers to the output, so the loss surface behaves reasonably.

(就卷积网络的通道数而言),但可选的后续线性变换可以映射回原始大小(对于卷积网络,为一次 1 × 1 卷积)。这使得模型能够将表示相加、取加权和,或以更复杂的方式组合它们。

DenseNet 架构使用拼接,使得某一层的输入由来自所有先前层的拼接输出组成(图 11.9)。这些输出经过处理以生成一个新的表示,该表示本身与先前的表示拼接,并传递给下一层。这种拼接意味着较早层对输出有直接贡献,因此损失面表现合理。

图 11.9 DenseNet。该架构使用残差连接,将较早层的输出拼接至后续层。这里,三通道输入图像被处理以形成 32 通道表示。输入图像被拼接至该表示,总共得
图 11.9 DenseNet。该架构使用残差连接,将较早层的输出拼接至后续层。这里,三通道输入图像被处理以形成 32 通道表示。输入图像被拼接至该表示,总共得到 35 个通道。对该组合表示进行处理以生成另一个 32 通道表示,并将这两个较早表示拼接至该表示,总共得到 67 个通道,依此类推。Figure 11.9 DenseNet. This architecture uses residual connections to concatenate the outputs of earlier layers to later ones. Here, the three-channel input image is processed to form a 32-channel representation. The input image is concatenated to this to give a total of 35 channels. This combined representation is processed to create another 32-channel representation, and both earlier representations are concatenated to this to create a total of 67 channels and so on.

In practice, this can only be sustained for a few layers because the number of channels (and hence the number of parameters required to process them) becomes increasingly large.

This problem can be alleviated by applying a 1 × 1 convolution to reduce the number of channels before the next 3 × 3 convolution is applied.

In a convolutional network, the input is periodically downsampled. Concatenation across the downsampling makes no sense since the representations have different spatial sizes. Consequently, the chain of concatenation is broken at this point, and a smaller representation starts a new chain. In addition, another bottleneck 1 × 1 convolution can be applied when the downsampling occurs to control the representation size further.

实际中,这只能维持少数几层,因为通道数(以及因此处理这些通道所需的参数数量)会越来越大。在应用下一次 3 × 3 卷积之前,可以通过应用 1 × 1 卷积来减少通道数,从而缓解这一问题。在卷积网络中,输入会被周期性地下采样。由于表示具有不同的空间尺寸,跨越下采样进行拼接没有意义。因此,拼接链在此处断开,较小的表示开始一条新链。此外,当下采样发生时,还可以应用另一个瓶颈 1 × 1 卷积,以进一步控制表示尺寸。

This network performs competitively with ResNet models on image classification (see figure 10.21); indeed, it can perform better for a comparable parameter count. This is presumably because it can reuse processing from earlier layers more flexibly.

该网络在图像分类上与 ResNet 模型表现相当(见图 10.21);事实上,在参数数量相当的情况下,它甚至可能表现更好。这大概是因为它能够更灵活地复用早期层的处理。

11.5.3 U-Net 与沙漏网络
11.5.3 U-Nets and hourglass networks

Section 10.5.3 described a semantic segmentation network that had an encoder-decoder or hourglass structure. The encoder repeatedly downsamples the image until the receptive fields are large and information is integrated from across the image. Then the decoder

upsamples it back to the size of the original image. The final output is a probability over possible object classes at each pixel.

One drawback of this architecture is that the low-resolution representation in the middle of the network must “remember” the high-resolution details to make the final result accurate. This is unnecessary if residual connections transfer the representations from the encoder to their partner in the decoder.

10.5.3 节描述了一种具有编码器 - 解码器或沙漏结构的语义分割网络。编码器反复对图像进行下采样,直到感受野足够大,并且能够整合来自整幅图像的信息。然后解码器

将其上采样回原始图像的尺寸。最终输出是每个像素上各可能目标类别的概率。该架构的一个缺点是,网络中间的低分辨率表示必须“记住”高分辨率细节,才能使最终结果准确。如果残差连接将编码器的表示传递到解码器中的对应部分,那么这就没有必要了。

The U-Net (figure 11.10) is an encoder-decoder architecture where the earlier representations are concatenated to the later ones. The original implementation used “valid” convolutions, so the spatial size decreases by two pixels each time a 3 × 3 convolutional layer is applied. This means that the upsampled version is smaller than its counterpart in the encoder, which must be cropped before concatenation. Subsequent implementations have used zero-padding, where this cropping is unnecessary. Note that the U-Net is completely convolutional, so after training, it can be run on an image of any size.

U-Net (图 11.10)是一种编码器 - 解码器架构,其中较早的表示被拼接到较晚的表示上。原始实现使用了“valid”卷积,因此每应用一个 3 × 3 卷积层,空间尺寸就会减少两个像素。这意味着上采样后的版本小于编码器中的对应表示,必须在拼接前进行裁剪。后续实现使用了零填充,因此无需这种裁剪。注意, U-Net 是完全卷积的,因此训练后,它可以在任意尺寸的图像上运行。

The U-Net was intended for segmenting medical images (figure 11.11) but has found many other uses in computer graphics and vision. Hourglass networks are similar but apply further convolutional layers in the skip connections and add the result back to the decoder rather than concatenating it. A series of these models form a stacked hourglass network that alternates between considering the image at local and global levels. Such networks are used for pose estimation (figure 11.12). The system is trained to predict one “heatmap” for each joint, and the estimated position is the maximum of each heatmap.

U-Net 最初用于医学图像分割(图 11.11),但在计算机图形学与视觉中也有许多其他用途。沙漏网络与之类似,但它在跳跃连接中应用更多卷积层,并将结果加回解码器,而不是将其拼接。一系列这样的模型构成一个堆叠沙漏网络,它在考虑图像的局部和全局层面之间交替。这类网络用于姿态估计(图 11.12)。系统被训练为对每个关节预测一张“热图”,估计位置为每张热图的最大值。

图 11.10 U-Net 用于分割海拉细胞。 U-Net 具有编码器 - 解码器结构,其中表示被下采样(橙色块),然后再重新上采样(蓝色块)。编码器使用常规卷
图 11.10 U-Net 用于分割海拉细胞。 U-Net 具有编码器 - 解码器结构,其中表示被下采样(橙色块),然后再重新上采样(蓝色块)。编码器使用常规卷积,解码器使用转置卷积。残差连接将编码器中每个尺度的最后一个表示附加到解码器中相同尺度的第一个表示上(橙色箭头)。原始 U-Net 使用了“valid”卷积,因此即使没有下采样,尺寸也会随着每一层略微减小。因此,来自编码器的表示在附加到解码器之前会被裁剪(虚线方块)。改编自 Ronneberger 等(2015)。Figure 11.10 U-Net for segmenting HeLa cells. The U-Net has an encoder-decoder structure, in which the representation is downsampled (orange blocks) and then re-upsampled (blue blocks). The encoder uses regular convolutions, and the decoder uses transposed convolutions. Residual connections append the last representation at each scale in the encoder to the first representation at the same scale in the decoder (orange arrows). The original U-Net used “valid” convolutions, so the size decreased slightly with each layer, even without downsampling. Hence, the representations from the encoder were cropped (dashed squares) before appending to the decoder. Adapted from Ronneberger et al. (2015).
图 11.11 使用 U-Net 进行三维分割。 a) 通过扫描电子显微镜获取的小鼠皮层三维体积中的三个切片。 b) 使用单个 U-Net 将体素分类为位于神经
图 11.11 使用 U-Net 进行三维分割。 a) 通过扫描电子显微镜获取的小鼠皮层三维体积中的三个切片。 b) 使用单个 U-Net 将体素分类为位于神经突内部或外部。连通区域以不同颜色标识。 c) 为了获得更好的结果,训练了一个由五个 U-Net 组成的集成模型,并且只有当五个网络全部一致时,体素才被分类为属于该细胞。改编自 Falk 等人(2019)。Figure 11.11 Segmentation using U-Net in 3D. a) Three slices through a 3D volume of mouse cortex taken by scanning electron microscope. b) A single UNet is used to classify voxels as being inside or outside neurites. regions are identified with different colors. c) For a better result, an ensemble of five U-Nets is trained, and a voxel is only classified as belonging to the cell if all five networks agree. Adapted from Falk et al. (2019).
11.6 为什么具有残差连接的网络表现如此出色?
11.6 Why do nets with residual connections perform so well?

Residual networks allow much deeper networks to be trained; it’s possible to extend the ResNet architecture to 1000 layers and still train effectively. The improvement in image classification performance was initially attributed to the additional network depth, but two pieces of evidence contradict this viewpoint.

First, shallower, wider residual networks sometimes outperform deeper, narrower ones with a comparable parameter count. In other words, better performance can sometimes be achieved with a network with fewer layers but more channels per layer. Second, there is evidence that the gradients during training do not propagate effectively through very long paths in the unraveled network (figure 11.4b). In effect, a very deep network may act more like a combination of shallower networks.

The current view is that residual connections add some value of their own, as well as allowing deeper networks to be trained. This perspective is supported by the fact that the loss surfaces of residual networks around a minimum tend to be smoother and more predictable than those for the same network when the skip connections are removed (figure 11.13). This may make it easier to learn a good solution that generalizes well.

残差网络使训练更深的网络成为可能;将 ResNet 架构扩展到 1000 层仍然可以有效训练。图像分类性能的提升最初被归因于额外的网络深度,但两项证据与这一观点相矛盾。

首先,较浅、较宽的残差网络有时能够胜过深度更深、宽度更窄但参数数量相当的网络。换句话说,有时可以通过层数更少但每层通道数更多的网络获得更好的性能。其次,有证据表明,在训练过程中,梯度无法在展开后的网络中非常长的路径上有效传播(图 11.4b)。实际上,一个非常深的网络可能更像是一组较浅网络的组合。

目前普遍认为,残差连接本身也能带来一定价值,同时使更深的网络得以训练。这一观点得到如下事实的支持:残差网络在极小值附近的损失曲面往往比移除跳跃连接后的同一网络更平滑、更可预测(图 11.13)。这可能使模型更容易学到能够良好泛化的优质解。

11.7 小结
11.7 Summary

Increasing network depth indefinitely causes both training and test performance for image classification to decrease. This may be because the gradient of the loss with respect to

无限增加网络深度会导致图像分类的训练和测试性能下降。这可能是由于损失相对于

图 11.12 用于姿态估计的堆叠沙漏网络。 a) 网络输入是包含一个人的图像,输出是一组热图,每个关节对应一张热图。这被表述为一个回归问题,其目标是热图图像,
图 11.12 用于姿态估计的堆叠沙漏网络。 a) 网络输入是包含一个人的图像,输出是一组热图,每个关节对应一张热图。这被表述为一个回归问题,其目标是热图图像,其中在真实关节位置处有小的高亮区域。估计热图的峰值用于确定每个最终关节位置。 b) 该架构由初始的卷积层和残差层组成,后面跟着一系列沙漏块。 c) 每个沙漏块都由一个类似于 U-Net 的编码器 - 解码器网络组成,不同之处在于卷积采用零填充,残差连接中执行一些进一步处理,并且这些连接将该处理后的表示相加,而不是拼接。每个蓝色长方体本身就是一个瓶颈残差块(图 11.7b)。改编自 Newell 等(2016)。Figure 11.12 Stacked hourglass networks for pose estimation. a) The network input is an image containing a person, and the output is a set of heatmaps, with one heatmap for each joint. This is formulated as a regression problem where the targets are heatmap images with small, highlighted regions at the ground-truth joint positions. The peak of the estimated heatmap is used to establish each final joint position. b) The architecture consists of initial convolutional and residual layers followed by a series of hourglass blocks. c) Each hourglass block consists of an encoder-decoder network similar to the U-Net except that the convolutions use zero-padding, some further processing is done in the residual links, and these links add this processed representation rather than concatenate it. cuboid is itself a bottleneck residual block (figure 11.7b). Adapted from Newell et al. (2016). Each blue

parameters early in the network changes quickly and unpredictably relative to the update step size. Residual connections add the processed representation back to their own input. Now each layer contributes directly to the output as well as indirectly, so propagating gradients through many layers is not mandatory, and the loss surface is smoother.

Residual networks don’t suffer from vanishing gradients but introduce an exponential increase in the variance of the activations during forward propagation and corresponding problems with exploding gradients. This is usually handled by adding batch normalization, which compensates for the empirical mean and variance of the batch and then shifts and rescales using learned parameters. If these parameters are initialized judiciously, very deep networks can be trained. There is evidence that both residual links and batch normalization make the loss surface smoother, which permits larger learning rates. Moreover, the variability in the batch statistics adds a source of regularization.

网络早期的参数相对于更新步长变化迅速且不可预测。残差连接将处理后的表示加回其自身输入。现在每一层既直接又间接地对输出作出贡献,因此梯度不必非得通过许多层传播,损失曲面也更平滑。

残差网络不会受到梯度消失的影响,但会在前向传播过程中引入激活方差的指数级增长,以及相应的梯度爆炸问题。这通常通过添加批归一化来处理,批归一化会补偿该批次的经验均值和方差,然后使用学习到的参数进行平移和缩放。如果这些参数初始化得当,就可以训练非常深的网络。有证据表明,残差连接和批归一化都能使损失曲面更平滑,从而允许更大的学习率。此外,批次统计量的变异性也提供了一种正则化来源。

图 11.13 可视化神经网络损失曲面。每张图展示的是在 CIFAR-10 数据集图像分类任务中,围绕 SGD 找到的最小值,在参数空间两个随机方向上的损失曲面
图 11.13 可视化神经网络损失曲面。每张图展示的是在 CIFAR-10 数据集图像分类任务中,围绕 SGD 找到的最小值,在参数空间两个随机方向上的损失曲面。这些方向经过归一化,以便并排比较。 a) 56 层残差网络。 b) 同一网络在不使用跳跃连接时的结果。使用跳跃连接时,曲面更平滑。这有助于学习,并使最终网络性能对参数中的微小误差更加鲁棒,因此可能具有更好的泛化能力。改编自 Li 等人(2018b)。Figure 11.13 Visualizing neural network loss surfaces. Each plot shows the loss surface in two random directions in parameter space around the minimum found by SGD for an image classification task on the CIFAR-10 dataset. These directions are normalized to facilitate side-by-side comparison. a) Residual net with 56 layers. b) Results from the same network without skip connections. The surface is smoother with the skip connections. This facilitates learning and makes the final network performance more robust to minor errors in the parameters, so it will likely generalize better. Adapted from Li et al. (2018b).

Residual blocks have been incorporated into convolutional networks.

They allow deeper networks to be trained with commensurate increases in image classification performance.

Variations of residual networks include the DenseNet architecture, which concatenates outputs of all prior layers to feed into the current layer, and U-Nets, which incorporate residual connections into encoder-decoder models.

残差块已被纳入卷积网络。它们使得更深的网络能够被训练,并带来图像分类性能的相应提升。残差网络的变体包括 DenseNet 架构,该架构将所有先前层的输出拼接起来,以馈入当前层,以及将残差连接纳入编码器 - 解码器模型的 U-Net 架构。

注释
Notes

Residual connections:

Why residual connections help:

Related architectures:

Residual networks as ensembles:

Regularization for residual networks:

Batch normalization:

公式

Variations of batch normalization:

图 11.14 归一化方案。批归一化分别修改每个通道,但基于跨批次和空间位置收集的统计量,以相同方式调整每个批次成员。幽灵批归一化仅从部分批次计算这些统计量,以
图 11.14 归一化方案。批归一化分别修改每个通道,但基于跨批次和空间位置收集的统计量,以相同方式调整每个批次成员。幽灵批归一化仅从部分批次计算这些统计量,以使其更具变异性。层归一化分别计算每个批次成员的统计量,基于跨通道和空间位置收集的统计量。它为每个通道保留单独学习到的缩放因子。组归一化在每个通道组内进行归一化,并为每个通道保留单独的缩放和偏移参数。实例归一化分别对每个通道进行归一化,仅跨空间位置计算统计量。改编自 Wu & He (2018)。位置本身。 Salimans 和 Kingma (2016)研究了归一化网络权重而非激活值,但这种方法在实证上不太成功。 Teye 等人(2018)引入了蒙特卡洛批归一化,它可以为神经网络预测中的不确定性提供有意义的估计。关于不同归一化方案性质的近期比较,可在 Lubana 等人(2021)中找到。Figure 11.14 Normalization schemes. rately but adjusts each batch member in the same way based on statistics gathered across the batch and spatial position. Ghost batch normalization computes these statistics from only part of the batch to make them more variable. LayerNorm computes statistics for each batch member separately, based on statistics gathered across the channels and spatial position. It retains a separate learned scaling factor for each channel. GroupNorm normalizes within each group of channels and also retains a separate scale and offset parameter for each channel. InstanceNorm normalizes within each channel separately, computing the statistics only across spatial position. Adapted from Wu & He (2018). position alone. Salimans & Kingma (2016) investigated normalizing the network weights rather than the activations, but this has been less empirically successful. Teye et al. (2018) introduced Monte Carlo batch normalization, which can provide meaningful estimates of uncertainty in the predictions of neural networks. A recent comparison of the properties of different normalization schemes can be found in Lubana et al. (2021).

Why BatchNorm helps:

Alternatives to batch normalization:

公式
公式
公式

DenseNet and U-Net:

问题
Problems

Figure 11.15 Computational graph for batch normalization (see problem 11.5). Problem 11.4 ∗ Explain why the values in the two branches of the residual blocks in figure 11.6a are uncorrelated. Show that the variance of the sum of uncorrelated variables is the sum of their individual variances. Problem 11.5 ∗ The forward pass for batch normalization given a batch of scalar values{zi}I where E[zi]= algorithm for the backward pass. Work backward through the computational graph computing the derivatives to generate a set of operations that computes ∂z′ batch. Write Python code to implement the backward pass. Problem 11.6 Consider a fully connected neural network with one input, one output, and ten hidden layers, each of which contains twenty hidden units. How many parameters does this network have? How many parameters will it have if we place a batch normalization operation between each linear transformation and ReLU? Problem 11.7 ∗ Consider applying an L2 regularization penalty to the weights in the convolutional layers in figure 11.7a, but not to the scaling parameters of the subsequent BatchNorm layers. What do you expect will happen as training proceeds? Problem 11.8 Consider a convolutional residual block that contains a batch normalization operation, followed by a ReLU activation function, and then a 3 × 3 convolutional layer. If the input and output both have 512 channels, how many parameters are needed to define this block? Now consider a bottleneck residual block that contains three batch normalization/ReLU/convolution sequences. The first uses a 1 × 1 convolution to reduce the number of channels from 512 to 128. The second uses a 3 × 3 convolution with the same number of input and output channels. The third uses a 1 × 1 convolution to increase the number of channels from 128 to 512 (see figure 11.7b). How many parameters are needed to define this block? Problem 11.9 The U-Net is completely convolutional and can be run with any sized image after training. Why do we not train with a collection of arbitrarily-sized images? i/∂zi for every element in the

图 11.15 批归一化的计算图(见问题 11.5)。问题 11. 4 ∗ 解释为什么图 11.6a 中残差块的两个分支中的数值是不相关的。证明不相关变量之和的方差等于它们各自方差之和。问题 11. 5 ∗ 给定一批标量值 {zi}I i=1,批归一化的前向传播包含以下操作(图 11.15):传播,计算导数,生成一组操作,为批次中的每个元素计算 ∂z′ 向传播。问题 11.6 考虑一个具有一个输入、一个输出和十个隐藏层的全连接神经网络,每个隐藏层包含二十个隐藏单元。该网络有多少个参数?如果我们在每次线性变换和 ReLU 之间放置一个批归一化操作,它将有多少个参数? 问题 11. 7 ∗ 考虑对图 11.7a 中卷积层的权重施加 L2 正则化惩罚,但不对随后的批归一化层的缩放参数施加。随着训练进行,你预计会发生什么? 问题 11.8 考虑一个卷积残差块,它包含一个批归一化操作,随后是一个 ReLU 激活函数,然后是一个 3 × 3 卷积层。如果输入和输出都有 512 个通道,定义该块需要多少个参数?现在考虑一个瓶颈残差块,它包含三个批归一化 /ReLU/ 卷积序列。第一个使用 1 × 1 卷积将通道数从 512 减少到 128。第二个使用 3 × 3 卷积,输入和输出通道数相同。第三个使用 1 × 1 卷积将通道数从 128 增加到 512 (见图 11.7b)。定义该块需要多少个参数? 问题 11.9 U-Net 完全由卷积构成,训练后可以使用任意尺寸的图像运行。我们为什么不使用任意尺寸图像的集合进行训练?