Skip to content

Commit

Permalink
PIL Image.transform should take in size (width, height)
Browse files Browse the repository at this point in the history
  • Loading branch information
Qizhe Xie committed Feb 8, 2020
1 parent abfb73d commit 960684e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions image/randaugment/augmentation_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ def get_mean_and_std():
return means, stds


def _width_height_from_img_shape(img_shape):
"""`img_shape` in autoaugment is (height, width)."""
return (img_shape[1], img_shape[0])


def random_flip(x):
"""Flip the input x horizontally with 50% probability."""
if np.random.rand(1)[0] > 0.5:
Expand Down Expand Up @@ -315,7 +320,7 @@ def _shear_x_impl(pil_img, level, img_shape):
if random.random() > 0.5:
level = -level
return pil_img.transform(
(img_shape[0], img_shape[1]),
_width_height_from_img_shape(img_shape),
Image.AFFINE,
(1, level, 0, 0, 1, 0))

Expand All @@ -341,7 +346,7 @@ def _shear_y_impl(pil_img, level, img_shape):
if random.random() > 0.5:
level = -level
return pil_img.transform(
(img_shape[0], img_shape[1]),
_width_height_from_img_shape(img_shape),
Image.AFFINE,
(1, 0, 0, level, 1, 0))

Expand All @@ -367,7 +372,7 @@ def _translate_x_impl(pil_img, level, img_shape):
if random.random() > 0.5:
level = -level
return pil_img.transform(
(img_shape[0], img_shape[1]),
_width_height_from_img_shape(img_shape),
Image.AFFINE,
(1, 0, level, 0, 1, 0))

Expand All @@ -393,7 +398,7 @@ def _translate_y_impl(pil_img, level, img_shape):
if random.random() > 0.5:
level = -level
return pil_img.transform(
(img_shape[0], img_shape[1]),
_width_height_from_img_shape(img_shape),
Image.AFFINE,
(1, 0, 0, 0, 1, level))

Expand Down

0 comments on commit 960684e

Please sign in to comment.