Skip to content
Advertisement

ImageDataGenerator() for CNN with input and output as an Image

I’m looking for a training map with something like this:

Grayscale Image -> Coloured Image

But the dataset can’t be loaded all to the ram as X and Y because of obvious reasons.

I looked up the ImageDataGenerator() library, but it didn’t give me a clear answer as to make it work here.

Summary:

Input Shape = (2048, 2048, 1)

Output Shape = (2048, 2048, 2)

Training Dataset = 17,000 images

Validation Dataset = 1,000 images

Here’s the structure of the model I’m trying to train:

JavaScript

Advertisement

Answer

That would be easiest with a custom training loop.

JavaScript

Here, my data iterator is cyling through all the color pictures, but its converted to grayscale before being passed to the model. Then, the RGB output of the model is compared to the original RGB image. You will have to use the argument class_mode=None in flow_from_directory. I used tf.image.rgb_to_grayscale to make the conversion between grayscale and RGB.

Full example:

JavaScript
Advertisement