1

I have a training set of images with structure like this:

path = /aug-dir/img_dir
             1.jpg
             2.jpg
             ...jpg

I am trying to augment the images and save them to disk for future use. I want to implement the below code:

## I want to do only mobilenet.preprocess_input and no other data augmentation

datagen = ImageDataGenerator(preprocessing_function=tensorflow.keras.applications.mobilenet.preprocess_input)
aug_datagen_test = datagen.flow_from_directory(path,
                                               save_to_dir=save_path, ### want to save the images to save_path
                                               save_format='jpg',
                                               target_size=(image_size,image_size),
                                               batch_size=1, 
                                               shuffle = False)

When I generate the image, the preprocessing_function (i.e. mobilenet.preprocess_input) is applied properly and I am getting the correct result.

for i in range(11):
     imgs, labels = next(aug_datagen_test)

plt.figure(figsize=(10,5))
plt.subplot(1,2,1)
plt.imshow(orginal_image)
plt.title('Original_image')

plt.subplot(1,2,2)
plt.imshow(imgs[0])
plt.title('output from ImageDataGenerator')
plt.show()

plot of original image and datagenerator image

But the 'output from ImageDataGenerator' (the actual output) image is not saved in save_path. This is how the image is saved in save_path after the data augmentation.

image from save_path

Am I doing something wrong? Why is the correct output not saved to the disk?

Please let me know if any further details are required.

Note: I am getting the same output from datagen.flow i.e. the image is not saved properly.

Any help or suggestion is appreciated.

Thank you very much

Rao208
  • 147
  • 1
  • 3
  • 15
  • Generally we can save augmented images using `ImageDataGenerator`. Are there any specific reason that are you trying `mobilenet.preprocess_input` ? –  Oct 09 '20 at 16:43

0 Answers0