28

Speed-up inference with Batch Normalization Folding

 4 years ago
source link: https://towardsdatascience.com/speed-up-inference-with-batch-normalization-folding-8a45a83a89d8?gi=3e0ad04ee894
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Introduction

Batch Normalization is a technique which takes care of normalizing the input of each layer to make the training process faster and more stable. In practice, it is an extra layer that we generally add after the computation layer and before the non-linearity.

It consists of 2 steps:

  • Normalize the batch by first subtracting its mean μ, then dividing it by its standard deviation σ.
  • Further scale by a factor γ and shift by a factor β. Those are the parameters of the batch normalization layer, required in case of the network not needing the data to have a mean of 0 and a standard deviation of 1.

naInEzy.png!web

Due to its efficiency for training neural networks, batch normalization is now widely used. But how useful is it at inference time?

Once the training has ended, each batch normalization layer possesses a specific set of γ and β, but also μ and σ, the latter being computed using an exponentially weighted average during training. It means that during inference, the batch normalization acts as a simple linear transformation of what comes out of the previous layer, often a convolution.

As a convolution is also a linear transformation, it also means that both operations can be merged into a single linear transformation!

This would remove some unnecessary parameters but also reduce the number of operations to be performed at inference time.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK