@@ -323,19 +323,23 @@ def __call__(self, img):
323
323
class RandomResizedCrop (object ):
324
324
"""Crop the given PIL Image to random size and aspect ratio.
325
325
326
- A crop of random size of ( 0.08 to 1.0) of the original size and a random
327
- aspect ratio of 3/4 to 4/3 of the original aspect ratio is made. This crop
326
+ A crop of random size (default: of 0.08 to 1.0) of the original size and a random
327
+ aspect ratio (default: of 3/4 to 4/3) of the original aspect ratio is made. This crop
328
328
is finally resized to given size.
329
329
This is popularly used to train the Inception networks.
330
330
331
331
Args:
332
332
size: expected output size of each edge
333
+ scale: range of size of the origin size cropped
334
+ ratio: range of aspect ratio of the origin aspect ratio cropped
333
335
interpolation: Default: PIL.Image.BILINEAR
334
336
"""
335
337
336
- def __init__ (self , size , interpolation = Image .BILINEAR ):
338
+ def __init__ (self , size , scale = ( 0.08 , 1.0 ), ratio = ( 3. / 4. , 4. / 3. ), interpolation = Image .BILINEAR ):
337
339
self .size = (size , size )
338
340
self .interpolation = interpolation
341
+ self .scale = scale
342
+ self .ratio = ratio
339
343
340
344
@staticmethod
341
345
def get_params (img ):
@@ -350,8 +354,8 @@ def get_params(img):
350
354
"""
351
355
for attempt in range (10 ):
352
356
area = img .size [0 ] * img .size [1 ]
353
- target_area = random .uniform (0.08 , 1.0 ) * area
354
- aspect_ratio = random .uniform (3. / 4 , 4. / 3 )
357
+ target_area = random .uniform (* self . scale ) * area
358
+ aspect_ratio = random .uniform (* self . ratio )
355
359
356
360
w = int (round (math .sqrt (target_area * aspect_ratio )))
357
361
h = int (round (math .sqrt (target_area / aspect_ratio )))
0 commit comments