Augmentations

Augmentations#

Is some transformation of data that allows you to get more data or transfrom your data in specific way.

from torchvision import transforms
from PIL import Image

from IPython.display import HTML

To show the result of the transformations, the image loaded and displayed below is used.

img = Image.open("cat.jpg")
img
../../_images/a5e08e4693de6102a005b7858a29d70d937839ef4fa329ab838078fda86b2be9.png

Resize#

Is a transformation that allows you to set a specific size for the image. So in the following cell I show how it can be done for a specific image.

display(HTML("<h4>Transforemd image</h4>"))
display(transforms.Resize((224, 224))(img))

Transforemd image

../../_images/0ec8bbee7d72fb542c1cc7dae347c8b1a630540c2483181e806d993c5eaaab82.png

Horizontal flip#

You can use torchvision.transforms.RandomHorizontalFlip for this purpose. But this transforms the flip randomly, you have to set the p parameter as the probability of the flip.

In the following cell I is showed RandomHorizontalFlip(p=1) that always will transform picture.

transforms.RandomHorizontalFlip(p=1)(img)
../../_images/75dafc930a3a78121b0675af456957352c322f0951f3424d21120d4ae3e10703.png