简介:
本文学习来自微软的msra初始化,来自论文《Delving Deep into Rectifiers:
Surpassing Human-Level Performance on ImageNet Classification》
目前在深度神经网络的训练过程中,初始化过程影响着网络最终的训练结果。网络越深收敛更加困难,为了处理这个问题,VGG团队先训练一个8层的网络,再用训练好的模型去初始化更深的网络。但这种方法耗时,也有可能使网络陷入局部最优。GoogLeNet则是使用辅助的分类层加速收敛。
Xavier初始化的使用是假设激活函数是线性的,但这种假设则是对Relu和Prelu无效的。
MSRA初始化:
为了使经过每一层后的输出和输入一致,经过卷积层后,根据卷积公式,可以得到卷积前后的分布一致:
进一步的当权重均值为0,由方差计算公式得:
推导:
由于x不是均值为0,所以得:
对于ReLU激活函数,负半轴部分为0,因此经过relu之后方差为:
带入上式得
经过所有层之后的方差分布为:
为了保持输入输出分布一致,则使:
最后结果初始化为均值为0,方差
实验对比
caffe中实现
跟xavier一样,n也有三种计算方法:
enum VarianceNorm {
FAN_IN = 0;
FAN_OUT = 1;
AVERAGE = 2;
}
optional VarianceNorm variance_norm = 8 [default = FAN_IN];
template <typename Dtype>
class MSRAFiller : public Filler<Dtype> {
public:
explicit MSRAFiller(const FillerParameter& param)
: Filler<Dtype>(param) {}
virtual void Fill(Blob<Dtype>* blob) {
CHECK(blob->count());
int fan_in = blob->count() / blob->num();
int fan_out = blob->count() / blob->channels();
Dtype n = fan_out; // default to fan_in
if (this->filler_param_.variance_norm() ==
FillerParameter_VarianceNorm_AVERAGE) {
n = (fan_in + fan_out) / Dtype(2);
} else if (this->filler_param_.variance_norm() ==
FillerParameter_VarianceNorm_FAN_IN) {
n = fan_in;
}
Dtype alpha = this->filler_param_.alpha();
Dtype std = sqrt(Dtype(2) / n / (1 + alpha * alpha));
caffe_rng_gaussian<Dtype>(blob->count(), Dtype(0), std,
blob->mutable_cpu_data());
CHECK_EQ(this->filler_param_.sparse(), -1)
<< "Sparsity not supported by this Filler.";
}
};