@@ -342,20 +342,22 @@ def __init__(self, size, scale=(0.08, 1.0), ratio=(3. / 4., 4. / 3.), interpolat
342
342
self .ratio = ratio
343
343
344
344
@staticmethod
345
- def get_params (img ):
345
+ def get_params (img , scale , ratio ):
346
346
"""Get parameters for ``crop`` for a random sized crop.
347
347
348
348
Args:
349
349
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
350
352
351
353
Returns:
352
354
tuple: params (i, j, h, w) to be passed to ``crop`` for a random
353
355
sized crop.
354
356
"""
355
357
for attempt in range (10 ):
356
358
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 )
359
361
360
362
w = int (round (math .sqrt (target_area * aspect_ratio )))
361
363
h = int (round (math .sqrt (target_area / aspect_ratio )))
@@ -382,7 +384,7 @@ def __call__(self, img):
382
384
Returns:
383
385
PIL Image: Randomly cropped and resize image.
384
386
"""
385
- i , j , h , w = self .get_params (img )
387
+ i , j , h , w = self .get_params (img , self . scale , self . ratio )
386
388
return F .resized_crop (img , i , j , h , w , self .size , self .interpolation )
387
389
388
390
0 commit comments