Reshape Images from ImageDataGenerator

Viewed 1561
from tensorflow.keras.preprocessing.image import ImageDataGenerator

With image data generator's flow_from_directory method can we reshape images also.

e.g. we have color images in 10 classes in 10 folders and we are providing path of that directory let's say train:

gen = ImageDataGenerator(rescale=1./255, width_shift_range=0.05, height_shift_range=0.05)

train_imgs= gen .flow_from_directory(
        '/content/data/train',
        target_size=(10,10),
        batch_size=1,
        class_mode='categorical')

Now my model is taking input shape 300. And I want to define training data from this train_imgs that is images of 10X10X3.

Is there any library, method or option available to convert this data generator to matrix in which columns are each image vector?

1 Answers

Generally the best option in these cases is to add a Reshape layer to the start of your model: layers.Reshape((300), input_shape=(10,10,3)). You can also do layers.Reshape((-1), input_shape=(10,10,3)), and it will automatically figure out the correct output length.

Related