how to save resized images using ImageDataGenerator and flow_from_directory in keras

前端 未结 4 1902
情深已故
情深已故 2021-02-14 06:47

I am resizing my RGB images stored in a folder(two classes) using following code:

from keras.preprocessing.image import ImageDataGenerator
dataset=ImageDataGener         


        
4条回答
  •  伪装坚强ぢ
    2021-02-14 07:07

    The flow_from_directory method gives you an "iterator", as described in your output. An iterator doesn't really do anything on its own. It's waiting to be iterated over, and only then the actual data will be read and generated.

    An iterator in Keras for fitting is to be used like this:

    generator = dataset.flow_from_directory('/home/1',target_size=(50,50),save_to_dir='/home/resized',class_mode='binary',save_prefix='N',save_format='jpeg',batch_size=10)
    
    for inputs,outputs in generator:
    
        #do things with each batch of inputs and ouptus
    

    Normally, instead of doing the loop above, you just pass the generator to a fit_generator method. There is no real need to do a for loop:

    model.fit_generator(generator, ......)
    

    Keras will only save images after they're loaded and augmented by iterating over the generator.

提交回复
热议问题