38
$\begingroup$

I am not clear the reason that we normalise the image for CNN by (image - mean_image)? Thanks!

$\endgroup$

1 Answer 1

52
$\begingroup$

First note: you really should be also dividing by the standard deviation of each feature (pixel) value as well. Subtracting the mean centers the input to 0, and dividing by the standard deviation makes any scaled feature value the number of standard deviations away from the mean.

To answer your question: Consider how a neural network learns its weights. C(NN)s learn by continually adding gradient error vectors (multiplied by a learning rate) computed from backpropagation to various weight matrices throughout the network as training examples are passed through.

The thing to notice here is the "multiplied by a learning rate".

If we didn't scale our input training vectors, the ranges of our distributions of feature values would likely be different for each feature, and thus the learning rate would cause corrections in each dimension that would differ (proportionally speaking) from one another. We might be over compensating a correction in one weight dimension while undercompensating in another.

This is non-ideal as we might find ourselves in a oscillating (unable to center onto a better maxima in cost(weights) space) state or in a slow moving (traveling too slow to get to a better maxima) state.

It is of course possible to have a per-weight learning rate, but it's yet more hyperparameters to introduce into an already complicated network that we'd also have to optimize to find. Generally learning rates are scalars.

Thus we try to normalize images before using them as input into NN (or any gradient based) algorithm.

$\endgroup$
7
  • 1
    $\begingroup$ what about color images? do i do it for each color channel? wouldn't that mess up the color distribution? $\endgroup$ Jun 28, 2016 at 0:19
  • 2
    $\begingroup$ Believe you're supposed to yes. You can just do something like: (image - image.mean()) / (image.std() + 1e-8) $\endgroup$
    – JohnAllen
    Sep 23, 2016 at 6:07
  • $\begingroup$ Is this really helpful for training? I am training object detector, and using this fitlers, the image(s) are really confusing, its hard to see objects that i am detecting $\endgroup$
    – Darlyn
    Apr 24, 2018 at 19:36
  • $\begingroup$ It’s quite helpful for training in terms of learnability and accuracy - it’s not for you it’s for the model :) You might want to output the non-normalized image when you’re debugging so that it appears normal to your human eyes. $\endgroup$ Apr 24, 2018 at 20:21
  • $\begingroup$ Standardisation is one kind of scaling. We need to scale when the features are of different scales, units, ranges etc. But in image all of the feature columns are nothing but the intensities. Hence, all of them are already scaled in the same range [0-255]. So what's the necessity of re-scaling them? But we can still mean shift the data and which is helpful in this case. I mean, subtracting the average R, G and B values of the whole dataset from each corresponding channel pixel value. I myself trained a classifier and I just subtract the mean only and which worked fine. $\endgroup$
    – hafiz031
    Aug 16, 2020 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.