Demo entry 6636094

augmentation

   

Submitted by anonymous on Aug 23, 2017 at 06:41
Language: Python 3. Code size: 912 Bytes.

from keras.preprocessing import image

gen = image.ImageDataGenerator(rotation_range=10,
                                width_shift_range=0.1,
                                height_shift_range=0.1,
                                width_zoom_range=0.2,
                                shear_range=0.15,
                                zoom_range=0.1,
                                channel_shift_range=10.,
                                horizontal_flip=True,
                                dim_ordering='tf'
                               )

# Create a 'batch' of a single image
img = np.expand_dims(ndimage.imread('data/dogscats/test/7.jpg'),0)
# Request the generator to create batches from this image
aug_iter = gen.flow(img)
# Get eight examples of these augmented images
aug_imgs = [next(aug_iter)[0].astype(np.uint8) for i in range(8)]
# Augmented data
plots(aug_imgs, (20,7), 2)

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).