{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n\nimport os\nprint(os.listdir(\"../input\"))","metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","execution":{"iopub.status.busy":"2021-11-28T03:48:42.410335Z","iopub.execute_input":"2021-11-28T03:48:42.410707Z","iopub.status.idle":"2021-11-28T03:48:42.435149Z","shell.execute_reply.started":"2021-11-28T03:48:42.410619Z","shell.execute_reply":"2021-11-28T03:48:42.434487Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2\nfrom keras import layers\nfrom keras.layers import Input, Dense, Activation, ZeroPadding2D, BatchNormalization, Flatten, Conv2D\nfrom keras.layers import AveragePooling2D, MaxPooling2D, Dropout, GlobalMaxPooling2D, GlobalAveragePooling2D\nfrom keras.models import Model\nfrom keras.preprocessing import image\nfrom keras.utils import layer_utils\nfrom keras.utils.data_utils import get_file\nfrom keras.applications.imagenet_utils import preprocess_input\nimport pydot\nfrom IPython.display import SVG\nfrom keras.utils.vis_utils import model_to_dot\nfrom keras.utils.vis_utils import plot_model\nfrom tensorflow.keras.utils import to_categorical\nimport matplotlib.pyplot as plt \nfrom random import shuffle\nnp.set_printoptions(suppress=True)\n#np.set_printoptions(threshold=np.inf)","metadata":{"_uuid":"915ddeac4d7cc8a1523cf8261e8b9130bab38f4a","execution":{"iopub.status.busy":"2021-11-28T03:48:50.269039Z","iopub.execute_input":"2021-11-28T03:48:50.269592Z","iopub.status.idle":"2021-11-28T03:48:56.200845Z","shell.execute_reply.started":"2021-11-28T03:48:50.269552Z","shell.execute_reply":"2021-11-28T03:48:56.199974Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import zipfile\n\nwith zipfile.ZipFile('../input/dogs-vs-cats-redux-kernels-edition/test.zip','r') as z:\n    z.extractall('.')\n    \nwith zipfile.ZipFile('../input/dogs-vs-cats-redux-kernels-edition/train.zip','r') as z:\n    z.extractall('.')\n","metadata":{"execution":{"iopub.status.busy":"2021-11-28T03:48:59.820806Z","iopub.execute_input":"2021-11-28T03:48:59.821489Z","iopub.status.idle":"2021-11-28T03:49:21.656189Z","shell.execute_reply.started":"2021-11-28T03:48:59.821447Z","shell.execute_reply":"2021-11-28T03:49:21.655311Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"IMG_SIZE = 40\nX_Train_orig = []\nY_Train_orig = []\nfor i in os.listdir('/kaggle/working/train/'):\n    label = i.split('.')[-3]\n    if label == 'cat':\n        label = 0\n    elif label == 'dog':\n        label = 1\n    img = cv2.imread('/kaggle/working/train/'+i, cv2.IMREAD_COLOR)\n    img = cv2.resize(img,(IMG_SIZE,IMG_SIZE), interpolation=cv2.INTER_CUBIC)\n    #img = img / 255\n    X_Train_orig.append([np.array(img), np.array(label)])\n\nnp.save('Training_Data.npy', X_Train_orig)","metadata":{"_uuid":"f3b68753e0732708180d300fada74ce3f4d374aa","execution":{"iopub.status.busy":"2021-11-28T03:49:34.243464Z","iopub.execute_input":"2021-11-28T03:49:34.243758Z","iopub.status.idle":"2021-11-28T03:50:29.227811Z","shell.execute_reply.started":"2021-11-28T03:49:34.243728Z","shell.execute_reply":"2021-11-28T03:50:29.226996Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"shuffle(X_Train_orig)","metadata":{"_uuid":"57117442faa3e8505d8352914056eefe18818d91","execution":{"iopub.status.busy":"2021-11-28T03:50:33.82072Z","iopub.execute_input":"2021-11-28T03:50:33.821046Z","iopub.status.idle":"2021-11-28T03:50:33.855033Z","shell.execute_reply.started":"2021-11-28T03:50:33.820994Z","shell.execute_reply":"2021-11-28T03:50:33.854144Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = np.array([i[0] for i in X_Train_orig]).reshape(-1,IMG_SIZE,IMG_SIZE,3)\nY = np.array([i[1] for i in X_Train_orig])","metadata":{"_uuid":"252c1bdc4906c04df7181e5df23e61c47f4cce96","execution":{"iopub.status.busy":"2021-11-28T03:50:35.370802Z","iopub.execute_input":"2021-11-28T03:50:35.371097Z","iopub.status.idle":"2021-11-28T03:50:35.48175Z","shell.execute_reply.started":"2021-11-28T03:50:35.371063Z","shell.execute_reply":"2021-11-28T03:50:35.48081Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(X)","metadata":{"execution":{"iopub.status.busy":"2021-11-28T03:50:45.78649Z","iopub.execute_input":"2021-11-28T03:50:45.786807Z","iopub.status.idle":"2021-11-28T03:50:45.796537Z","shell.execute_reply.started":"2021-11-28T03:50:45.786769Z","shell.execute_reply":"2021-11-28T03:50:45.795662Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(Y)","metadata":{"execution":{"iopub.status.busy":"2021-11-27T17:17:53.017441Z","iopub.execute_input":"2021-11-27T17:17:53.017806Z","iopub.status.idle":"2021-11-27T17:17:53.028519Z","shell.execute_reply.started":"2021-11-27T17:17:53.017758Z","shell.execute_reply":"2021-11-27T17:17:53.027819Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X.shape","metadata":{"execution":{"iopub.status.busy":"2021-11-28T03:50:53.434776Z","iopub.execute_input":"2021-11-28T03:50:53.435394Z","iopub.status.idle":"2021-11-28T03:50:53.444929Z","shell.execute_reply.started":"2021-11-28T03:50:53.435339Z","shell.execute_reply":"2021-11-28T03:50:53.443685Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Y.shape","metadata":{"execution":{"iopub.status.busy":"2021-11-28T03:50:55.498289Z","iopub.execute_input":"2021-11-28T03:50:55.498609Z","iopub.status.idle":"2021-11-28T03:50:55.504593Z","shell.execute_reply.started":"2021-11-28T03:50:55.498573Z","shell.execute_reply":"2021-11-28T03:50:55.503762Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nX_train, X_val, Y_train, Y_val = train_test_split(X, Y, test_size = 0.9, stratify=Y)","metadata":{"_uuid":"d91fb23ee9689f792adb9973bd483ae3c6bc0faf","execution":{"iopub.status.busy":"2021-11-28T03:50:57.393381Z","iopub.execute_input":"2021-11-28T03:50:57.393826Z","iopub.status.idle":"2021-11-28T03:50:58.179719Z","shell.execute_reply.started":"2021-11-28T03:50:57.393796Z","shell.execute_reply":"2021-11-28T03:50:58.178885Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Shape of X_train is :', X_train.shape)\nprint('Shape of Y_train is :', Y_train.shape)\nprint('Shape of X_val is :', X_val.shape)\nprint('Shape of Y_val is :', Y_val.shape)","metadata":{"_uuid":"3650249df7955cab4983d03f4252a02489409185","execution":{"iopub.status.busy":"2021-11-28T03:50:59.093244Z","iopub.execute_input":"2021-11-28T03:50:59.093592Z","iopub.status.idle":"2021-11-28T03:50:59.10125Z","shell.execute_reply.started":"2021-11-28T03:50:59.093554Z","shell.execute_reply":"2021-11-28T03:50:59.100245Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(pd.Series(Y_train).value_counts(1))\nprint(pd.Series(Y_val).value_counts(1))","metadata":{"execution":{"iopub.status.busy":"2021-11-28T03:51:00.672988Z","iopub.execute_input":"2021-11-28T03:51:00.673296Z","iopub.status.idle":"2021-11-28T03:51:00.690028Z","shell.execute_reply.started":"2021-11-28T03:51:00.673267Z","shell.execute_reply":"2021-11-28T03:51:00.689102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_val, Y_train, Y_val = train_test_split(X_train, Y_train, test_size = 0.20, stratify=Y_train)","metadata":{"execution":{"iopub.status.busy":"2021-11-28T03:51:02.788671Z","iopub.execute_input":"2021-11-28T03:51:02.789606Z","iopub.status.idle":"2021-11-28T03:51:02.80473Z","shell.execute_reply.started":"2021-11-28T03:51:02.789556Z","shell.execute_reply":"2021-11-28T03:51:02.803587Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Shape of X_train is :', X_train.shape)\nprint('Shape of Y_train is :', Y_train.shape)\nprint('Shape of X_val is :', X_val.shape)\nprint('Shape of Y_val is :', Y_val.shape)","metadata":{"execution":{"iopub.status.busy":"2021-11-28T03:51:04.612706Z","iopub.execute_input":"2021-11-28T03:51:04.613314Z","iopub.status.idle":"2021-11-28T03:51:04.619101Z","shell.execute_reply.started":"2021-11-28T03:51:04.613255Z","shell.execute_reply":"2021-11-28T03:51:04.61847Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(pd.Series(Y_train).value_counts(1))\nprint(pd.Series(Y_val).value_counts(1))","metadata":{"execution":{"iopub.status.busy":"2021-11-28T03:51:06.265772Z","iopub.execute_input":"2021-11-28T03:51:06.266081Z","iopub.status.idle":"2021-11-28T03:51:06.275032Z","shell.execute_reply.started":"2021-11-28T03:51:06.266043Z","shell.execute_reply":"2021-11-28T03:51:06.274263Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt \nplt.figure(figsize=(20,20))   # to fix a shape for each image print\nfor i in range(50):          # using a for loop to display a number of images\n    plt.subplot(5, 10, i+1) # we need to use this function to print an array of pictures \n    plt.imshow(X_val[i,:,:,:]) # this will call the images from train set one by one\n    plt.title('DOG' if Y_val[i] == 1 else 'CAT')  # Lets also look into the labels \n    plt.axis('off') ","metadata":{"_uuid":"2ba6838f1f1e4b7e33c9e35c7807ce128094015b","execution":{"iopub.status.busy":"2021-11-28T03:51:08.171844Z","iopub.execute_input":"2021-11-28T03:51:08.172406Z","iopub.status.idle":"2021-11-28T03:51:11.09066Z","shell.execute_reply.started":"2021-11-28T03:51:08.172369Z","shell.execute_reply":"2021-11-28T03:51:11.089982Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def Keras_Model(input_shape):    \n    \n    X_input = Input(input_shape)\n    \n    # First Layer\n    X = Conv2D(64, (3, 3), strides = (1, 1), padding = 'same', name = 'conv0')(X_input) \n    X = BatchNormalization(axis = 3, name = 'bn0')(X)\n    X = Activation('relu')(X) \n    \n    X = Conv2D(64, (3, 3), strides = (1, 1), padding = 'same', name = 'conv1')(X) \n    X = BatchNormalization(axis = 3, name = 'bn1')(X)\n    X = Activation('relu')(X)\n    \n    X = MaxPooling2D((3, 3), name='max_pool_0')(X)\n    X = Dropout(0.3)(X)\n    \n     # Second Layer\n    X = Conv2D(128, (3, 3), strides = (1, 1), padding = 'same', name = 'conv3')(X) \n    X = BatchNormalization(axis = 3, name = 'bn3')(X)\n    X = Activation('relu')(X)\n    \n    X = Conv2D(128, (3, 3), strides = (1, 1), padding = 'same', name = 'conv4')(X) \n    X = BatchNormalization(axis = 3, name = 'bn4')(X)\n    X = Activation('relu')(X)\n    \n    X = Conv2D(128, (3, 3), strides = (1, 1), padding = 'same', name = 'conv5')(X) \n    X = BatchNormalization(axis = 3, name = 'bn5')(X)\n    X = Activation('relu')(X)\n     \n    X = MaxPooling2D((3,3 ), name='max_pool_1')(X)\n    X = Dropout(0.3)(X)\n    \n#     # Third Convolutional Layer\n    X = Conv2D(256, (3, 3), strides = (1, 1), padding = 'same', name = 'conv6')(X) \n    X = BatchNormalization(axis = 3, name = 'bn6')(X)\n    X = Activation('relu')(X)\n    \n    X = Conv2D(256, (3, 3), strides = (1, 1), padding = 'same', name = 'conv7')(X) \n    X = BatchNormalization(axis = 3, name = 'bn7')(X)\n    X = Activation('relu')(X)\n    \n    X = Conv2D(256, (3, 3), strides = (1, 1), padding = 'same', name = 'conv8')(X) \n    X = BatchNormalization(axis = 3, name = 'bn8')(X)\n    X = Activation('relu')(X)\n\n \n    X = MaxPooling2D((3, 3), name='max_pool_2')(X)\n    X = Dropout(0.3)(X)\n    \n    #X = Conv2D(512, (4, 4), strides = (1, 1), padding = 'same', name = 'conv10')(X) \n    #X = BatchNormalization(axis = 3, name = 'bn10')(X)\n    #X = Activation('relu')(X)\n    \n    #X = Conv2D(512, (4, 4), strides = (1, 1), padding = 'same', name = 'conv11')(X) \n    #X = BatchNormalization(axis = 3, name = 'bn11')(X)\n    #X = Activation('relu')(X)\n    \n    #X = Conv2D(512, (4, 4), strides = (1, 1), padding = 'same', name = 'conv12')(X) \n    #X = BatchNormalization(axis = 3, name = 'bn12')(X)\n    #X = Activation('relu')(X)\n\n    \n    #X = MaxPooling2D((4, 4), name='max_pool_3')(X)\n    #X = Dropout(0.3)(X)\n    \n    # Flatten the data.\n    X = Flatten()(X)\n    # Dense Layer\n    X = Dense(4096, activation='relu', name='fc1')(X)\n    X = Dropout(0.5)(X)\n    X = Dense(1024, activation='relu', name='fc2')(X)\n    X = Dropout(0.5)(X)\n    X = Dense(256, activation='relu', name='fc3')(X)\n    # Using softmax function to get the output\n    X = Dense(1, activation='sigmoid', name='fc4')(X)\n    \n    model = Model(inputs = X_input, outputs = X, name='model')\n    \n    return model","metadata":{"_uuid":"130838688d5b7e0cb66e3e6936f9a7042f62a2d3","execution":{"iopub.status.busy":"2021-11-28T04:13:54.735229Z","iopub.execute_input":"2021-11-28T04:13:54.735797Z","iopub.status.idle":"2021-11-28T04:13:54.755132Z","shell.execute_reply.started":"2021-11-28T04:13:54.73576Z","shell.execute_reply":"2021-11-28T04:13:54.754432Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Keras_Model = Keras_Model(X_train.shape[1:4])","metadata":{"_uuid":"f8ca985f73d74c07d9b9b7c8f3b73b4f41643f93","execution":{"iopub.status.busy":"2021-11-28T04:15:52.125069Z","iopub.execute_input":"2021-11-28T04:15:52.125416Z","iopub.status.idle":"2021-11-28T04:15:52.364532Z","shell.execute_reply.started":"2021-11-28T04:15:52.125378Z","shell.execute_reply":"2021-11-28T04:15:52.363865Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.optimizers import Adam\nepochs = 100\nbatch_size = 64\nlrate = 0.001\ndecay = lrate/epochs\noptimizer = Adam(learning_rate=lrate, epsilon=1e-08, decay = decay)","metadata":{"_uuid":"3738ac4a4e7b8fb7dd2ad230c9f733237203aaac","execution":{"iopub.status.busy":"2021-11-28T04:15:56.919074Z","iopub.execute_input":"2021-11-28T04:15:56.919721Z","iopub.status.idle":"2021-11-28T04:15:56.925001Z","shell.execute_reply.started":"2021-11-28T04:15:56.919682Z","shell.execute_reply":"2021-11-28T04:15:56.924417Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Keras_Model.compile(loss='binary_crossentropy', optimizer=optimizer, metrics=['accuracy'])","metadata":{"_uuid":"2c7e680adbf89ea985de03ba05ebaebaaa5b077a","execution":{"iopub.status.busy":"2021-11-28T04:15:59.759458Z","iopub.execute_input":"2021-11-28T04:15:59.760487Z","iopub.status.idle":"2021-11-28T04:15:59.772224Z","shell.execute_reply.started":"2021-11-28T04:15:59.760429Z","shell.execute_reply":"2021-11-28T04:15:59.771311Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.callbacks import ReduceLROnPlateau\nlearning_rate_reduction = ReduceLROnPlateau(monitor='val_acc', \n                                            patience=1, \n                                            verbose=1, \n                                            factor=0.5, \n                                            min_lr=0.0000001)","metadata":{"_uuid":"8ed853eff65ed21eb0cc72eb46933d830b4d192a","execution":{"iopub.status.busy":"2021-11-28T04:16:10.965214Z","iopub.execute_input":"2021-11-28T04:16:10.965639Z","iopub.status.idle":"2021-11-28T04:16:10.970319Z","shell.execute_reply.started":"2021-11-28T04:16:10.965608Z","shell.execute_reply":"2021-11-28T04:16:10.969434Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.callbacks import ModelCheckpoint, Callback, EarlyStopping\nearly_stopping = EarlyStopping(monitor='val_loss', patience=3, verbose=1, mode='auto')","metadata":{"_uuid":"8a59c0ba29efd8d758aa122222f4787b711e0800","execution":{"iopub.status.busy":"2021-11-28T04:16:12.369408Z","iopub.execute_input":"2021-11-28T04:16:12.369688Z","iopub.status.idle":"2021-11-28T04:16:12.374187Z","shell.execute_reply.started":"2021-11-28T04:16:12.369659Z","shell.execute_reply":"2021-11-28T04:16:12.373246Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history = Keras_Model.fit(x = X_train, y = Y_train, batch_size = batch_size, \n                        epochs=epochs, verbose=1, \n                        validation_data = (X_val, Y_val),\n                          shuffle = True, \n                          steps_per_epoch= None, validation_steps=None,\n                                  callbacks=[learning_rate_reduction, early_stopping] )","metadata":{"_uuid":"33d59bcc39c4a474f1696555e6f82101727eeb0c","execution":{"iopub.status.busy":"2021-11-28T04:16:16.799966Z","iopub.execute_input":"2021-11-28T04:16:16.800293Z","iopub.status.idle":"2021-11-28T04:20:50.094415Z","shell.execute_reply.started":"2021-11-28T04:16:16.800257Z","shell.execute_reply":"2021-11-28T04:20:50.092967Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds = Keras_Model.evaluate(X_train, Y_train)\nprint (\"Loss = \" + str(preds[0]))\nprint (\"Train set Accuracy = \" + str(preds[1]))","metadata":{"_uuid":"459602bc76cc1966a0f017f7ad5a0ac22c05caae","execution":{"iopub.status.busy":"2021-11-28T04:20:50.097988Z","iopub.execute_input":"2021-11-28T04:20:50.098373Z","iopub.status.idle":"2021-11-28T04:20:56.060898Z","shell.execute_reply.started":"2021-11-28T04:20:50.098324Z","shell.execute_reply":"2021-11-28T04:20:56.060257Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds_val = Keras_Model.evaluate(X_val, Y_val)\nprint (\"Loss = \" + str(preds_val[0]))\nprint (\"Validation Set Accuracy = \" + str(preds_val[1]))","metadata":{"_uuid":"c0a25e3afbc805f2bf3fdcba48a671dce68c3544","execution":{"iopub.status.busy":"2021-11-28T04:20:56.06198Z","iopub.execute_input":"2021-11-28T04:20:56.062259Z","iopub.status.idle":"2021-11-28T04:20:57.594992Z","shell.execute_reply.started":"2021-11-28T04:20:56.062227Z","shell.execute_reply":"2021-11-28T04:20:57.594102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history_dict = history.history\nhistory_dict.keys()","metadata":{"_uuid":"3798d66e9c624f98b1f83462d849e8b1b8d73ec1","execution":{"iopub.status.busy":"2021-11-28T04:20:57.59793Z","iopub.execute_input":"2021-11-28T04:20:57.598277Z","iopub.status.idle":"2021-11-28T04:20:57.604442Z","shell.execute_reply.started":"2021-11-28T04:20:57.598231Z","shell.execute_reply":"2021-11-28T04:20:57.603605Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_loss = history_dict['val_loss']\nval_acc = history_dict['val_accuracy']\nloss = history_dict['loss']\nacc = history_dict['accuracy']\nepochs = range(1,len(history_dict['val_loss'])+1)","metadata":{"_uuid":"36f0df8ccfd64876915bb3524ce5ade194e7ba3d","execution":{"iopub.status.busy":"2021-11-28T04:20:57.605901Z","iopub.execute_input":"2021-11-28T04:20:57.606475Z","iopub.status.idle":"2021-11-28T04:20:57.615465Z","shell.execute_reply.started":"2021-11-28T04:20:57.606433Z","shell.execute_reply":"2021-11-28T04:20:57.614872Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(epochs,acc,'b-')\nplt.title('Accuracy of Model')\nplt.xlabel('epochs')\nplt.ylabel('Accuracy')\n\nplt.plot(epochs,val_acc,'b-', color = 'red')\nplt.title('Accuracy of Model')\nplt.xlabel('epochs')\nplt.ylabel('Accuracy')\nplt.show()","metadata":{"_uuid":"391dd25d33d15a17da3ace56d44a91639fbab50b","scrolled":true,"execution":{"iopub.status.busy":"2021-11-28T04:20:57.616843Z","iopub.execute_input":"2021-11-28T04:20:57.617675Z","iopub.status.idle":"2021-11-28T04:20:57.851766Z","shell.execute_reply.started":"2021-11-28T04:20:57.617631Z","shell.execute_reply":"2021-11-28T04:20:57.850845Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(epochs,loss,'b-')\nplt.title('loss function')\nplt.xlabel('epochs')\nplt.ylabel('Loss')\n\nplt.plot(epochs,val_loss,'b-', color = 'red')\nplt.title('loss function')\nplt.xlabel('epochs')\nplt.ylabel('val_loss')\nplt.show()","metadata":{"_uuid":"f617e562701a140372075c8159c31947f3b90bb7","execution":{"iopub.status.busy":"2021-11-28T04:20:57.853862Z","iopub.execute_input":"2021-11-28T04:20:57.854284Z","iopub.status.idle":"2021-11-28T04:20:58.063297Z","shell.execute_reply.started":"2021-11-28T04:20:57.85424Z","shell.execute_reply":"2021-11-28T04:20:58.06222Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predicted_val_probability = Keras_Model.predict(X_val, batch_size=64)","metadata":{"_uuid":"9c1e62b41eca359540b11ad6404a16d8f1784a3d","execution":{"iopub.status.busy":"2021-11-28T04:20:58.064567Z","iopub.execute_input":"2021-11-28T04:20:58.064784Z","iopub.status.idle":"2021-11-28T04:20:59.706042Z","shell.execute_reply.started":"2021-11-28T04:20:58.064758Z","shell.execute_reply":"2021-11-28T04:20:59.70534Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Y_val_pred_label = np.round(predicted_val_probability)\nl = []\nfor i in range(len(Y_val_pred_label)):\n    if Y_val[i] != Y_val_pred_label[i]:\n        l.append(i)","metadata":{"_uuid":"16b5c003ab117486c42bdde80f25c1e41ead387d","execution":{"iopub.status.busy":"2021-11-28T04:20:59.707696Z","iopub.execute_input":"2021-11-28T04:20:59.708139Z","iopub.status.idle":"2021-11-28T04:20:59.715771Z","shell.execute_reply.started":"2021-11-28T04:20:59.708083Z","shell.execute_reply":"2021-11-28T04:20:59.715225Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"m = []\nfor t in l:\n    if predicted_val_probability[t] >= 0.5:\n        m.append(t)\n    elif predicted_val_probability[t] < 0.5:\n        m.append(t)\n    ","metadata":{"_uuid":"420a62d80b6556b910d8d8119173d8e56b3e9b37","execution":{"iopub.status.busy":"2021-11-28T04:20:59.717783Z","iopub.execute_input":"2021-11-28T04:20:59.718108Z","iopub.status.idle":"2021-11-28T04:20:59.728951Z","shell.execute_reply.started":"2021-11-28T04:20:59.718081Z","shell.execute_reply":"2021-11-28T04:20:59.728093Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(m)","metadata":{"_uuid":"f0c136df87aef4f01625808ef79fc6ee25959fa7","execution":{"iopub.status.busy":"2021-11-28T04:20:59.73014Z","iopub.execute_input":"2021-11-28T04:20:59.730366Z","iopub.status.idle":"2021-11-28T04:20:59.741624Z","shell.execute_reply.started":"2021-11-28T04:20:59.730341Z","shell.execute_reply":"2021-11-28T04:20:59.740946Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(35,35))\nc = 1\nfor i in m[:]:\n    plt.subplot(10,6,c)\n    plt.imshow(X_val[i])\n    plt.title('DOG:{}\\nTrue label:{}'.format(predicted_val_probability[i], Y_val[i])\n              if predicted_val_probability[i]>= 0.5 else 'CAT:{}\\nTrue label:{}'.format(predicted_val_probability[i],Y_val[i]))\n    plt.axis('off')\n    c = c+1","metadata":{"_uuid":"e2e6144870ed37a0766ef8005eccef28526c2af6","execution":{"iopub.status.busy":"2021-11-28T04:20:59.743309Z","iopub.execute_input":"2021-11-28T04:20:59.743952Z","iopub.status.idle":"2021-11-28T04:21:04.567442Z","shell.execute_reply.started":"2021-11-28T04:20:59.743903Z","shell.execute_reply":"2021-11-28T04:21:04.566041Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_Test_orig = []\nfor i in os.listdir('/kaggle/working/test/'):\n    label = i.split('.')[-2]\n    img = cv2.imread('/kaggle/working/test/'+i, cv2.IMREAD_COLOR)\n    img = cv2.resize(img,(IMG_SIZE,IMG_SIZE), interpolation = cv2.INTER_CUBIC)\n    #img = img / 255\n    X_Test_orig.append([np.array(img), np.array(label)])\n\nnp.save('Test_Data.npy', X_Train_orig)","metadata":{"_uuid":"c25765553e1db2d44ebcb91fcb7b981a00603be8","execution":{"iopub.status.busy":"2021-11-28T04:21:22.969948Z","iopub.execute_input":"2021-11-28T04:21:22.970865Z","iopub.status.idle":"2021-11-28T04:21:59.09435Z","shell.execute_reply.started":"2021-11-28T04:21:22.970821Z","shell.execute_reply":"2021-11-28T04:21:59.092791Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_test = np.array([i[0] for i in X_Test_orig]).reshape(-1,IMG_SIZE, IMG_SIZE, 3)\nLabel = np.array([i[1] for i in X_Test_orig])","metadata":{"_uuid":"076a820fa95d5987acf8ac655460c2e694e9bfb4","execution":{"iopub.status.busy":"2021-11-28T04:21:59.095917Z","iopub.execute_input":"2021-11-28T04:21:59.09615Z","iopub.status.idle":"2021-11-28T04:21:59.159883Z","shell.execute_reply.started":"2021-11-28T04:21:59.096123Z","shell.execute_reply":"2021-11-28T04:21:59.158919Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_test = X_test / 255","metadata":{"_uuid":"29fb0a8ed8e1de26575c8d1748a10155f104eab8","execution":{"iopub.status.busy":"2021-11-28T04:21:59.161397Z","iopub.execute_input":"2021-11-28T04:21:59.162156Z","iopub.status.idle":"2021-11-28T04:21:59.353353Z","shell.execute_reply.started":"2021-11-28T04:21:59.162111Z","shell.execute_reply":"2021-11-28T04:21:59.352381Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"classes = Keras_Model.predict(X_test, batch_size = batch_size)","metadata":{"_uuid":"eb8b4ac08954ebc942a4f158aae441b5df88c532","execution":{"iopub.status.busy":"2021-11-28T04:21:59.355479Z","iopub.execute_input":"2021-11-28T04:21:59.355888Z","iopub.status.idle":"2021-11-28T04:22:34.130242Z","shell.execute_reply.started":"2021-11-28T04:21:59.355842Z","shell.execute_reply":"2021-11-28T04:22:34.129249Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"prediction = pd.DataFrame()\nprediction['id'] = Label\nprediction['label'] = classes\n\nprediction.to_csv('submission4.csv', index = False)","metadata":{"_uuid":"187383744f503a192f31139351b4280f54379827","execution":{"iopub.status.busy":"2021-11-28T04:22:34.131709Z","iopub.execute_input":"2021-11-28T04:22:34.131972Z","iopub.status.idle":"2021-11-28T04:22:34.18359Z","shell.execute_reply.started":"2021-11-28T04:22:34.131943Z","shell.execute_reply":"2021-11-28T04:22:34.182971Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}