text_plain_output_1.png
from sklearn.model_selection import train_test_split

from tensorflow.keras.layers import Dense, Conv2D, Flatten, MaxPooling2D, Dropout

from tensorflow.keras.models import Sequential

from tensorflow.keras.preprocessing.image import load_img, img_to_array

from tensorflow.keras.utils import to_categorical

import numpy as np

import pandas as pd

data = pd.read_csv('../input/hardfakevsrealfaces/data.csv')

height, width = (128, 128)
X = np.empty((data.shape[0], height, width, 3))
for i in range(data.shape[0]):
    img = load_img('../input/hardfakevsrealfaces/{}/{}.jpg'.format(data.loc[i, 'label'], data.loc[i, 'images_id']), target_size=(height, width))
    X[i] = img_to_array(img)
X.shape

def changeLabels(x):
    return labels[x]
labels = data.label.unique()
labels = {labels[i]: i for i in range(labels.size)}
y = data.label.apply(changeLabels)
y[:5]

y = to_categorical(y, len(labels))
y = y.astype(int)
y[:5]

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=8)
(X_train.shape, y_train.shape)

model = Sequential()
model.add(Conv2D(64, kernel_size=3, activation='relu', input_shape=(height, width, 3)))
model.add(MaxPooling2D(pool_size=(3, 3)))
model.add(Conv2D(32, kernel_size=3, activation='relu'))
model.add(MaxPooling2D(pool_size=(3, 3)))
model.add(Conv2D(32, kernel_size=3, activation='relu'))
model.add(MaxPooling2D(pool_size=(3, 3)))
model.add(Flatten())
model.add(Dense(64, activation='relu'))
model.add(Dropout(0.45))
model.add(Dense(2, activation='softmax'))

epochs = 8
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
stats = model.fit(X_train, y_train, epochs=epochs, validation_split=0.2)
model.summary()