Skip to content

Commit 2041402

Browse files
alykhantejanifmassa
authored andcommitted
add scale and ratio params to RandomResizedCrop.get_params (#345)
1 parent aae0dc6 commit 2041402

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

torchvision/transforms/transforms.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,20 +342,22 @@ def __init__(self, size, scale=(0.08, 1.0), ratio=(3. / 4., 4. / 3.), interpolat
342342
self.ratio = ratio
343343

344344
@staticmethod
345-
def get_params(img):
345+
def get_params(img, scale, ratio):
346346
"""Get parameters for ``crop`` for a random sized crop.
347347
348348
Args:
349349
img (PIL Image): Image to be cropped.
350+
scale (tuple): range of size of the origin size cropped
351+
ratio (tuple): range of aspect ratio of the origin aspect ratio cropped
350352
351353
Returns:
352354
tuple: params (i, j, h, w) to be passed to ``crop`` for a random
353355
sized crop.
354356
"""
355357
for attempt in range(10):
356358
area = img.size[0] * img.size[1]
357-
target_area = random.uniform(*self.scale) * area
358-
aspect_ratio = random.uniform(*self.ratio)
359+
target_area = random.uniform(*scale) * area
360+
aspect_ratio = random.uniform(*ratio)
359361

360362
w = int(round(math.sqrt(target_area * aspect_ratio)))
361363
h = int(round(math.sqrt(target_area / aspect_ratio)))
@@ -382,7 +384,7 @@ def __call__(self, img):
382384
Returns:
383385
PIL Image: Randomly cropped and resize image.
384386
"""
385-
i, j, h, w = self.get_params(img)
387+
i, j, h, w = self.get_params(img, self.scale, self.ratio)
386388
return F.resized_crop(img, i, j, h, w, self.size, self.interpolation)
387389

388390

0 commit comments

Comments
 (0)