@@ -321,7 +321,14 @@ def __repr__(self):
321
321
322
322
323
323
class RandomHorizontalFlip (object ):
324
- """Horizontally flip the given PIL Image randomly with a probability of 0.5."""
324
+ """Horizontally flip the given PIL Image randomly with a given probability.
325
+
326
+ Args:
327
+ p (float): probability of the image being flipped. Default value is 0.5
328
+ """
329
+
330
+ def __init__ (self , p = 0.5 ):
331
+ self .p = p
325
332
326
333
def __call__ (self , img ):
327
334
"""
@@ -331,16 +338,23 @@ def __call__(self, img):
331
338
Returns:
332
339
PIL Image: Randomly flipped image.
333
340
"""
334
- if random .random () < 0.5 :
341
+ if random .random () < self . p :
335
342
return F .hflip (img )
336
343
return img
337
344
338
345
def __repr__ (self ):
339
- return self .__class__ .__name__ + '()'
346
+ return self .__class__ .__name__ + '(p={})' . format ( self . p )
340
347
341
348
342
349
class RandomVerticalFlip (object ):
343
- """Vertically flip the given PIL Image randomly with a probability of 0.5."""
350
+ """Vertically flip the given PIL Image randomly with a given probability.
351
+
352
+ Args:
353
+ p (float): probability of the image being flipped. Default value is 0.5
354
+ """
355
+
356
+ def __init__ (self , p = 0.5 ):
357
+ self .p = p
344
358
345
359
def __call__ (self , img ):
346
360
"""
@@ -350,12 +364,12 @@ def __call__(self, img):
350
364
Returns:
351
365
PIL Image: Randomly flipped image.
352
366
"""
353
- if random .random () < 0.5 :
367
+ if random .random () < self . p :
354
368
return F .vflip (img )
355
369
return img
356
370
357
371
def __repr__ (self ):
358
- return self .__class__ .__name__ + '()'
372
+ return self .__class__ .__name__ + '(p={})' . format ( self . p )
359
373
360
374
361
375
class RandomResizedCrop (object ):
0 commit comments