Skip to content

Commit c90f57d

Browse files
committed
Fix randomresized params flaky (#1282)
* Fix flakiness of test_randomresized_params * Real fix * Reduce number of iters
1 parent 887c41c commit c90f57d

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

test/test_transforms.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ def test_randomresized_params(self):
141141
img = to_pil_image(img)
142142
size = 100
143143
epsilon = 0.05
144+
min_scale = 0.25
144145
for _ in range(10):
145-
scale_min = round(random.random(), 2)
146+
scale_min = max(round(random.random(), 2), min_scale)
146147
scale_range = (scale_min, scale_min + round(random.random(), 2))
147148
aspect_min = max(round(random.random(), 2), epsilon)
148149
aspect_ratio_range = (aspect_min, aspect_min + round(random.random(), 2))

torchvision/transforms/transforms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ def get_params(img, scale, ratio):
645645
w = int(round(math.sqrt(target_area * aspect_ratio)))
646646
h = int(round(math.sqrt(target_area / aspect_ratio)))
647647

648-
if w <= img.size[0] and h <= img.size[1]:
648+
if 0 < w <= img.size[0] and 0 < h <= img.size[1]:
649649
i = random.randint(0, img.size[1] - h)
650650
j = random.randint(0, img.size[0] - w)
651651
return i, j, h, w

0 commit comments

Comments
 (0)