Batch Normalization 笔记

Abstract

1.提出了dnn训练很复杂,因为layer input 的distribution一直在变化

因此,initialization很重要,同时,也不能用大的学习率,

makes it notoriously hard to train models with saturating nonlinearities 

将其成为ICS internal covariate shift

提出了batch normalization解决这个问题

核心思想: 解决深度学习中,每一层的输入的分布一直在变化的问题,

1.Introduction

介绍sgd迭代,sgd simple and effective,但同时,requires careful tuning of the hyper-parameters

尤其是learning rate 相当关键

同时,

fixed distribution consequences for the layers outside the sub-network, as well

比如,,激活函数

z = g(W u + b)

g(x) = 1 / (1+exp(−x))

当x绝对值大的时候,导数趋近于0,意味着我们总是期望比较小的Wu + b值,

但是,x 被所有层的参数影响,容易进入饱和区域,即梯度比较小的区域,同时,随着网络层数的加深,这种效应被放大了,(我的理解是,因为饱和区域的梯度比较小,所以陷入饱和后不基本上就不变了), 因此,造成了梯度弥散

relu,精细的初始化和小的learning rate可以一定程度改善这个问题

但是,batch normalization 可以ensure the distribution stable , 即更少地落在饱和区域, 加速训练

总结:

1. reduce internal covarite shift accomplished by a normalization step to fixes the mean and viriances

减少ics,使训练输入的distribution保持不变

2. benefit on gradient flow through the network, reducing the dependence of gradients on the scale of the parameters and init

有利于网络中的梯度传播,减少了对梯度对参数尺度和初始化的依赖,同时可以采用更大的learning rate

3. regularizes the model  (起到一定正则化的作用,减少了dropout的需求,原因不明)

4.make it possible to use saturating nonlinearities 即避免网络进入左右的梯度小的饱和区域

2.Towards Reducing ICS

再次介绍了ICS,提出了减少ICS的方法,其中一种是白化(whitening)

By whitening the inputs to each layer,we would take a step towards achieving the fixed distributions of inputs that would remove the ill effects of the internal covariate shift.

However, if these modifications are interspersed with the optimization steps, then the gradient descent step may attempt to update the parameters in a way that requires the normalization to be updated, which reduces the effect of the gradient step.

但是,当这些modification被带入到优化步骤的时候, 可能降低梯度的影响,

比如

x` = x -e(x)

x = u + b

e(x)是期望,如果忽略b对x 的影响,那么

sgd的时候.b = b + ∆b 

x -e(x) = u + b + ∆b - e(u + b + ∆b) = u + b - e(u + b)

即,,b更新了,但是x` 没变,因此loss也没变,,,

This problem can get worse if the normalization not only centers but also scales the activations

如果加入scales 问题会更加严重

原因是在梯度下降的时候没有考虑到normalization的存在

To address this issue, we would like to ensure that, for any parameter values, the network always produces activations with the desired distribution

因此,x = Norm(x, X ) 对于一个norm ,bp的时候既要对x 求导,也要对X 求导,如果用白化, 则计算代价非常大,

3. Normalization via Mini-Batch Statistics

既然白化的代价很大,就要寻求一种更简单的方法

第一,各个维度独立normalize


但是简单的normalization会影响layer所能表示的空间,因此需要做恒等变换, 引入


最开始的e和var都是基于全部train set定的,但是在sgd 中不现实,因此做简化二

第二: 

since we use mini-batches in stochastic gradient training, each mini-batch produces estimates of the mean and variance of each activation.

即把方差和期望都用batch 来计算


bp的时候


通过这种方式,在保持网络拟合能力的同时, 减少了ics

总结:

1.batch normalization的本质: 减少ics, 但是普通的白化这种,会影响网络的表达能力,同时影响梯度下降,但是恒等变换的白化计算量又太大,

因此引入了batch normalization

特点1, 不同维度分别normalization

特点2, 期望和方差都用当前batch 的去计算,并引入了gamma和beta参数,保证了模型的capacity

3.1 训练和inference中的 batch normalization

训练时已经如上文,inference时,由于不一定有mini batch, 因此mean和var就确定为



猜你喜欢

转载自blog.csdn.net/loubiao9212/article/details/88897239
今日推荐