text_html_output_1.png
from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img

import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

main_folder = '../input/celeba-dataset/'
images_folder = main_folder + 'img_align_celeba/img_align_celeba/'
example_pic = images_folder + '000506.jpg'
training_sample = 10000
validation_sample = 2000
test_sample = 2000
img_width = 178
img_height = 218
batch_size = 16
num_epochs = 5

df_attr = pd.read_csv(main_folder + 'list_attr_celeba.csv')
df_attr.set_index('image_id', inplace=True)
df_attr.replace(to_replace=-1, value=0, inplace=True)

df_attr.columns

df_attr.isnull().sum()

df_attr.shape

img = load_img(example_pic)
df_attr.loc[example_pic.split('/')[-1]][['Smiling', 'Male', 'Young']]

def load_reshape_img(fname):
    img = load_img(fname)
    x = img_to_array(img) / 255.0
    x = x.reshape((1,) + x.shape)
    return x

datagen = ImageDataGenerator(rotation_range=30, width_shift_range=0.2, height_shift_range=0.2, shear_range=0.2, zoom_range=0.2, horizontal_flip=True)
img = load_img(example_pic)
x = img_to_array(img) / 255.0
x = x.reshape((1,) + x.shape)
plt.figure(figsize=(20, 10))
plt.suptitle('Data augmentation', fontsize=28)
i = 0
for batch in datagen.flow(x, batch_size=1):
    plt.subplot(3, 5, i + 1)
    plt.grid(False)
    plt.imshow(batch.reshape(218, 178, 3))
    if i == 9:
        break
    i = i + 1
plt.show()