Unverified Commit d4aa0111 authored by Aditya Oke's avatar Aditya Oke Committed by GitHub
Browse files

Add illustrations for AutoAugment in gallery example (#3727)


Co-authored-by: default avatarNicolas Hug <nicolashug@fb.com>
parent c2b8575c
...@@ -178,3 +178,26 @@ plot(random_apply_img, "Random Apply transformed Image") ...@@ -178,3 +178,26 @@ plot(random_apply_img, "Random Apply transformed Image")
# performs gaussianblur transform on an image. # performs gaussianblur transform on an image.
gaus_blur_img = T.GaussianBlur(kernel_size=(5, 9), sigma=(0.4, 3.0))(orig_img) gaus_blur_img = T.GaussianBlur(kernel_size=(5, 9), sigma=(0.4, 3.0))(orig_img)
plot(gaus_blur_img, "Gaussian Blurred Image") plot(gaus_blur_img, "Gaussian Blurred Image")
####################################
# AutoAugment
# -----------
# The :class:`~torchvision.transforms.AutoAugment` transform
# automatically augments data based on a given auto-augmentation policy.
# See :class:`~torchvision.transforms.AutoAugmentPolicy` for the available policies.
policies = [T.AutoAugmentPolicy.CIFAR10, T.AutoAugmentPolicy.IMAGENET, T.AutoAugmentPolicy.SVHN]
num_cols = 5
fig, axs = plt.subplots(nrows=len(policies), ncols=num_cols)
fig.suptitle("Auto-augmented images with different policies")
for pol_idx, policy in enumerate(policies):
auto_augmenter = T.AutoAugment(policy)
for col in range(num_cols):
augmented_img = auto_augmenter(orig_img)
ax = axs[pol_idx, col]
ax.imshow(np.asarray(augmented_img))
ax.set(xticklabels=[], yticklabels=[], xticks=[], yticks=[])
if col == 0:
ax.set(ylabel=str(policy).split('.')[-1])
...@@ -142,16 +142,6 @@ class AutoAugment(torch.nn.Module): ...@@ -142,16 +142,6 @@ class AutoAugment(torch.nn.Module):
If input is Tensor, only ``InterpolationMode.NEAREST``, ``InterpolationMode.BILINEAR`` are supported. If input is Tensor, only ``InterpolationMode.NEAREST``, ``InterpolationMode.BILINEAR`` are supported.
fill (sequence or number, optional): Pixel fill value for the area outside the transformed fill (sequence or number, optional): Pixel fill value for the area outside the transformed
image. If given a number, the value is used for all bands respectively. image. If given a number, the value is used for all bands respectively.
If input is PIL Image, the options is only available for ``Pillow>=5.0.0``.
Example:
>>> t = transforms.AutoAugment()
>>> transformed = t(image)
>>> transform=transforms.Compose([
>>> transforms.Resize(256),
>>> transforms.AutoAugment(),
>>> transforms.ToTensor()])
""" """
def __init__(self, policy: AutoAugmentPolicy = AutoAugmentPolicy.IMAGENET, def __init__(self, policy: AutoAugmentPolicy = AutoAugmentPolicy.IMAGENET,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment