Skip to content
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.

add keep_aspect_ratio flag to load_img #81

Closed
wants to merge 1 commit into from

Conversation

qdbp
Copy link

@qdbp qdbp commented Oct 22, 2018

Summary

Adds a keep_aspect_ratio kwarg to ImageDataGenerator.flow_from_directory to allow keeping images at their original aspect ratio, padding them to target_size with the value specified by the new cval kwarg.

Related Issues

This resuscitates keras-team/keras#4987 by popular demand.

PR Overview

  • [y ] This PR requires new unit tests [y/n] (make sure tests are included)
  • [ y] This PR requires to update the documentation [y/n] (make sure the docs are up-to-date)
  • [y ] This PR is backwards compatible [y/n]
  • [n ] This PR changes the current API [y/n] (all API changes need to be approved by fchollet)

@rragundez rragundez added the image Related to images label Jan 13, 2019
if not keep_aspect_ratio:
img = img.resize(width_height_tuple, resample)
else:
img.thumbnail(width_height_tuple, resample)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If size is smaller than width_height_tuple, then thumbnail will contain small image with edges on the right and at the bottom. I'm sure it is possible to resize an image to minimal height/width keeping aspect ratio.

@ldeluigi
Copy link

years go by

@fchollet
Copy link
Member

fchollet commented Feb 9, 2022

Closing outdated PR. Note that the Keras Preprocessing repository is no longer in use, instead please just use the dataset utilities provided in tf.keras.utils (see docs).

This particular feature is supported by image_dataset_from_directory as the crop_to_aspect_ratio argument.

@fchollet fchollet closed this Feb 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
image Related to images
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants