How does data normalization work in keras during prediction?

前端 未结 4 1640
日久生厌
日久生厌 2020-12-23 10:58

I see that the imageDataGenerator allows me to specify different styles of data normalization, e.g. featurewise_center, samplewise_center, etc.

I see from the exampl

4条回答
  •  清歌不尽
    2020-12-23 11:20

    I also had the same issue and I solved it using the same functionality, that the ImageDataGenerator used:

    # Load Cifar-10 dataset
    (trainX, trainY), (testX, testY) = cifar10.load_data()
    generator = ImageDataGenerator(featurewise_center=True, 
                                   featurewise_std_normalization=True)
    
    # Calculate statistics on train dataset
    generator.fit(trainX)
    # Apply featurewise_center to test-data with statistics from train data
    testX -= generator.mean
    # Apply featurewise_std_normalization to test-data with statistics from train data
    testX /= (generator.std + K.epsilon())
    
    # Do your regular fitting
    model.fit_generator(..., validation_data=(testX, testY), ...)
    

    Note that this is only possible if you have a reasonable small dataset, like CIFAR-10. Otherwise the solution proposed by Marcin sounds good more reasonable.

提交回复
热议问题