Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add keep_aspect_ratio flag to flow_from_directory #4987

Closed
wants to merge 1 commit into from

Conversation

qdbp
Copy link
Contributor

@qdbp qdbp commented Jan 11, 2017

I had a collection of images with non-standard, non-square sizes, and found that ImageDataGenerator would stretch them significantly.

I decided to add 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.

#3338

@fchollet
Copy link
Member

Closing outdated PR. If you still care about the content of the PR, please submit a new PR to master, updated for the Keras 2.0 API.

@fchollet fchollet closed this Mar 15, 2017
@paulo-raca
Copy link

Any particular reason why it has never been merged?
The code is very straightforward, and I believe many other have the same issue. (Well, I do 🙋‍♂️ )

If there is a better way of doing this, please let me know -- Otherwise, I can go on and make an updated pull request.

@small-yellow-duck
Copy link

I agree that having a keep_aspect_ratio flag is a good idea and I would like to see another PR opened.

@mark-meyer
Copy link

I also agreed that this would be nice to have. When dealing with classifying images it is easy to images scenarios where deforming the images id going to be a problem. Imagine a image-based iris dataset where sepal width and height are important but you are starting with inputs of different aspect ratios.

@EliasHasle
Copy link

There are even datasets where rescaling seriously breaks the data. See the ALASKA steganalysis contest.

I would expect there to be an option of padding/cropping instead of resampling, and then the fill_mode could apply naturally.

@qdbp qdbp deleted the keep_aspect_ratio branch October 22, 2018 18:10
@qdbp qdbp restored the keep_aspect_ratio branch October 22, 2018 18:10
@qdbp qdbp deleted the keep_aspect_ratio branch October 22, 2018 18:53
@codingpy
Copy link

codingpy commented May 30, 2019

Hi, I think this functionality doesn't work when the original image is smaller than the target image. But appreciate your great work. @qdbp

@jsl303
Copy link

jsl303 commented Jul 1, 2019

@xunnv, then would it be possible to enlarge smaller images as much as possible to keep the aspect ratio and then add padding?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants