dl-workshop-2022

Augmenting data (images)

No augmentation

datagen = ImageDataGenerator(
    rescale=1./255)

Some augmentation

datagen = ImageDataGenerator(
    rescale=1./255,
    rotation_range=2,
    width_shift_range=0.05,
    height_shift_range=0.05,
    horizontal_flip=True)
    
augmented_train_ds = datagen.flow_from_directory(
  './face-expression-kaggle/images/train/',
  target_size=(48, 48),
  shuffle=True,
  batch_size=32)

augmented_valid_ds = datagen.flow_from_directory(
  './face-expression-kaggle/images/validation/',
  target_size=(48, 48),
  shuffle=True,
  batch_size=32)
  
import matplotlib.pyplot as plt
# Take one batch full of images
images, labels = augmented_train_ds[0]
print(images.shape)
plt.imshow(images[0])
plt.title(labels[0])
plt.axis("off")
    

Heavy augmentation

datagen = ImageDataGenerator(
    rescale=1./255,
    rotation_range=20,
    width_shift_range=0.3,
    height_shift_range=0.3,
    horizontal_flip=True,
    shear_range=2.0)
    
augmented_train_ds = datagen.flow_from_directory(
  './face-expression-kaggle/images/train/',
  target_size=(48, 48),
  shuffle=True,
  batch_size=32)

augmented_valid_ds = datagen.flow_from_directory(
  './face-expression-kaggle/images/validation/',
  target_size=(48, 48),
  shuffle=True,
  batch_size=32)
    
import matplotlib.pyplot as plt
# Take one batch full of images
images, labels = augmented_train_ds[0]
print(images.shape)
plt.imshow(images[0])
plt.title(labels[0])
plt.axis("off") 
   

tf.keras.preprocessing.image.ImageDataGenerator

tf.keras.preprocessing.image.ImageDataGenerator(
    featurewise_center=False,
    samplewise_center=False,
    featurewise_std_normalization=False,
    samplewise_std_normalization=False,
    zca_whitening=False,
    zca_epsilon=1e-06,
    rotation_range=0,
    width_shift_range=0.0,
    height_shift_range=0.0,
    brightness_range=None,
    shear_range=0.0,
    zoom_range=0.0,
    channel_shift_range=0.0,
    fill_mode='nearest',
    cval=0.0,
    horizontal_flip=False,
    vertical_flip=False,
    rescale=None,
    preprocessing_function=None,
    data_format=None,
    validation_split=0.0,
    interpolation_order=1,
    dtype=None
)