Autoencoder implementation using ImageDataGenerator I'm using the concept demonstrated in this paper. Their training data consists of &quot;GOOD&quot; images and &quot;BAD&quot; images. They train the AE using &quot;BAD&quot; images (X) to make it produce &quot;GOOD&quot; image. &quot;BAD&quot; images in this case maybe very similar to &quot;GOOD&quot; image but with small dent or scratch.
I've had success using ImageDataGenerator on mnist number data but in such case it is trained by using X -&gt; X or if not using ImageDataGenerator the model fitting code will be something like model.fit(x_train, x_train).
However, in this AE problem, we want to train using X_good_and_defect -&gt; X_good or  model.fit(x_good_and_defect_train, x_good_train). Not sure how to achieve this using ImageDataGenerator.

I'm using keras's image data generator to load the images.
train_dir = r'chunks/training'
train_datagen = ImageDataGenerator(rescale=1 / 255)
train_generator = train_datagen.flow_from_directory(train_dir, target_size=(256,256), 
                   color_mode='grayscale', class_mode='input', batch_size=256)
...
autoencoder.fit(train_generator,
                epochs=5,
                batch_size=128,
                shuffle=True,
                validation_data=(test_generator, train_generator),
                callbacks=[])
As the following images from the paper shows, during training time you create patches from larger images. These patches have no defects and can therefore be seen as 'good' images. To get the accompanying 'bad' images with defects you synthetically generate these defects on the 'good' images.

Your data generator should therefore follow the following steps:

Read in full size 'good' images
Create patches from the full size images
Synthetically add defects to the patches from step 2
Return both the 'good' patches from step 2 and 'bad' patches from step 3

You then train your model using the 'bad' patches as the input and your 'good' patches as the output.