This notebook contains implementation of the randaugment item transform
%reload_ext autoreload
%autoreload 2
import matplotlib.pyplot as plt
from fastai2.data.all import untar_data, URLs
from fastai2.vision.all import get_image_files
cifar = untar_data(URLs.CIFAR)
img = Image.open(get_image_files(cifar)[0])
All transformations as functions f(img, level)
, where level is in $[0, \texttt{PARAMETER_MAX}]$ as in randaugment paper.
We use standard geometric transforms, pixel level color transforms and cutout (cutout was used in UDA implementation, and is also present in randaugment) from PIL and albumenations. Geometric transforms:
Color transforms include, inversion, autocontrast, histogram equalization, contrast change, color change, brightness change, sharpness change. For contrast, color, brightness and sharpness we manually select ranges (e.g color could change to black and white, or realy vivid based on the value of level
parameter + randomness).
All implemented transforms:
Visualize transforms
def identity(img, level):
return img
plt.figure(figsize=(10,6))
cnt = len(all_transforms)
print(f"Showing all {cnt} transformations")
for i, t in enumerate([identity] + ALL_TRANSFORMS, 1):
plt.subplot((cnt + 1) // 5 + (cnt+1) % 5, 5, i)
plt.imshow(t(img, 10))
plt.axis(False)
plt.title(t.__name__)
plt.tight_layout()
plt.show()
Policy, randomly choosing 2 transformations
ra = RandAugment()
plt.figure(figsize=(15,15))
for i in range(1,31):
plt.subplot(5,6,i)
plt.imshow(ra(PILImage.create(files[0])))
plt.show()
from nbdev.export import notebook2script
notebook2script()