# Neural Network Input Normalization

As I know it is recommended to normalize the input to a neural network ($\mu=0,\sigma=1$). Assuming I use a CNN that uses RGB-images as input, how do i have to normalize?

• Over all the data of the complete batch (at once)?
• Each image independent of each other?
• For each $x$/$y$ pair (=pixel) over the batch?
• For each color channel or all at once?

Thank you very much

-edit-

Or is it sufficient to use a BatchNormalization-Layer as the first layer in the neural network?

Usually, for RGB images you just subtract half the range and divide by the full range: $$x:=\frac{x-\frac{range}{2}}{range}$$ where $range=255$ in this case since each pixel is a value from 0 to 255. This will not result in having zero mean and unit variance but for most applications it is close enough and works well.
If this is not working for you, the correct way to scale the data to have zero mean and unit variance is to take each channel individually; calculate the mean and variance of all the pixels in all the images in that channel; then scale each channel individually as follows: $$x_R:=\frac{x_R-\mu_R}{\sigma_R} \;\; x_G:=\frac{x_G-\mu_G}{\sigma_G} \;\; x_B:=\frac{x_B-\mu_B}{\sigma_B}$$
Note: If $\sigma$ is too small for one or more of the channels you can cap it at minimum value to avoid numerical stability issues e.g. $\sigma= max(\sigma, 0.0001)$
• Thanks for the great answer:) But why is $range=256$ and not $255$? $255$ seems for me to be the more natural choice, because then the values are distributed in $[0,1]$? – Kevin Meier Oct 9 '17 at 10:09