Autoencoder with images in Google Drive

Hi,

I’m looking for a basic tutorial for autoencoder using images in Google Drive (not preset datasets like MNIST).
I’m trying to use my photos in Google Drive to develop an Autoencoder in Keras. I loaded images using

data = pathlib.Path('/content/drive/MyDrive/my_imgs')
train_generator = ImageDataGenerator(rescale=1./255, shear_range=0.2, zoom_range=0.2)
train_generator = train_generator.flow_from_directory(data, target_size=(32, 32), batch_size=32) # DirectoryIterator: iterator of batch (array and label)

and the model is simple

W = 32
input_x = Input(shape=(W, W, 3))
x = Conv2D(10, (4, 4), padding='same')(input_x)
x = Flatten()(x)
v = Dense(W * W * 3, activation='relu')(x)
x = Reshape((W, W, 3))(v)

model = Model(input_x, x)
model.compile(optimizer='rmsprop', loss='mse')
model.summary()

Now in the train phase

model.fit(
    train_generator,
    train_generator,
    epochs=10,
    batch_size=10,
    validation_split=0.2,
    shuffle=True
)

got error

ValueError: `validation_split` is only supported for Tensors or NumPy arrays, found following types in the input: [<class 'keras.preprocessing.image.DirectoryIterator'>, <class 'keras.preprocessing.image.DirectoryIterator'>]

I think I’m going the wrong way, but I can’t find the best practice.
Does anyone know a good resource (notebook, blog etc) on it?

Thanks

Hi @Yui_Kita

Welcome to the TensorFlow Forum!

The reason of this error occurred is, Validation_split argument is not supported when x is a dataset, generator or keras.utils.Sequence instance. Please refer to the validation_split detail in model.fit() args definition for the same.

However, you can mention the validation_split() arg at the Images Generator to split the dataset such as :

train_generator = ImageDataGenerator(rescale=1./255, shear_range=0.2, zoom_range=0.2, validation_split(0.2))

Likewise, you need not to provide the target data as described in the same model.fit() args definition at Target(y) args detail.

If x is a dataset, generator, or keras.utils.Sequence instance, y should not be specified (since targets will be obtained from x )

So, please try again by removing the train_generator target data and validation_split() from the model.fit() while model training.

You can also refer to this TensorFlow Autoencoders page for more details and to know different ways of Autoencoder like the basics, image denoising, and anomaly detection. Thank you.