Search code examples
kerasmeanstandard-deviationimage-preprocessing

Keras Feature Wise Center at Training and Prediction Time


I have had ImageDataGenerator implemented with featurewise_center=True, featurewise_std_normalization=True. I fit the generator to my training set (it learns some statistics) and train my model. All is well.

After training is done and python is closed, how do I do the same preprocessing on my test set using the generator? I want to carry over the statistics learned from fit to be used whenever I want to test or further train my model (where the original training set might not be available anymore).

Thanks in advance


Solution

  • I have solved this problem. To those who are still coming across it. Follow below steps.

    1. Create ImageDataGenerator with preprocessing that you want.
    2. Randomly sample 0.1% out of your training data (i.e sample) . Load it in memory Fit ImageDataGenerator
    3. Get the get Mean and STD from ImageDataGenerator and put it in a list
    4. Iterate over the dataset for as many times as you like and save the Mean and STD on each iteration
    5. Compute the average Mean and STD
    6. List item

    Assign the averaged mean and averaged STD to new ImageDataGenerator.