keras-team / keras-preprocessing

Utilities for working with image data, text data, and sequence data.
Other
1.02k stars 444 forks source link

Keep original aspect ratio of objects in flow_from_directory #333

Closed kopytjuk closed 3 years ago

kopytjuk commented 3 years ago

Summary

Often while using ImageDataGenerator from local images, you want to maintain the aspect ratio of the objects itself in order to avoid models to learn the retransformation. This flag allows to maintain original aspect ratio of the objects.

An additional parameter in flow_from_directory is introduced, i.e. train_datagen.flow_from_directory(keep_aspect_ratio=True).

before

after

In tensorflow there is https://www.tensorflow.org/api_docs/python/tf/keras/preprocessing/image/smart_resize?hl=en , copied the logic from there, since reuse was not possible due circular import ...

Related Issues

https://github.com/keras-team/keras/pull/4987/files

https://stackoverflow.com/questions/42467734/keras-how-to-use-imagedatagenerator-without-deforming-aspect-ratio

PR Overview