image_output_1.png
from sklearn.model_selection import train_test_split

from tensorflow.keras.layers import Conv2D, MaxPooling2D

from tensorflow.keras.layers import Dense, Dropout, Activation, Flatten

from tensorflow.keras.models import Sequential

import numpy as np

import pandas as pd

import pickle

data = pickle.load(open('../input/dog-and-cat/DOGnCAT50x50.pickle', 'rb'))

X = np.array([e[0] for e in data]).astype('float32')
y = np.array([e[1] for e in data])
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
X_train = np.resize(X_train, (len(X_train), 50, 50, 1))
X_test = np.resize(X_test, (len(X_test), 50, 50, 1))
X_train /= 255.0
X_test /= 255.0

model1 = Sequential()
model1.add(Conv2D(64, kernel_size=(3, 3), input_shape=X_train[0].shape))
model1.add(Activation('relu'))
model1.add(MaxPooling2D(pool_size=(2, 2)))
model1.add(Dropout(0.5))
model1.add(Conv2D(64, kernel_size=(3, 3)))
model1.add(Activation('relu'))
model1.add(MaxPooling2D(pool_size=(2, 2)))
model1.add(Flatten())
model1.add(Dense(64))
model1.add(Activation('relu'))
model1.add(Dropout(0.3))
model1.add(Dense(1))
model1.add(Activation('sigmoid'))
model1.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
history1 = model1.fit(X_train, y_train, batch_size=32, epochs=10, validation_split=0.2)

history_df1 = pd.DataFrame(history1.history)

model2 = Sequential()
model2.add(Conv2D(128, kernel_size=(3, 3), input_shape=X_train[0].shape))
model2.add(Activation('relu'))
model2.add(MaxPooling2D(pool_size=(2, 2)))
model2.add(Dropout(0.5))
model2.add(Conv2D(128, kernel_size=(3, 3)))
model2.add(Activation('relu'))
model2.add(MaxPooling2D(pool_size=(2, 2)))
model2.add(Dropout(0.5))
model2.add(Conv2D(128, kernel_size=(3, 3)))
model2.add(Activation('relu'))
model2.add(MaxPooling2D(pool_size=(2, 2)))
model2.add(Dropout(0.5))
model2.add(Conv2D(128, kernel_size=(3, 3)))
model2.add(Activation('relu'))
model2.add(MaxPooling2D(pool_size=(2, 2)))
model2.add(Flatten())
model2.add(Dense(128))
model2.add(Activation('relu'))
model2.add(Dropout(0.3))
model2.add(Dense(1))
model2.add(Activation('sigmoid'))
model2.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
history2 = model2.fit(X_train, y_train, batch_size=64, epochs=40, validation_split=0.2)

history_df2 = pd.DataFrame(history2.history)
history_df2.loc[:, ['loss', 'val_loss']].plot(title='Loss')
history_df2.loc[:, ['accuracy', 'val_accuracy']].plot(title='Accuracy')