Skip to content

Fix randomresized params flaky #1282

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

Merged
merged 3 commits into from
Aug 30, 2019

Conversation

fmassa
Copy link
Member

@fmassa fmassa commented Aug 30, 2019

Fixes #1170

The flakiness is due to the rounding in

w = int(round(math.sqrt(target_area * aspect_ratio)))
h = int(round(math.sqrt(target_area / aspect_ratio)))

We are guaranteed that the floating point values for the dimensions gives an aspect ratio between the requested range, but after rounding this doesn't hold anymore.

One possible fix would be to re-check that this is still the case after rounding in

if w <= img.size[0] and h <= img.size[1]:
similar to what was done in #1181, but this won't guard us from going outside of the requested aspect ratio in the fallback implementation in
# Fallback to central crop
in_ratio = img.size[0] / img.size[1]
if (in_ratio < min(ratio)):
w = img.size[0]
h = int(round(w / min(ratio)))
elif (in_ratio > max(ratio)):
h = img.size[1]
w = int(round(h * max(ratio)))
else: # whole image
w = img.size[0]
h = img.size[1]
i = (img.size[1] - h) // 2
j = (img.size[0] - w) // 2

Given that for arbitrary values of scale, ratio and sizes there is no guarantee that there exists an integer value that satisfies all the constraints, I decided instead to keep the implementation the same, but to increase the minimum scale that is allowed during the tests, so that rounding differences are amortized, and tests passes much more often.

The only fix that is done in the transforms here is to avoid empty-sized dimensions to be returned, which was a problem with the previous implementation.

@fmassa fmassa requested a review from lw August 30, 2019 13:22
@fmassa fmassa unassigned lw Aug 30, 2019
Copy link

@lw lw left a comment

Choose a reason for hiding this comment

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

Ok for a mitigation, could be reworked some more to make it more robust.

@fmassa fmassa merged commit 7c9bbf5 into pytorch:master Aug 30, 2019
@fmassa fmassa deleted the fix_randomresized_params_flaky branch August 30, 2019 13:33
@fmassa fmassa mentioned this pull request Oct 31, 2019
fmassa added a commit that referenced this pull request Oct 31, 2019
* Fix flakiness of test_randomresized_params

* Real fix

* Reduce number of iters
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.

test_randomresized_params is flaky
2 participants