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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With