How does data normalization work in keras during prediction?

前端 未结 4 1629
日久生厌
日久生厌 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:09

    Yes - this is a really huge downside of Keras.ImageDataGenerator that you couldn't provide the standarization statistics on your own. But - there is an easy method on how to overcome this issue.

    Assuming that you have a function normalize(x) which is normalizing an image batch (remember that generator is not providing a simple image but an array of images - a batch with shape (nr_of_examples_in_batch, image_dims ..) you could make your own generator with normalization by using:

    def gen_with_norm(gen, normalize):
        for x, y in gen:
            yield normalize(x), y
    

    Then you might simply use gen_with_norm(datagen.flow, normalize) instead of datagen.flow.

    Moreover - you might recover the mean and std computed by a fit method by getting it from appropriate fields in datagen (e.g. datagen.mean and datagen.std).

提交回复
热议问题