Kevin Kevin - 7 months ago 340
Python Question

How to perform mean subtraction and normalization with Tensorflow

On it is mentioned that for convolutional neural networks it is preferred to preprocess data using mean subtraction and normalization techniques.

I was just wondering how would it be best approached using Tensorflow.

Mean substraction

X -= np.mean(X)


X /= np.std(X, axis = 0)


You're looking for tf.image.per_image_whitening(image):

Linearly scales image to have zero mean and unit norm.

This op computes (x - mean) / adjusted_stddev, where mean is the average of all values in image, and adjusted_stddev = max(stddev, 1.0/sqrt(image.NumElements())).