Skip to content

Commit a5b75c8

Browse files
authored
Merge pull request #272 from chsasank/flip
VerticalFlip converted to follow refactor #240
2 parents fbe4ad5 + 256495f commit a5b75c8

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

torchvision/transforms.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,21 @@ def hflip(img):
266266
return img.transpose(Image.FLIP_LEFT_RIGHT)
267267

268268

269+
def vflip(img):
270+
"""Vertically flip the given PIL.Image.
271+
272+
Args:
273+
img (PIL.Image): Image to be flipped.
274+
275+
Returns:
276+
PIL.Image: Vertically flipped image.
277+
"""
278+
if not _is_pil_image(img):
279+
raise TypeError('img should be PIL Image. Got {}'.format(type(img)))
280+
281+
return img.transpose(Image.FLIP_TOP_BOTTOM)
282+
283+
269284
class Compose(object):
270285
"""Composes several transforms together.
271286
@@ -548,7 +563,7 @@ def __call__(self, img):
548563

549564

550565
class RandomVerticalFlip(object):
551-
"""Vertically flip the given PIL.Image randomly with a probability of 0.5"""
566+
"""Vertically flip the given PIL.Image randomly with a probability of 0.5."""
552567

553568
def __call__(self, img):
554569
"""
@@ -559,7 +574,7 @@ def __call__(self, img):
559574
PIL.Image: Randomly flipped image.
560575
"""
561576
if random.random() < 0.5:
562-
return img.transpose(Image.FLIP_TOP_BOTTOM)
577+
return vflip(img)
563578
return img
564579

565580

0 commit comments

Comments
 (0)