How does flow_from_directory target_size deal with non-square and low-res images?

In the C1W4 lecture, “Understanding ImageDataGenerator,” we learn that target_size=(300,300) leads to images being automatically pre-processed to be of size 300x300. This raises a few questions:

  • For non-square input images, is the default behavior currently to stretch/squeeze the image into a square shape, crop it to be square, or zeropad (e.g. letterbox) it to be square? This old thread suggests the first option. Either way, is this behavior selectable? python - Keras - How to use ImageDataGenerator without deforming aspect ratio - Stack Overflow

  • Related, if the input image is lower resolution than 300x300, is the default behavior to duplicate pixels, to duplicate and smooth / interpolate, zeropad, apply some nontrivial sharpening algorithm, or other? Is this behavior selectable?

Do interpolation and keep_aspect_ratio parameters of ImageDataGenerator#flow_from_directory help?

1 Like

Ah yes, thanks! The args interpolation and keep_aspect_ratio address my question. However, I might request that if the lectures are updated that a brief comment be made about this, specifically that the default in cases of unequal resolution is to do “nearest” interpolation and, in case of aspect ratio disagreement, to center crop the image to fit the specified aspect ratio. This seems important because the lecture touts the benefits of this convenient pre-processing.