If I understand correctly the ImageDataGenerator class is a generator and returns batches of images when called, but what I don't seem to understand is:

  • featurewise_center
  • featurewise_std_normalization

The documentation says:

  • featurewise_center: Boolean. Set input mean to 0 over the dataset, feature-wise.
  • featurewise_std_normalization: Boolean. Divide inputs by std of the dataset, feature-wise.

How can you set mean to 0 over entire dataset when you have only a batch of images at any given time? and same for normalization.


1 Answer 1


You are right, normally you would not be able to tell these from a single batch of loaded samples.

This is why before you use ImageDataGenerator for generating batches, you need to fit it to your data, to calculate the statistics necessary for normalization.

Here is an example from Keras documentation

(x_train, y_train), (x_test, y_test) = cifar10.load_data()
y_train = np_utils.to_categorical(y_train, num_classes)
y_test = np_utils.to_categorical(y_test, num_classes)

datagen = ImageDataGenerator(

# compute quantities required for featurewise normalization
# (std, mean, and principal components if ZCA whitening is applied)

# fits the model on batches with real-time data augmentation:
model.fit_generator(datagen.flow(x_train, y_train, batch_size=32),
                    steps_per_epoch=len(x_train) / 32, epochs=epochs)

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.