{"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":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_cell_guid":"53387de2-ef1a-420f-8698-54be9ea50841","_uuid":"c7837c53-e3f0-48fd-a690-7e66f33cc1b9","jupyter":{"outputs_hidden":false},"collapsed":false,"execution":{"iopub.status.busy":"2021-11-27T05:16:43.177617Z","iopub.execute_input":"2021-11-27T05:16:43.17823Z","iopub.status.idle":"2021-11-27T05:16:43.211325Z","shell.execute_reply.started":"2021-11-27T05:16:43.178137Z","shell.execute_reply":"2021-11-27T05:16:43.210594Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Required Libraries\nimport cv2, zipfile, os, pydot, numpy as np\nfrom keras import layers\nfrom tensorflow.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 tensorflow.keras.optimizers import Adam\nfrom keras.callbacks import ReduceLROnPlateau\nfrom keras.callbacks import ModelCheckpoint, Callback, EarlyStopping\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 \nfrom IPython.display import SVG\nfrom keras.utils.vis_utils import model_to_dot\nfrom tensorflow.keras.utils import plot_model\nfrom tensorflow.keras.utils import to_categorical\nfrom sklearn.model_selection import train_test_split\nimport matplotlib.pyplot as plt \nfrom random import shuffle\nnp.set_printoptions(suppress=True)\nimport warnings\nwarnings.filterwarnings('ignore')","metadata":{"_cell_guid":"0574a1ee-5498-4999-aebf-34e4ee8997fa","_uuid":"9a75dc75-00d8-4adf-be0e-f4c51680b01f","jupyter":{"outputs_hidden":false},"collapsed":false,"execution":{"iopub.status.busy":"2021-11-27T05:16:43.212945Z","iopub.execute_input":"2021-11-27T05:16:43.213361Z","iopub.status.idle":"2021-11-27T05:16:50.221923Z","shell.execute_reply.started":"2021-11-27T05:16:43.21331Z","shell.execute_reply":"2021-11-27T05:16:50.220962Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Print all the interactive output\nfrom IPython.core.interactiveshell import InteractiveShell\nInteractiveShell.ast_node_interactivity = \"all\"","metadata":{"_cell_guid":"da07a3e6-2fc0-4b24-ae8d-7caae96a7895","_uuid":"cea7d029-e515-4fb0-aadb-b0980a4e6a69","jupyter":{"outputs_hidden":false},"collapsed":false,"execution":{"iopub.status.busy":"2021-11-27T05:16:50.22358Z","iopub.execute_input":"2021-11-27T05:16:50.223883Z","iopub.status.idle":"2021-11-27T05:16:50.22872Z","shell.execute_reply.started":"2021-11-27T05:16:50.223843Z","shell.execute_reply":"2021-11-27T05:16:50.227802Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\n# Extract Train and Test Zip Files\n\nwith zipfile.ZipFile('/kaggle/input/dogs-vs-cats-redux-kernels-edition/test.zip','r') as z:\n    z.extractall('.')\n    \nwith zipfile.ZipFile('/kaggle/input/dogs-vs-cats-redux-kernels-edition/train.zip','r') as z:\n    z.extractall('.')","metadata":{"_cell_guid":"48a41172-24da-4cd5-bbc7-f79b6377b6d5","_uuid":"557c4f65-4ada-4ead-aebe-8cb4c41d26fa","jupyter":{"outputs_hidden":false},"collapsed":false,"execution":{"iopub.status.busy":"2021-11-27T05:16:50.231335Z","iopub.execute_input":"2021-11-27T05:16:50.231692Z","iopub.status.idle":"2021-11-27T05:17:09.720634Z","shell.execute_reply.started":"2021-11-27T05:16:50.23165Z","shell.execute_reply":"2021-11-27T05:17:09.719614Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\n#Image re-sizing for training the model faster\n\nIMG_SIZE = 60\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":{"_cell_guid":"a314f24b-585a-41aa-a871-cef6ffa758c6","_uuid":"4f31acc7-a51b-4f71-b95f-02e88fbfdb5c","jupyter":{"outputs_hidden":false},"collapsed":false,"execution":{"iopub.status.busy":"2021-11-27T05:17:09.721814Z","iopub.execute_input":"2021-11-27T05:17:09.722273Z","iopub.status.idle":"2021-11-27T05:18:06.080237Z","shell.execute_reply.started":"2021-11-27T05:17:09.722238Z","shell.execute_reply":"2021-11-27T05:18:06.079374Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# \nshuffle(X_Train_orig)\nX = 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])\n\nprint(X.shape)\nprint(Y.shape)","metadata":{"_cell_guid":"4367f009-9ccb-45f4-8e05-c4a5ee85e7c2","_uuid":"19699374-e102-4045-84e2-247e8bfa3cab","jupyter":{"outputs_hidden":false},"collapsed":false,"execution":{"iopub.status.busy":"2021-11-27T05:18:06.081458Z","iopub.execute_input":"2021-11-27T05:18:06.08173Z","iopub.status.idle":"2021-11-27T05:18:06.270023Z","shell.execute_reply.started":"2021-11-27T05:18:06.081699Z","shell.execute_reply":"2021-11-27T05:18:06.269164Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#\nX_train, X_val, Y_train, Y_val = train_test_split(X, Y, test_size = 0.8, stratify=Y, random_state=43)\nprint('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":{"_cell_guid":"38610fd6-c38d-4cb4-9be2-10810ab24a7c","_uuid":"44458cb3-f3cf-4c5e-bfff-77eb74847656","jupyter":{"outputs_hidden":false},"collapsed":false,"execution":{"iopub.status.busy":"2021-11-27T05:18:06.271554Z","iopub.execute_input":"2021-11-27T05:18:06.272028Z","iopub.status.idle":"2021-11-27T05:18:06.414057Z","shell.execute_reply.started":"2021-11-27T05:18:06.271985Z","shell.execute_reply":"2021-11-27T05:18:06.413197Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#\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') \npass;","metadata":{"_cell_guid":"051931e4-bd72-466d-a26a-e3394137af0b","_uuid":"c1c01cee-9837-4246-9df0-2e9abf5b22f5","jupyter":{"outputs_hidden":false},"collapsed":false,"execution":{"iopub.status.busy":"2021-11-27T05:18:06.415488Z","iopub.execute_input":"2021-11-27T05:18:06.415753Z","iopub.status.idle":"2021-11-27T05:18:09.319159Z","shell.execute_reply.started":"2021-11-27T05:18:06.415723Z","shell.execute_reply":"2021-11-27T05:18:09.318431Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#\ndef 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, (3, 3), 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, (3, 3), 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, (3, 3), 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((3, 3), 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":{"_cell_guid":"4b13abc5-329b-4593-ae9e-7a5a963c43b5","_uuid":"35a98bd5-5415-4381-a751-a10774a97721","jupyter":{"outputs_hidden":false},"collapsed":false,"execution":{"iopub.status.busy":"2021-11-27T05:18:09.320318Z","iopub.execute_input":"2021-11-27T05:18:09.320719Z","iopub.status.idle":"2021-11-27T05:18:09.332979Z","shell.execute_reply.started":"2021-11-27T05:18:09.320673Z","shell.execute_reply":"2021-11-27T05:18:09.331976Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#\nKeras_Model = Keras_Model(X_train.shape[1:4])\n\nepochs = 100\nbatch_size = 64\nlrate = 0.001\ndecay = lrate/epochs\noptimizer = Adam(lr=lrate, epsilon=1e-08, decay = decay)\n\nKeras_Model.compile(loss='binary_crossentropy', optimizer=optimizer, metrics=['accuracy'])\n\nlearning_rate_reduction = ReduceLROnPlateau(monitor='val_acc', \n                                            patience=1, \n                                            verbose=1, \n                                            factor=0.5, \n                                            min_lr=0.0000001)\n\nearly_stopping = EarlyStopping(monitor='val_loss', patience=3, verbose=1, mode='auto')\n\npass;","metadata":{"_cell_guid":"78068852-4924-4541-acb5-14c699a38f2d","_uuid":"b1aee360-8c94-4820-86e9-709f70bb6f18","jupyter":{"outputs_hidden":false},"collapsed":false,"execution":{"iopub.status.busy":"2021-11-27T05:18:09.335883Z","iopub.execute_input":"2021-11-27T05:18:09.336163Z","iopub.status.idle":"2021-11-27T05:18:10.340207Z","shell.execute_reply.started":"2021-11-27T05:18:09.336133Z","shell.execute_reply":"2021-11-27T05:18:10.339578Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\n#\nhistory = 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] )\npass;","metadata":{"_cell_guid":"2ae17a6e-8237-45d2-a063-f517cdb43743","_uuid":"21c870f0-0994-447f-a2a0-5a814ea18f7d","jupyter":{"outputs_hidden":false},"collapsed":false,"execution":{"iopub.status.busy":"2021-11-27T05:18:10.341216Z","iopub.execute_input":"2021-11-27T05:18:10.341944Z","iopub.status.idle":"2021-11-27T05:22:27.209356Z","shell.execute_reply.started":"2021-11-27T05:18:10.341909Z","shell.execute_reply":"2021-11-27T05:22:27.208444Z"},"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":{"_cell_guid":"58f8b14a-20b0-429b-b360-0761cd8e24a0","_uuid":"05492b0d-1920-4460-9894-ec579c02a220","jupyter":{"outputs_hidden":false},"collapsed":false,"execution":{"iopub.status.busy":"2021-11-27T05:22:27.210692Z","iopub.execute_input":"2021-11-27T05:22:27.210952Z","iopub.status.idle":"2021-11-27T05:22:30.273669Z","shell.execute_reply.started":"2021-11-27T05:22:27.210921Z","shell.execute_reply":"2021-11-27T05:22:30.272427Z"},"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":{"_cell_guid":"6b627134-9578-4a5a-a141-a607b0acc216","_uuid":"3e73ba45-0a47-4302-9cf0-90e38676c3d7","jupyter":{"outputs_hidden":false},"collapsed":false,"execution":{"iopub.status.busy":"2021-11-27T05:22:30.274816Z","iopub.status.idle":"2021-11-27T05:22:30.275142Z","shell.execute_reply.started":"2021-11-27T05:22:30.274967Z","shell.execute_reply":"2021-11-27T05:22:30.274983Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history_dict = history.history\nhistory_dict.keys()","metadata":{"_cell_guid":"0efe2d00-f18e-45c5-aede-33307951a540","_uuid":"71797cbf-7aca-4501-a475-bb58cbfce935","jupyter":{"outputs_hidden":false},"collapsed":false,"execution":{"iopub.status.busy":"2021-11-27T05:22:30.276566Z","iopub.status.idle":"2021-11-27T05:22:30.276881Z","shell.execute_reply.started":"2021-11-27T05:22:30.276722Z","shell.execute_reply":"2021-11-27T05:22:30.276738Z"},"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":{"_cell_guid":"bb8c9ea0-b31f-4680-be8c-94520c59d9c3","_uuid":"4511ff85-8052-4117-8a01-0d610add3db9","jupyter":{"outputs_hidden":false},"collapsed":false,"execution":{"iopub.status.busy":"2021-11-27T05:22:30.277897Z","iopub.status.idle":"2021-11-27T05:22:30.278202Z","shell.execute_reply.started":"2021-11-27T05:22:30.278044Z","shell.execute_reply":"2021-11-27T05:22:30.278061Z"},"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()\n\npass;","metadata":{"_cell_guid":"5b80b307-5cd7-406b-888b-26676ae68d39","_uuid":"7c0d945d-fc43-49be-8979-bb5548ebcc00","jupyter":{"outputs_hidden":false},"collapsed":false,"execution":{"iopub.status.busy":"2021-11-27T05:22:30.279232Z","iopub.status.idle":"2021-11-27T05:22:30.279561Z","shell.execute_reply.started":"2021-11-27T05:22:30.279373Z","shell.execute_reply":"2021-11-27T05:22:30.279388Z"},"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()\n\npass;","metadata":{"_cell_guid":"369a9be2-e8ab-4477-aec6-5646e4bedf64","_uuid":"ca0d447d-ef0a-4f17-931d-cf2c74cc9f68","jupyter":{"outputs_hidden":false},"collapsed":false,"execution":{"iopub.status.busy":"2021-11-27T05:22:30.280459Z","iopub.status.idle":"2021-11-27T05:22:30.280798Z","shell.execute_reply.started":"2021-11-27T05:22:30.280639Z","shell.execute_reply":"2021-11-27T05:22:30.280656Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predicted_val_probability = Keras_Model.predict(X_val, batch_size=64)\n\nY_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":{"_cell_guid":"f7021cf7-bc89-4f3c-b314-252556fe8352","_uuid":"6eb17968-0399-4adb-8c39-d0f48fe7515e","jupyter":{"outputs_hidden":false},"collapsed":false,"execution":{"iopub.status.busy":"2021-11-27T05:22:30.281726Z","iopub.status.idle":"2021-11-27T05:22:30.282019Z","shell.execute_reply.started":"2021-11-27T05:22:30.281866Z","shell.execute_reply":"2021-11-27T05:22:30.281881Z"},"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)","metadata":{"_cell_guid":"8f78e09e-16a9-4855-975a-d5c2a22b9792","_uuid":"839a4a79-4d93-4bb3-aaad-fb573a01acfe","jupyter":{"outputs_hidden":false},"collapsed":false,"execution":{"iopub.status.busy":"2021-11-27T05:22:30.282928Z","iopub.status.idle":"2021-11-27T05:22:30.283225Z","shell.execute_reply.started":"2021-11-27T05:22:30.283071Z","shell.execute_reply":"2021-11-27T05:22:30.283087Z"},"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,3,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\npass;","metadata":{"_cell_guid":"2345426a-181e-4c52-9f30-1f9ddf5b9d31","_uuid":"b1732567-314a-4ff9-888c-1d3fbedeebef","jupyter":{"outputs_hidden":false},"collapsed":false,"execution":{"iopub.status.busy":"2021-11-27T05:22:30.284121Z","iopub.status.idle":"2021-11-27T05:22:30.284412Z","shell.execute_reply.started":"2021-11-27T05:22:30.284257Z","shell.execute_reply":"2021-11-27T05:22:30.284272Z"},"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":{"_cell_guid":"28d3c629-5f55-4e3f-816d-64dccf683723","_uuid":"3b81471b-053a-450c-88a6-5885cb556fd1","jupyter":{"outputs_hidden":false},"collapsed":false,"execution":{"iopub.status.busy":"2021-11-27T05:22:30.285922Z","iopub.status.idle":"2021-11-27T05:22:30.286244Z","shell.execute_reply.started":"2021-11-27T05:22:30.286073Z","shell.execute_reply":"2021-11-27T05:22:30.286095Z"},"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":{"_cell_guid":"394259b3-11f7-4385-b39a-8724dce9de1a","_uuid":"cbadb95c-445a-4831-8016-e39d4be50eb2","jupyter":{"outputs_hidden":false},"collapsed":false,"execution":{"iopub.status.busy":"2021-11-27T05:22:30.288309Z","iopub.status.idle":"2021-11-27T05:22:30.289122Z","shell.execute_reply.started":"2021-11-27T05:22:30.288908Z","shell.execute_reply":"2021-11-27T05:22:30.288936Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"classes = Keras_Model.predict(X_test, batch_size = batch_size)\nprediction = pd.DataFrame()\nprediction['id'] = Label\nprediction['label'] = classes\n\nprediction.to_csv('submission.csv', index = False)","metadata":{"_cell_guid":"815fb6fe-d77e-4a93-9aaa-476dc2ecc61d","_uuid":"1b6e6cc8-5b52-47e7-b81d-9ba56c7d189f","jupyter":{"outputs_hidden":false},"collapsed":false,"execution":{"iopub.status.busy":"2021-11-27T05:22:30.289902Z","iopub.status.idle":"2021-11-27T05:22:30.290472Z","shell.execute_reply.started":"2021-11-27T05:22:30.29026Z","shell.execute_reply":"2021-11-27T05:22:30.290286Z"},"trusted":true},"execution_count":null,"outputs":[]}]}