# Deep Learning CNN model to recognize face
'''This script uses a database of images and creates CNN model on top of it to test
if the given image is recognized correctly or not'''
'''####### IMAGE PRE-PROCESSING for TRAINING and TESTING data #######'''
# Specifying the folder where images are present
TrainingImagePath='/Users/farukh/Python Case Studies/Face Images/Final Training Images'
from keras.preprocessing.image import ImageDataGenerator
# Understand more about ImageDataGenerator at below link
# https://blog.keras.io/building-powerful-image-classification-models-using-very-little-data.html
# Defining pre-processing transformations on raw images of training data
# These hyper parameters helps to generate slightly twisted versions
# of the original image, which leads to a better model, since it learns
# on the good and bad mix of images
train_datagen = ImageDataGenerator(
shear_range=0.1,
zoom_range=0.1,
horizontal_flip=True)
# Defining pre-processing transformations on raw images of testing data
# No transformations are done on the testing images
test_datagen = ImageDataGenerator()
# Generating the Training Data
training_set = train_datagen.flow_from_directory(
TrainingImagePath,
target_size=(64, 64),
batch_size=32,
class_mode='categorical')
# Generating the Testing Data
test_set = test_datagen.flow_from_directory(
TrainingImagePath,
target_size=(64, 64),
batch_size=32,
class_mode='categorical')
# Printing class labels for each face
test_set.class_indices