liveBook · Manning

Batch normalization

As explained in Deep Learning with Python, Third Edition

A normalization technique used in neural networks that stabilizes activations during training, commonly implemented as a normalization layer.

Batch normalization is a layer that normalizes intermediate activations, not only the input data. It centers values around zero and scales them toward unit variance, helping when successive transformations change activation statistics during training. section 9.3

Training versus inference

During training, BatchNormalization uses the mean and variance of the current batch. During inference, it uses exponential moving averages collected from batches seen during training, avoiding dependence on a large representative batch at prediction time. section 9.3

Use these practical placement rules when building a convolutional network:

  • Place a batch-normalization layer after a convolution; disabling the convolution bias is shown as a compatible pattern. section 9.3
  • Choose the activation ordering deliberately: normalization can follow a convolution with an existing activation, or precede a separate ReLU activation. section 9.3
  • Treat it as an architecture pattern rather than a guaranteed explanation of improved performance; its precise mechanism remains uncertain. section 9.3

In practice, the main observed benefit appears to be smoother gradient propagation, much like residual connections, which can make deeper networks easier to train. It is commonly combined with residual connections in deep ConvNets. section 9.3 section 20.1.6

Xception-like image classifier

A mini Xception-like model places BatchNormalization layers before activations inside repeated convolutional blocks, alongside separable convolutions, max pooling, and residual connections. The complete architecture reaches 90.8% test accuracy on dogs-versus-cats, compared with 83.9% for the preceding model; the improvement belongs to the combined architecture choices. section 9.5

x = layers.Conv2D(32, 3, use_bias=False)(x)                          #1
x = layers.BatchNormalization()(x)
x = layers.Activation("relu")(x)                                     #2

Compare a convolution, batch normalization, and separately applied ReLU in a common pre-activation arrangement. section 9.3

How Deep Learning with Python, Third Edition covers it

How deep it goes
Defines batchwise training and moving-average inference behavior, but stops short of a certain causal explanation for its benefits.
Examples
Uses Keras layer snippets and a mini Xception-like dogs-versus-cats classifier with repeated normalized convolutional blocks.
What it assumes
Assumes familiarity with neural-network transformations and training, while reviewing input normalization and extending it to intermediate activations.
What you can do after
Apply it via Keras by inserting BatchNormalization into convolutional blocks and selecting an activation ordering.
How it connects
Connects intermediate activation normalization with convolutional networks, residual connections, gradient propagation, and separable convolutions.

Also explained in

Compare how 9 books explain batch normalization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with Python, Third Edition. The section links point to the parts of the book it draws on.