Skip to content

Commit

Permalink
Fix randomresized params flaky (#1282)
Browse files Browse the repository at this point in the history
* Fix flakiness of test_randomresized_params

* Real fix

* Reduce number of iters
  • Loading branch information
fmassa committed Aug 30, 2019
1 parent a44a163 commit 7c9bbf5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion test/test_transforms.py
Expand Up @@ -141,8 +141,9 @@ def test_randomresized_params(self):
img = to_pil_image(img)
size = 100
epsilon = 0.05
min_scale = 0.25
for _ in range(10):
scale_min = round(random.random(), 2)
scale_min = max(round(random.random(), 2), min_scale)
scale_range = (scale_min, scale_min + round(random.random(), 2))
aspect_min = max(round(random.random(), 2), epsilon)
aspect_ratio_range = (aspect_min, aspect_min + round(random.random(), 2))
Expand Down
2 changes: 1 addition & 1 deletion torchvision/transforms/transforms.py
Expand Up @@ -645,7 +645,7 @@ def get_params(img, scale, ratio):
w = int(round(math.sqrt(target_area * aspect_ratio)))
h = int(round(math.sqrt(target_area / aspect_ratio)))

if w <= img.size[0] and h <= img.size[1]:
if 0 < w <= img.size[0] and 0 < h <= img.size[1]:
i = random.randint(0, img.size[1] - h)
j = random.randint(0, img.size[0] - w)
return i, j, h, w
Expand Down

0 comments on commit 7c9bbf5

Please sign in to comment.