Skip to content

Commit

Permalink
Merge pull request pytorch#272 from chsasank/flip
Browse files Browse the repository at this point in the history
VerticalFlip converted to follow refactor pytorch#240
  • Loading branch information
soumith authored Sep 26, 2017
2 parents fbe4ad5 + 256495f commit a5b75c8
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions torchvision/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,21 @@ def hflip(img):
return img.transpose(Image.FLIP_LEFT_RIGHT)


def vflip(img):
"""Vertically flip the given PIL.Image.
Args:
img (PIL.Image): Image to be flipped.
Returns:
PIL.Image: Vertically flipped image.
"""
if not _is_pil_image(img):
raise TypeError('img should be PIL Image. Got {}'.format(type(img)))

return img.transpose(Image.FLIP_TOP_BOTTOM)


class Compose(object):
"""Composes several transforms together.
Expand Down Expand Up @@ -548,7 +563,7 @@ def __call__(self, img):


class RandomVerticalFlip(object):
"""Vertically flip the given PIL.Image randomly with a probability of 0.5"""
"""Vertically flip the given PIL.Image randomly with a probability of 0.5."""

def __call__(self, img):
"""
Expand All @@ -559,7 +574,7 @@ def __call__(self, img):
PIL.Image: Randomly flipped image.
"""
if random.random() < 0.5:
return img.transpose(Image.FLIP_TOP_BOTTOM)
return vflip(img)
return img


Expand Down

0 comments on commit a5b75c8

Please sign in to comment.