简体   繁体   中英

Keras: how to disable resizing of images when using an ImageDataGenerator with flow_from_dataframe / flow_from_directory?

I am trying to apply some cropping operations on my images by using an ImageDataGenerator and passing a custom function to the preprocessing_function parameter . However, according to the Keras docs, this function will only run after the images are already resized:

preprocessing_function : function that will be implied on each input. The function will run after the image is resized and augmented.

Now I would like to disable resizing, however the target_size parameter defaults to (256,256) if no value is provided. Again from the docs:

target_size : Tuple of integers (height, width), default: (256, 256). The dimensions to which all images found will be resized.

I've been trying to set the target_size parameter to None , however this results in an error:

TypeError: 'NoneType' object cannot be interpreted as an integer

Cropping an already resized image yields wrong results in my case. Hence I am looking for a way, to prevent either the resizing to happen at all or for it to only happen after my custom preprocessing function has been applied. Is this possible without writing an entire custom data generator?

With the current implementation of ImageDataGenerator it is impossible. Image resizing happens while loading image , while preprocessing function is called from standardize few steps later .

Not to resize during loading is also not an option, since iterator pre-allocates the array for a batch and needs to know its shape.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM