0

I am really new to using tensorflow and working with CNNs. I'm trying to load my image dataset and resize and grayscale each image. I was reading documentation on TensorFlow Keras.preprocessing.image.directoryIterator. I tried it (code below) and it finds all my images but it doesn't actually save them or make any modifications to the images? Am I doing something wrong? I have this code by itself, so I'm not sure if I have to set anything else up to make this work. Any help is appreciated!! There is not much documentation or help on the internet unfortunately :(

Note: I have excluded my local file path where the images are contained - but I do actually have a legit path in my code. Also, the save_to_dir argument, Im not sure if it is just the directory name or a complete file path but I have tried both ways and they do not work.

image.DirectoryIterator(
'LOCAL FILE PATH', image_data_generator, target_size=(170, 170),
color_mode ='grayscale', classes =['Face', 'NonFace'], class_mode ="categorical",
batch_size=5, shuffle=True, seed=None, data_format ='channels_first',
save_to_dir = 'Test', save_prefix='Test_', save_format ='jpg',
follow_links=False, subset=None, interpolation='nearest', dtype=None)
user2197867
  • 83
  • 2
  • 7

1 Answers1

0

You need to trigger the generator Iterator which you have created.

Below is the code which will save the files in the desired directory.

import tensorflow as tf
from tensorflow.keras.preprocessing.image import ImageDataGenerator 

image_data_generator = ImageDataGenerator() 

image = tf.keras.preprocessing.image.DirectoryIterator(
'/content/Images/', image_data_generator, target_size=(170, 170),
color_mode ='grayscale', classes =['Face', 'NonFace'], class_mode ="categorical",
batch_size=5, shuffle=True, seed=None, data_format ='channels_first',
save_to_dir = '/content/Test/', save_prefix='Test_', save_format ='jpg',
follow_links=False, subset=None, interpolation='nearest', dtype=None)

image.next() # This line will trigger the execution of Iterator.