Logo elodees  elodees

A caring AI for a better world













Only alphabetic characters accented or not as well as the space are accepted

Logo IA




Image augmentation layer





No account yet ?

Sign up to access all content




Free image provided by pexel.com


Image flipping



Free image provided by pexel.com
Free image provided by pexel.com


Random Image Rotation



Free image provided by pexel.com
Free image provided by pexel.com


Random Image Zoom



Free image provided by pexel.com
Free image provided by pexel.com
Free image provided by pexel.com
Free image provided by pexel.com


Random Height and Width Shifting



Free image provided by pexel.com
Free image provided by pexel.com
Free image provided by pexel.com
Free image provided by pexel.com
Free image provided by pexel.com
Free image provided by pexel.com


Tilt and Perspective (Shear)



Free image provided by pexel.com
Free image provided by pexel.com
Free image provided by pexel.com
Free image provided by pexel.com


Lighting Transformations



Free image provided by pexel.com
Free image provided by pexel.com
Free image provided by pexel.com
Free image provided by pexel.com


Tested in Anaconda and Python 3.7

#importing libraries
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from matplotlib import pyplot
import numpy as np
import tensorflow as tf
 
# downloading and saving the image
import requests
DownURL = "https://images.pexels.com/photos/1056251/pexels-photo-1056251.jpeg?crop=entropy&cs=srgb&dl=pexels-ihsan-aditya-1056251.jpg&fit=crop&fm=jpg&h=426&w=640"
img_data = requests.get(DownURL).content
with open('/tmp/impath/cat/cat-small.jpg', 'wb') as handler:
    handler.write(img_data)
 
# setting up data pipeline to read image from disk
image_augmentor = ImageDataGenerator()
data = image_augmentor.flow_from_directory(
    "/tmp/impath",
    target_size=(213, 320),
    batch_size=1,
)
 
# plotting an original image
pyplot.imshow(data.next()[0][0].astype('int'))
pyplot.title("Without Augmentation")
 
# set up horizontal flip
image_augmentor = ImageDataGenerator(horizontal_flip=True)
data = image_augmentor.flow_from_directory(
    "/tmp/impath",
    target_size=(213, 320),
    batch_size=1,
)
pyplot.imshow(data.next()[0][0].astype('int'))
pyplot.title("Augmentation: Horizontal flip")
 
# set up vertical flip
image_augmentor = ImageDataGenerator(vertical_flip=True)
data = image_augmentor.flow_from_directory(
    "/tmp/impath",
    target_size=(213, 320),
    batch_size=1,
)
pyplot.imshow(data.next()[0][0].astype('int'))
pyplot.title("Augmentation: Vertical flip")
 
# random rotation
image_augmentor = ImageDataGenerator(rotation_range=45)
data = image_augmentor.flow_from_directory(
    "/tmp/impath",
    target_size=(213, 320),
    batch_size=1,
)
pyplot.imshow(data.next()[0][0].astype('int'))
pyplot.title("Augmentation: Random rotation")
 
# random zoom
# zooms an image to between 80% to 125%
image_augmentor = ImageDataGenerator(zoom_range=[0.8, 1.25])
data = image_augmentor.flow_from_directory(
    "/tmp/impath",
    target_size=(213, 320),
    batch_size=1,
)
pyplot.imshow(data.next()[0][0].astype('int'))
pyplot.title("Augmentation: Random zoom")
 
#Random Height Shift
image_augmentor = ImageDataGenerator(height_shift_range=0.30)
data = image_augmentor.flow_from_directory(
    "/tmp/impath",
    target_size=(213, 320),
    batch_size=1,
)
pyplot.imshow(data.next()[0][0].astype('int'))
pyplot.title("Augmentation: Height shift")
 
#Random Width Shift
image_augmentor = ImageDataGenerator(width_shift_range=0.30)
data = image_augmentor.flow_from_directory(
    "/tmp/impath",
    target_size=(213, 320),
    batch_size=1,
)
pyplot.imshow(data.next()[0][0].astype('int'))
pyplot.title("Augmentation: Width shift")
 
#Random Height & Width Shift
image_augmentor = ImageDataGenerator(width_shift_range=0.30, height_shift_range=0.30)
data = image_augmentor.flow_from_directory(
    "/tmp/impath",
    target_size=(213, 320),
    batch_size=1,
)
pyplot.imshow(data.next()[0][0].astype('int'))
pyplot.title("Augmentation: Height & width shift")
 
#Tilt and Perspective (Shear)
image_augmentor = ImageDataGenerator(shear_range=45)
data = image_augmentor.flow_from_directory(
    "/tmp/impath",
    target_size=(213, 320),
    batch_size=1,
)
pyplot.imshow(data.next()[0][0].astype('int'))
pyplot.title("Augmentation: Tilt & perspective")
 
#Lighting Transformations
image_augmentor = ImageDataGenerator(brightness_range=(0.3, 1))
data = image_augmentor.flow_from_directory(
    "/tmp/impath",
    target_size=(213, 320),
    batch_size=1,
)
pyplot.imshow(data.next()[0][0].astype('int'))
pyplot.title("Augmentation: Brightness")
 


Source : https://datamonje.com/image-data-augmentation/





Layers of neural networks


Machine learning

Deep learning














Welcome, my name is Eric Soupet and I am the administrator of the site elodees.com. elodees.com is a state of the art of Artificial Intelligence and aims to be collaborative, you can now offer content such as articles, events, tutorials, ... so don't hesitate !

Platform images credit : Pixabay - Pixabay License | Pexels - Pexels License