caffe中实现批量归一化(batch-normalization)需要借助两个层:BatchNorm 和 Scale
BatchNorm实现的是归一化
Scale实现的是平移和缩放
在实现的时候要注意的是由于Scale需要实现平移功能,所以要把bias_term项设为true
另外,实现BatchNorm的时候需要注意一下参数use_global_stats,在训练的时候设为false,在测试的时候设为true
use_global_stats = false 时采用滑动平均计算新的均值和方差
use_global_stats = true 时会强制使用模型中存储的BatchNorm层均值与方差参数
具体训练实现过程为(conv-batchnorm-scale-relu):
layer {
bottom: "data"
top: "conv1_1"
name: "conv1_1"
type: "Convolution"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
}
num_output: 64
pad: 1
kernel_size: 3
}
}
layer {
bottom: "conv1_1"
top: "conv1_1"
name: "bn_conv1_1"
type: "BatchNorm"
param {
lr_mult: 0
decay_m