I'm working on facial expression recognition using Keras, the dataset I'm using does not have a big amount of data available, So I'm going to use Keras's image preprocessing for data augmentation.
I want to know the best parameters of ImageDataGenerator to generate normal faces wich I can use to train my neural network with.
Here's the code I'm using for Data augmentation :
def data_augmentation(subdir):
datagen = ImageDataGenerator(
featurewise_center=False,
samplewise_center=False,
featurewise_std_normalization=False,
samplewise_std_normalization=False,
zca_whitening=False,
rotation_range=30,
width_shift_range=0.2,
height_shift_range=0.2,
horizontal_flip=True,
vertical_flip=False)
print ("\nData augmentation...")
print ("\nProcess...")
for file in glob.glob(subdir+"*/*.jpg"):
img = load_img(file)
print ("\nProcessing..." + str(file))
x = img_to_array(img)
x = x.reshape((1,) + x.shape)
i = 0
for batch in datagen.flow(x, batch_size=1, save_to_dir='data_aug', save_prefix='Fig', save_format='jpg'):
i += 1
if i > 20:
break
Here's all ImageDataGenerator's parameters
keras.preprocessing.image.ImageDataGenerator(featurewise_center=False,
samplewise_center=False,
featurewise_std_normalization=False,
samplewise_std_normalization=False,
zca_whitening=False,
zca_epsilon=1e-6,
rotation_range=0.,
width_shift_range=0.,
height_shift_range=0.,
shear_range=0.,
zoom_range=0.,
channel_shift_range=0.,
fill_mode='nearest',
cval=0.,
horizontal_flip=False,
vertical_flip=False,
rescale=None,
preprocessing_function=None,
data_format=K.image_data_format())
And here's an example of images generated using my code :
As you can see, the images are distorted and not good enough to train my network.
I want to know what's the best parameters of ImageDataGenerator for human faces or is there any better methods for data augmentation ?
yes you can increase the size by creating and saving augmented images for each class then merging those images with the original trainset.
target_size: Tuple of integers (height, width) , default: (256, 256) . The dimensions to which all images found will be resized. interpolation: Interpolation method used to resample the image if the target size is different from that of the loaded image.
There are a total of 1646 unique images in the dataset. Since these are not a lot of images to create a robust neural network, it will act as a great dataset to test the potential of the ImageDataGenerator class!
If you are dealing with faces only, check this paper: http://www.openu.ac.il/home/hassner/projects/augmented_faces/ It can generate 30 images from a single face image. Also you can use virtual makeup implementations in python. They are easy to use and successful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With