Skip to content

VerticalFlip converted to follow refactor #240 #272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 26, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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