-
Notifications
You must be signed in to change notification settings - Fork 4.3k
BatchNormalization
BatchNormalization implements a technique described in paper
Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift (Sergey Ioffe, Christian Szegedy).
In short, it normalizes layer outputs for every minibatch for each output (feature) independently and applies affine transformation to preserve representation of the layer. That is, for layer input:
m = mean(input)
var = variance(input)
input_norm = (input - mean)/sqrt(var)
output = gamma * input_norm + beta
where gamma and beta are trainable parameters (represented as LearnableParameter).
BatchNormalization has the following syntax:
BatchNormalization(input, scale, bias, runMean, runInvStdDev, spatial,
normalizationTimeConstant = 0, blendTimeConstant = 0,
epsilon = 0.00001,
useCntkEngine = true, imageLayout='cudnn', tag='')
Where:
-
inputis the input of the batch normalization node -
scaleis a LearnableParameter that stores scale vector (gammaterm in the equation above). -
biasis a LearnableParameter that stores bias vector (betaterm).scaleandbiasmust have the same dimensions which must be equal to theinputdimensions in case ofspatial = falseor number of output convolution feature maps in case ofspatial = true. -
runMeanis the running mean which is used during evaluation phase and might be used during training as well. It is represented as a LearnableParameter with the same dimensions asscaleandbias. -
runInvStdDevis the running inverse square root of variance (soInvStdDev = 1 / sqrt(var + epsilon)). It is represented as a LearnableParameter with the same dimensions asscaleandbias. -
spatialis a flag that specifies whether to compute mean/var for each feature in a minibatch independently or, in case of convolutional layers, per feature map. -
normalizationTimeConstantis the time constant which is used to compute running average of mean and variance. Value0(default) means there will be no exponential smoothing and running mean/variance will always have values computed for the last seen minibatch. Value1#INF(infinity) means running values are "frozen" (i.e. will not be updated). Depending on the dataset and network configuration, different values can be used. For example, for MNIST dataset you can set it to 1024 and for speech datasets to number of frames corresponding to 24 hour period. The constant can also be set globally (in .cntk config file) usingbatchNormalizationTimeConstantparameter, for example:batchNormalizationTimeConstant=0:1024 -
blendTimeConstantis the time constant which allows to specify how much of running mean/var should be "blended" into mean/var of the current minibatch. Value0(default) means no blending will happen and only the current minibatch statistics will be used. Value1#INF(infinity) means only running mean/var will be used (this is used, for example, in evaluation phase). For example, you can start with 0, then set it to half of the size of minibatch and then set it to infinity after several epochs. This can be done using .cntk (config) filebatchNormalizationBlendTimeConstantoption:batchNormalizationBlendTimeConstant=0:32*10:1#INF -
epsilonis a conditioner constant used in computingInvStdDev -
useCntkEngineis a boolean flag that specifies which batch normalization implementation to use: CNTK or cuDNN-based. -
imageLayoutis the image layout. Onlycudnnis supported.
For more information about time constants and exponential smoothing: https://en.wikipedia.org/wiki/Exponential_smoothing#Time_Constant
Note that for evaluation stage CNTK will set time constants automatically, users do not have to change anything to switch between the stages.