Batch Normalization
原理与总结
Batch Normalization 能够使得数据进行归一处理,可以解决内部协变量偏移,可以缓解梯度饱和问题。
公式:
μ = 1 m ∑ i = 1 m x i \mu = \frac{1}{m}\sum_{i=1}^mx_i μ=m1∑i=1mxi 求出数据的均值
σ 2 = 1 m ∑ i = 1 m ( x i − μ ) 2 \sigma^2 = \frac{1}{m}\sum_{i=1}^m(x_i-\mu)^2 σ2=m1∑i=1m(xi−μ)2 求出数据的方差
x ^ i = x i − μ σ 2 + ϵ \hat{x}_i=\frac{x_i-\mu}{\sqrt{\sigma^2+\epsilon}} x^i=σ2+ϵxi−μ
y i = γ x ^ i + β y_i=\gamma\hat{x}_i+\beta yi=γx^i+β
然后根据该公式,我推导了Batch Normalization的前向以及反向传播的值与梯度
作业实现
batchnorm_forward
这里主要是根据上面的公式进行代码编写 batchnorm的前向传播。这里要注意在train和test的不同。
- train中
- test中固定var和mean 进行计算
- 测试结果:
batchnorm_backward
这里是根据上图中推导的batchnorm的反向传播公式进行代码编写
测试结果:
batchnorm_backward_alt
根据图中的反向传播公式可以直接求出最后的反向传播公式
测试结果:
Fully Connected Nets with Batch Normalization
测试结果:
Batchnorm for deep networks
测试结果:
Batchnorm and initialization
研究网络使用batchnorm之后的效果。
测试结果:
在这里插入图片描
Question
Describe the results of this experiment, and try to give a reason why the experiment gave the results that it did.
Answer:
batchnorm能够加快模型的收敛,这是因为batchnorm将数据进行归一化,使得每一层提取的特征更加规则。