diff --git a/torchvision/transforms/transforms.py b/torchvision/transforms/transforms.py index 85dc68314f2..f0a11432bbc 100644 --- a/torchvision/transforms/transforms.py +++ b/torchvision/transforms/transforms.py @@ -553,8 +553,9 @@ def get_params(img, scale, ratio): tuple: params (i, j, h, w) to be passed to ``crop`` for a random sized crop. """ + area = img.size[0] * img.size[1] + for attempt in range(10): - area = img.size[0] * img.size[1] target_area = random.uniform(*scale) * area aspect_ratio = random.uniform(*ratio)