Path: blob/master/notebooks/book1/19/image_augmentation_jax.ipynb
1192 views
Please find torch implementation of this notebook here: https://colab.research.google.com/github/probml/pyprobml/blob/master/notebooks/book1/19/image_augmentation_torch.ipynb
AUTHOR : Susnato Dhar (Github : https://github.com/susnato)
IMAGE AUGMENTATION
This Notebook shows how to apply Image Augmentation using JAX, based on 13.1. of http://d2l.ai/chapter_computer-vision/image-augmentation.html
ACKNOWLEDGEMENTS & MENTIONS
- This Notebook uses Augmax made by Konrad Heidler. Which is an Image Data Augmentation Framework with support for JAX function transformations.
Cloning AUGMAX
Repository & Installing it
I took the image from github repo but feel free to use your own.
To visualize an image augmentation, which may be stochastic, we apply it multiple times to an image.
Flipping
Crop and resize
Below, we randomly crop a region with an area of 10% to 100% of the original area, and the ratio of width to height of the region is randomly selected from between 0.5 and 2. Then, the width and height of the region are both scaled to 200 pixels.
Changing color
We can change brightness, contrast, saturation and hue. First we change brightness, from 1-0.5=0.5 times less to 1+0.5=1.5 times more.
Now we change hue.
Now we change saturation.
Now we change contrast.
Combining multiple augmentations in a pipeline
Using augmentations in a dataloader
We illustrate how we can transform training and test images from CIFAR10.
Downloading and preparing dataset cifar10/3.0.2 (download: 162.17 MiB, generated: 132.40 MiB, total: 294.58 MiB) to /root/tensorflow_datasets/cifar10/3.0.2...
Dataset cifar10 downloaded and prepared to /root/tensorflow_datasets/cifar10/3.0.2. Subsequent calls will reuse this data.