An example with library imgaug, Keras, ImageDataGenerator and flow_from_dataframe:
import imgaug as ia
import imgaug.augmenters as iaa
seq = iaa.Sequential([
iaa.Crop(px=(0, 16)),
# crop images from each side by 0 to 16px (randomly chosen)
iaa.Fliplr(0.5),
# horizontally flip 50% of the images
iaa.GaussianBlur(sigma=(0, 3.0))
# blur images with a sigma of 0 to 3.0
])
def augment(img):
seq_det = seq.to_deterministic()
aug_image = seq_det.augment_image(img)
return applications.inception_resnet_v2.preprocess_input(aug_image)
train_generator = image.ImageDataGenerator(preprocessing_function=augment)
train_flow = train_generator.flow_from_dataframe(
dataframe=train_df,
directory=train_data_dir,
x_col="path",
y_col=columns,
batch_size=batch_size,
class_mode="other",
target_size=(img_height ,img_width),
shuffle=True
)