Resizing images in Keras ImageDataGenerator flow methods

前端 未结 4 1566
攒了一身酷
攒了一身酷 2020-12-16 10:56

The Keras ImageDataGenerator class provides the two flow methods flow(X, y) and flow_from_directory(directory) (https://keras.io/prepr

4条回答
  •  猫巷女王i
    2020-12-16 11:19

    For large training dataset, performing transformations such as resizing on the entire training data is very memory consuming. As Keras did in ImageDataGenerator, it's better to do it batch by batch. As far as I know, there're 2 ways to achieve this other than operating the whole dataset:

    1. You can use Lambda Layer to create a layer and then feed original training data to it. The output is the resized you need.

    Here is the sample code if you use TensorFlow as the backend of Keras:

    original_dim = (32, 32, 3)
    target_size = (64, 64)
    input = keras.layers.Input(original_dim)
    x = tf.keras.layers.Lambda(lambda image: tf.image.resize(image, target_size))(input)
    
    1. As @Retardust mentioned, maybe you can customize your own ImageDataGenerator as well as the preprocessing_function.

提交回复
热议问题