论文笔记:Batch Normalization(论文刨析)

前言

论文地址:Batch Normalization

一、概述

在训练传统的神经网络模型时,因为每一层的参数不一样,所以导致每一层输入数据的分布不一样。这就需要我们谨慎的使用非常小的学习率来更新参数,所以模型训练要耗费大量时间。

作者为了解决这一问题,提出了Batch Normalization,简言之就是对每一层的输入都进行归一化(实际操作起来还需要一些别的处理),使用了Batch Normalization之后,我们就可以使用较大的学习率了,并且不用太考虑参数初始化的问题(参数初始化问题真的是令人头疼!),作者在实验过程中发现,使用了Batch Normalization的网络,可以大大降低训练时间(达到同一效果,使用了BN的模型只需训练原来模型的所消耗时间的 1 14 \frac{1}{14} 141)。

二、Batch Normalization

首先原论文简单介绍了一下传统训练神经网络的方法,即随机梯度下降法(SGD),以及其变种,如Adam、Adagrad、Momentum等。并且指出了用SGD训练神经网络时,学习率和初始化参数会对优化过程影响非常大,导致我们不得不使学习率很小以及非常小心的初始化参数。

While stochastic gradient is simple and effective, it requires careful tuning of the model hyper-parameters, specifically the learning rate used in optimization, as well as the initial values for the model parameters

对于每一层的输入来说,如果其分布总是变化,那么网络就必须得一直去适应这种变化。如果每层的输入的分布基本保持不变,那么每一层的参数就不必为了去适应这些变化而调整自己。

As such it is advantageous for the distribution of x to remain fixed over time. Then, Θ does not have to readjust to compensate for the change in the distribution of x.

举个例子,如果某个神经网络的某一层使用了sigmoid作为激活函数,该函数的分布如下
在这里插入图片描述
观察上图,可以发现,当 ∣ x ∣ > 4 |x|>4 x>4时,其导数几乎为0,这也就是常说的梯度消失。这就会导致训练速度非常非常慢。

对于某一层网络的输入,即x来说,其计算公式如下
x = W u + b x = Wu+b x=Wu+b
观察上述公式,易知,x不仅受本层网络参数的W、b的影响,还会受之前所有网络参数的影响(u)。只要前面网络的参数稍有变化,就有可能让 ∣ x ∣ > 4 |x|>4 x>4,造成梯度消失。为了解决这个问题,就有了后来的relu。


作者为了解决这个问题,提出了Batch Normalization,该方法的主要思想就是固定某层输入的均值和方差。Batch Normalization减小了梯度对于参数大小的依赖,可以允许我们使用更大的学习率,让训练速度变得更快,而且如果使用了Batch Normalization,就可以解决使用sigmoid作为激活函数时出现的梯度消失问题。

Batch Normalization also has a beneficial effect on the gradient flow through the network, by reducing the dependence of gradients on the scale of the parameters or of their initial values. This allows us to use much higher learning rates without the risk of divergence. Furthermore, batch normalization regularizes the model and reduces the need for Dropout (Srivastava et al., 2014). Finally, Batch Normalization makes it possible to use saturating nonlinearities by preventing the network from getting stuck in the saturated modes.


Batch Normoaliztion 为了固定每层输入的分布,使用了最简单的类似于标准化的方法。如果我们仅对每一层的输入使用归一化方法(即将数据转化为均值为0,方差为1),这会大大限制网络的表达能力,举个简单的例子,如果网络使用的激活函数为sigmoid,那么如果将其输入转化都转化为均值为0,方差为1的化,那这个sigmoid函数就非常近似于线性变换函数了(可以仔细看看上述的sigmoid函数图)。

为了解决上述问题,作者进行了一个简单的变换,如下。
在这里插入图片描述
上式中,其中 x ^ \hat{x} x^为归一化后的结果,其中 γ 、 β \gamma、\beta γβ是待学习的参数,当 γ = s t d ( x ) 、 β = E ( x ) 时 \gamma=std(x)、\beta=E(x)时 γ=std(x)β=E(x) y y y就是未进行放缩时的值。

原论文给出的基础的BN算法如下
在这里插入图片描述

作者也给出了使用了BN算法后,反向传播的求导过程。
在这里插入图片描述
使用了Batch Normaliztion的网络,可以使用SGD、Adagrad等优化策略。在训练的过程中,我们会使用小批量数据的均值方差,但是在实际应用的时候,可能就只有一个输入,所以在inference过程使用的均值和方差都是基于训练数据集得来的。

The normalization of activations that depends on the mini-batch allows efficient training, but is neither necessary nor desirable during inference; we want the output to depend only on the input, deterministically. For this, once the network has been trained, we use the normalizatio

因为在inference的过程中,均值和方差都已经被固定,此时的Batch Normaliztion就是一个简单的线性变换。

Since the means and variances are fixed during inference, the normalization is simply a linear transform applied to each activation. It may further be composed with the scaling by γ and shift by β, to yield a single linear transform that replaces BN(x).

最后作者给出了一个复杂一点的BN网络训练的算法,
在这里插入图片描述
假设现在某神经网络的第k-1层的输出为 u u u,第k层的激活函数为 g ( ⋅ ) g(·) g(),第k层的参数为 w 、 b w、b wb。那么第k层可以表示如下形式
a = g ( w u + b ) a = g(wu+b) a=g(wu+b)
那么我们是应该对 u u u进行BN,还是应该对 w u + b wu+b wu+b进行BN呢?作者在原论文中建议我们对 w u + b wu+b wu+b进行Batch Normalization进行BN。道理很简单,如果对 u u u进行BN,如果 w 、 b w、b wb的值太大的化,那么该层的输入还是会非常的大,仍然会造成饱和现像。

BN算法可以很直接的用到MPL网络,实际上BN可以用在卷积神经网络中。假设现在每个输入只有一个feature map,每个feature map的大小为 p × q p\times q p×q,批量大小为m,那么我们可以将m个输入的feature map拉直成 p × q p\times q p×q的向量,然后m个 p × q p\times q p×q的向量进行BN即可。这里需要注意的是,进行BN的一定要是同类型的feature map!

对于传统的MPL网络,如果我们训练时使用的学习率太高,可能会导致梯度消失或者梯度爆炸。使用了BN算法,这个问题就可以解决。

Batch Normalization helps address these issues. By normalizing activations throughout the network, it prevents small changes to the parameters from amplifying into larger and suboptimal changes in activations in gradients; for instance, it prevents the training from getting stuck in the saturated regimes of nonlinearities

通常来说,学习率太大会导致网络的参数膨胀从而导致梯度爆炸,这是因为它放大了梯度的影响。但是如果使用了BN之后,就不会有这种问题。
在这里插入图片描述
在这里插入图片描述

Batch Normalization also makes training more resilient to the parameter scale. Normally, large learning rates may increase the scale of laye r parameters, which then amplify the gradientduring backpropagationand lead to the model explosion. However, with Batch Normalization, backpropagation through a layer is unaffected by the scale of its parameters. Indeed, for a scalar a,

Batch Normalization 也为网络提供了一些泛化作用,因为在训练过程中,使用的均值和方差是来自于所有训练样本。

When training with Batch Normalization, a training example is seen in conjunction with other examples in the mini-batch, and the training network no longer producing deterministic values for a given training example. In our experiments, we found this effect to be advantageous to the generalization of the network. Whereas Dropout (Srivastava et al., 2014) is typically used to reduce overfitting, in a batch-normalizednetwork we found that it can be either removed or reduced in strength

三、实验

下图a,蓝色曲线为使用了BN的网络,虚线为未使用BN的网络,明显可以看出使用BN的网络训练速度要快得多。下图b、c 分别是不使用BN、使用BN的网络最后一层的输出值、均值、方差的波动情况,可以看到不使用BN的网络波动更大,而使用BN的网络变化更加平缓
在这里插入图片描述
以下内容介绍了上述实验的细节

3 fully-connectedhidden layers with 100 activations each. Each hidden layer computesy = g(Wu+b) with sigmoid nonlinearity, and the weights W initialized to small random Gaussian values. The last hidden layer is followed by a fully-connected layer with 10 activations (one per class) and cross-entropy loss. We trained the network for 50000 steps, with 60 examples per mini-batch. We added Batch Normalization to each hidden layer of the network, as in Sec. 3.1. We were interested in the comparison between the baseline and batch-normalized networks, rather than achieving the state of the art performance on MNIST (which the described architecture does not).

作者又在ImageNet分类任务中,使用Inception模型进行测试。测试结果如下
在这里插入图片描述
x5:学习率是原始Inception模型的5倍
x30:学习率是原始Inception模型的30倍
x5-sigmoid:指的是模型使用的sigmoid作为激活

上述结果可以看到如果BN大大提高了训练速度,不过令人疑惑的是X30的训练速度要比X5低,不过准确率却提升了。 而且BN算法让sigmoid激活函数可用,要知道,如果不使用BN,sigmoid函数作为激活函数几乎完全是副作用。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ReWz

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值