Composing image data using keras.preprocessing.image.ImageDataGenerator?

I would like to generate additional data for images using random rotation, shift, shift and flip.

I found this keras

feature.

Function keras.preprocessing.image.ImageDataGenerator

But I have seen this is used to provision networks directly.

Is there a way to input images and then save the converted images to HDD instead of what currently works in the examples in the link

Or is there another simple plugin and use the python package that I can use instead of implementing everything with numpy

or opencv

?

+3


source to share


2 answers


Basically it's this generator

that returns batches of images endlessly. The following could be done:

def save_images_from_generator(maximal_nb_of_images, generator):
    nb_of_images_processed = 0
    for x, _ in generator:
        nb_of_images += x.shape[0]
        if nb_of_images <= maximal_nb_of_images:
            for image_nb in range(x.shape[0]):
                your_custom_save(x[image_nb]) # your custom function for saving images
        else:
            break

      



to save images from the image generator keras

.

+1


source


You can save the images output by ImageGenerator to your hard drive. One option is to use datagen.flow like this:

for X_batch, y_batch in datagen.flow(X_train, y_train, batch_size=9, save_to_dir='images', save_prefix='aug', save_format='png')

      

The second option is to manually iterate over each image, load it, and apply a random transform. Once you've created an ImageGenerator instance, just call:



img_trans = datagen.random_transform(img)

      

Then save the converted image to your hard drive using PIL, etc.

The third option is to manually iterate over each image, load it, and apply a random transform using a third party program. I recommend imgaug found here .

0


source







All Articles