{"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":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-02-14T17:38:15.634892Z","iopub.execute_input":"2022-02-14T17:38:15.635919Z","iopub.status.idle":"2022-02-14T17:38:15.646307Z","shell.execute_reply.started":"2022-02-14T17:38:15.635860Z","shell.execute_reply":"2022-02-14T17:38:15.645098Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Unzipping the Files","metadata":{}},{"cell_type":"code","source":"import zipfile as zp","metadata":{"execution":{"iopub.status.busy":"2022-02-14T17:38:17.138950Z","iopub.execute_input":"2022-02-14T17:38:17.139862Z","iopub.status.idle":"2022-02-14T17:38:17.146832Z","shell.execute_reply.started":"2022-02-14T17:38:17.139810Z","shell.execute_reply":"2022-02-14T17:38:17.145709Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"with zp.ZipFile(\"/kaggle/input/dogs-vs-cats/test1.zip\",\"r\") as z:\n    z.extractall(\".\")\nwith zp.ZipFile(\"/kaggle/input/dogs-vs-cats/train.zip\",\"r\") as z:\n    z.extractall(\".\")","metadata":{"execution":{"iopub.status.busy":"2022-02-14T17:39:11.174708Z","iopub.execute_input":"2022-02-14T17:39:11.175036Z","iopub.status.idle":"2022-02-14T17:39:30.924832Z","shell.execute_reply.started":"2022-02-14T17:39:11.174983Z","shell.execute_reply":"2022-02-14T17:39:30.923931Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Creating Required Directory Structure for ImageDataGenerator","metadata":{}},{"cell_type":"code","source":"os.mkdir(\"/kaggle/working/train/dog\")\nos.mkdir(\"/kaggle/working/train/cat\")\nos.mkdir(\"/kaggle/working/val\")\nos.mkdir(\"/kaggle/working/val/dog\")\nos.mkdir(\"/kaggle/working/val/cat\")\nprint(\"Directories Created\")","metadata":{"execution":{"iopub.status.busy":"2022-02-14T17:40:01.278977Z","iopub.execute_input":"2022-02-14T17:40:01.279304Z","iopub.status.idle":"2022-02-14T17:40:01.287931Z","shell.execute_reply.started":"2022-02-14T17:40:01.279264Z","shell.execute_reply":"2022-02-14T17:40:01.286749Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Moving Training Data to the relevant Directories","metadata":{}},{"cell_type":"code","source":"import shutil\n#shutil.rmtree('/kaggle/working/train')\n#shutil.rmtree('/kaggle/working/test1')","metadata":{"execution":{"iopub.status.busy":"2022-02-14T17:40:04.413029Z","iopub.execute_input":"2022-02-14T17:40:04.413364Z","iopub.status.idle":"2022-02-14T17:40:04.418347Z","shell.execute_reply.started":"2022-02-14T17:40:04.413334Z","shell.execute_reply":"2022-02-14T17:40:04.417183Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path=\"/kaggle/working/train\"\ndog_dest = path +\"/dog\"\ncat_dest = path +\"/cat\"\nfiles = os.listdir(path)\n\nfor file_name in files:\n        if \"dog.\" in file_name:\n            shutil.move(os.path.join(path, file_name),os.path.join(dog_dest,file_name))\n        elif \"cat.\" in file_name:\n            shutil.move(os.path.join(path, file_name),os.path.join(cat_dest,file_name))\n        else:\n            continue\nprint(\"Done Moving!\")","metadata":{"execution":{"iopub.status.busy":"2022-02-14T17:40:06.330020Z","iopub.execute_input":"2022-02-14T17:40:06.330368Z","iopub.status.idle":"2022-02-14T17:40:07.249776Z","shell.execute_reply.started":"2022-02-14T17:40:06.330336Z","shell.execute_reply":"2022-02-14T17:40:07.247901Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.listdir(path)","metadata":{"execution":{"iopub.status.busy":"2022-02-14T17:40:08.904741Z","iopub.execute_input":"2022-02-14T17:40:08.905066Z","iopub.status.idle":"2022-02-14T17:40:08.915585Z","shell.execute_reply.started":"2022-02-14T17:40:08.905001Z","shell.execute_reply":"2022-02-14T17:40:08.914560Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Creating a Random Validation Set","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"import random","metadata":{"execution":{"iopub.status.busy":"2022-02-14T17:40:10.145620Z","iopub.execute_input":"2022-02-14T17:40:10.147928Z","iopub.status.idle":"2022-02-14T17:40:10.152311Z","shell.execute_reply.started":"2022-02-14T17:40:10.147894Z","shell.execute_reply":"2022-02-14T17:40:10.151214Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"source = \"/kaggle/working/train/dog\"\ndest = '/kaggle/working/val/dog'\nfiles = os.listdir(source)\nno_of_files = 1250\nfor file_name in random.sample(files, no_of_files):\n    shutil.move(os.path.join(source, file_name), dest)\nos.listdir(dest)","metadata":{"execution":{"iopub.status.busy":"2022-02-14T17:40:12.726561Z","iopub.execute_input":"2022-02-14T17:40:12.727271Z","iopub.status.idle":"2022-02-14T17:40:12.833213Z","shell.execute_reply.started":"2022-02-14T17:40:12.727213Z","shell.execute_reply":"2022-02-14T17:40:12.832072Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"source = \"/kaggle/working/train/cat\"\ndest = '/kaggle/working/val/cat'\nfiles = os.listdir(source)\nno_of_files = 1250\nfor file_name in random.sample(files, no_of_files):\n    shutil.move(os.path.join(source, file_name), dest)\nos.listdir(dest)","metadata":{"execution":{"iopub.status.busy":"2022-02-14T17:40:15.818694Z","iopub.execute_input":"2022-02-14T17:40:15.819166Z","iopub.status.idle":"2022-02-14T17:40:15.923416Z","shell.execute_reply.started":"2022-02-14T17:40:15.819132Z","shell.execute_reply":"2022-02-14T17:40:15.922399Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Lets Figure out Average Size of the Images so that we can standardize on a normal value","metadata":{}},{"cell_type":"code","source":"from matplotlib.image import imread","metadata":{"execution":{"iopub.status.busy":"2022-02-14T17:40:19.584734Z","iopub.execute_input":"2022-02-14T17:40:19.585132Z","iopub.status.idle":"2022-02-14T17:40:19.590783Z","shell.execute_reply.started":"2022-02-14T17:40:19.585031Z","shell.execute_reply":"2022-02-14T17:40:19.589281Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dim1=[]\ndim2=[]\nfor image_filename in os.listdir(path+'/dog'):\n    img=imread(path+'/dog/'+image_filename)\n    d1,d2,colors=img.shape\n    dim1.append(d1)\n    dim2.append(d2)","metadata":{"execution":{"iopub.status.busy":"2022-02-14T17:40:38.192752Z","iopub.execute_input":"2022-02-14T17:40:38.193091Z","iopub.status.idle":"2022-02-14T17:41:08.317118Z","shell.execute_reply.started":"2022-02-14T17:40:38.193056Z","shell.execute_reply":"2022-02-14T17:41:08.316152Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\nsns.jointplot(dim1,dim2)","metadata":{"execution":{"iopub.status.busy":"2022-02-14T17:41:08.320552Z","iopub.execute_input":"2022-02-14T17:41:08.321603Z","iopub.status.idle":"2022-02-14T17:41:10.286241Z","shell.execute_reply.started":"2022-02-14T17:41:08.321554Z","shell.execute_reply":"2022-02-14T17:41:10.285073Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# We observe that mean size of images are centered between 300 to 400, which is confirmed by the Numpy Mean, thus we take the image shape as 350,350","metadata":{}},{"cell_type":"code","source":"print(np.mean(dim1),np.mean(dim2))","metadata":{"execution":{"iopub.status.busy":"2022-02-14T17:41:18.173221Z","iopub.execute_input":"2022-02-14T17:41:18.173533Z","iopub.status.idle":"2022-02-14T17:41:18.184036Z","shell.execute_reply.started":"2022-02-14T17:41:18.173501Z","shell.execute_reply":"2022-02-14T17:41:18.182940Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# We would be passing these images to our model as GreyScale so the third parameter has been taken as one","metadata":{}},{"cell_type":"code","source":"image_shape=(350,350,1)","metadata":{"execution":{"iopub.status.busy":"2022-02-14T18:24:53.288606Z","iopub.execute_input":"2022-02-14T18:24:53.289314Z","iopub.status.idle":"2022-02-14T18:24:53.294048Z","shell.execute_reply.started":"2022-02-14T18:24:53.289276Z","shell.execute_reply":"2022-02-14T18:24:53.293040Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.preprocessing.image import ImageDataGenerator","metadata":{"execution":{"iopub.status.busy":"2022-02-14T18:24:54.043428Z","iopub.execute_input":"2022-02-14T18:24:54.043944Z","iopub.status.idle":"2022-02-14T18:24:54.049802Z","shell.execute_reply.started":"2022-02-14T18:24:54.043911Z","shell.execute_reply":"2022-02-14T18:24:54.048468Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Initializing ImageDataGenerator","metadata":{}},{"cell_type":"code","source":"image_gen=ImageDataGenerator(rescale=1./255,rotation_range=20,width_shift_range=0.1,\n                            height_shift_range=0.1,shear_range=0.1,\n                             zoom_range=0.1,horizontal_flip=True,\n                             fill_mode='nearest')","metadata":{"execution":{"iopub.status.busy":"2022-02-14T18:24:54.769839Z","iopub.execute_input":"2022-02-14T18:24:54.770658Z","iopub.status.idle":"2022-02-14T18:24:54.776340Z","shell.execute_reply.started":"2022-02-14T18:24:54.770623Z","shell.execute_reply":"2022-02-14T18:24:54.775312Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_gen.flow_from_directory(\"/kaggle/working/train\")","metadata":{"execution":{"iopub.status.busy":"2022-02-14T18:24:55.670114Z","iopub.execute_input":"2022-02-14T18:24:55.670593Z","iopub.status.idle":"2022-02-14T18:24:56.349627Z","shell.execute_reply.started":"2022-02-14T18:24:55.670557Z","shell.execute_reply":"2022-02-14T18:24:56.348581Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_gen.flow_from_directory(\"/kaggle/working/val\")","metadata":{"execution":{"iopub.status.busy":"2022-02-14T18:24:56.560344Z","iopub.execute_input":"2022-02-14T18:24:56.561138Z","iopub.status.idle":"2022-02-14T18:24:56.674254Z","shell.execute_reply.started":"2022-02-14T18:24:56.561101Z","shell.execute_reply":"2022-02-14T18:24:56.673255Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Model Creation Step","metadata":{}},{"cell_type":"code","source":"from tensorflow.keras.models import Sequential","metadata":{"execution":{"iopub.status.busy":"2022-02-14T18:24:57.953587Z","iopub.execute_input":"2022-02-14T18:24:57.954464Z","iopub.status.idle":"2022-02-14T18:24:57.961291Z","shell.execute_reply.started":"2022-02-14T18:24:57.954427Z","shell.execute_reply":"2022-02-14T18:24:57.958470Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.layers import Dense,Conv2D,MaxPool2D,Flatten,Dropout","metadata":{"execution":{"iopub.status.busy":"2022-02-14T18:24:58.593988Z","iopub.execute_input":"2022-02-14T18:24:58.594333Z","iopub.status.idle":"2022-02-14T18:24:58.599467Z","shell.execute_reply.started":"2022-02-14T18:24:58.594303Z","shell.execute_reply":"2022-02-14T18:24:58.598039Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = Sequential()\nmodel.add(Conv2D(filters=32,kernel_size=(3,3),input_shape=image_shape,activation='relu'))\nmodel.add(MaxPool2D(pool_size=(2,2)))\nmodel.add(Conv2D(32,kernel_size=(3,3),activation='relu'))\nmodel.add(MaxPool2D(pool_size=(2,2)))\nmodel.add(Conv2D(filters=64,kernel_size=(3,3),activation='relu'))\nmodel.add(MaxPool2D(pool_size=(2,2)))\n\nmodel.add(Flatten())\n\nmodel.add(Dense(64,activation='relu'))\nmodel.add(Dropout(0.5))\nmodel.add(Dense(1,activation='sigmoid'))\n\nmodel.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2022-02-14T18:24:59.608967Z","iopub.execute_input":"2022-02-14T18:24:59.610033Z","iopub.status.idle":"2022-02-14T18:24:59.691042Z","shell.execute_reply.started":"2022-02-14T18:24:59.609965Z","shell.execute_reply":"2022-02-14T18:24:59.690089Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2022-02-14T18:25:00.276912Z","iopub.execute_input":"2022-02-14T18:25:00.277294Z","iopub.status.idle":"2022-02-14T18:25:00.293460Z","shell.execute_reply.started":"2022-02-14T18:25:00.277261Z","shell.execute_reply":"2022-02-14T18:25:00.292318Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.callbacks import EarlyStopping","metadata":{"execution":{"iopub.status.busy":"2022-02-14T18:25:01.174771Z","iopub.execute_input":"2022-02-14T18:25:01.175123Z","iopub.status.idle":"2022-02-14T18:25:01.179977Z","shell.execute_reply.started":"2022-02-14T18:25:01.175078Z","shell.execute_reply":"2022-02-14T18:25:01.178940Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"early_stop=EarlyStopping(monitor='val_loss',patience=2)","metadata":{"execution":{"iopub.status.busy":"2022-02-14T18:25:01.939346Z","iopub.execute_input":"2022-02-14T18:25:01.939625Z","iopub.status.idle":"2022-02-14T18:25:01.946158Z","shell.execute_reply.started":"2022-02-14T18:25:01.939594Z","shell.execute_reply":"2022-02-14T18:25:01.944620Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"batch_size=64","metadata":{"execution":{"iopub.status.busy":"2022-02-14T18:25:02.623353Z","iopub.execute_input":"2022-02-14T18:25:02.623847Z","iopub.status.idle":"2022-02-14T18:25:02.633667Z","shell.execute_reply.started":"2022-02-14T18:25:02.623799Z","shell.execute_reply":"2022-02-14T18:25:02.632124Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Creating the Generator Objects so that it will pass images from the directory into the model as input. We had set what operations need to be performed on the images while initializing ImageDataGenerator","metadata":{}},{"cell_type":"code","source":"train_image_gen=image_gen.flow_from_directory(\"/kaggle/working/train\",target_size=(350,350),color_mode='grayscale',batch_size=batch_size,\n                                              class_mode='binary')\ntest_image_gen=image_gen.flow_from_directory(\"/kaggle/working/val\",target_size=image_shape[:2],color_mode='grayscale',batch_size=batch_size,\n                                              class_mode='binary',shuffle=False)","metadata":{"execution":{"iopub.status.busy":"2022-02-14T18:25:05.156281Z","iopub.execute_input":"2022-02-14T18:25:05.156568Z","iopub.status.idle":"2022-02-14T18:25:05.936911Z","shell.execute_reply.started":"2022-02-14T18:25:05.156537Z","shell.execute_reply":"2022-02-14T18:25:05.935952Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_image_gen.class_indices","metadata":{"execution":{"iopub.status.busy":"2022-02-14T18:25:06.421955Z","iopub.execute_input":"2022-02-14T18:25:06.422474Z","iopub.status.idle":"2022-02-14T18:25:06.432322Z","shell.execute_reply.started":"2022-02-14T18:25:06.422438Z","shell.execute_reply":"2022-02-14T18:25:06.430924Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Fitting The Model","metadata":{}},{"cell_type":"code","source":"results= model.fit_generator(train_image_gen,epochs=20,validation_data=test_image_gen,callbacks=[early_stop])","metadata":{"execution":{"iopub.status.busy":"2022-02-14T18:25:07.829725Z","iopub.execute_input":"2022-02-14T18:25:07.830522Z","iopub.status.idle":"2022-02-14T19:55:29.336299Z","shell.execute_reply.started":"2022-02-14T18:25:07.830487Z","shell.execute_reply":"2022-02-14T19:55:29.335368Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Saving Model Weights and the Model","metadata":{}},{"cell_type":"code","source":"model.save_weights('dogcatcnn_weights.h5')\nmodel.save('dogcatmodel.h5')","metadata":{"execution":{"iopub.status.busy":"2022-02-14T19:55:43.243193Z","iopub.execute_input":"2022-02-14T19:55:43.243479Z","iopub.status.idle":"2022-02-14T19:55:43.476851Z","shell.execute_reply.started":"2022-02-14T19:55:43.243436Z","shell.execute_reply":"2022-02-14T19:55:43.475736Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Preparing our Test Data, We are creating an additional folder inside test1 directory so that we can use ImageDataGenerator","metadata":{}},{"cell_type":"code","source":"os.mkdir(\"/kaggle/working/test1/test_data\")\npath=\"/kaggle/working/test1\"\ndest = path +\"/test_data\"\nfiles = os.listdir(path)\n\nfor file_name in files:\n    if \"test\" not in file_name:\n        shutil.move(os.path.join(path, file_name),os.path.join(dest,file_name))\n    else:\n        continue\nprint(\"Done Moving!\")\nprint(len(os.listdir(dest)))","metadata":{"execution":{"iopub.status.busy":"2022-02-14T19:56:13.901548Z","iopub.execute_input":"2022-02-14T19:56:13.901866Z","iopub.status.idle":"2022-02-14T19:56:14.347673Z","shell.execute_reply.started":"2022-02-14T19:56:13.901837Z","shell.execute_reply":"2022-02-14T19:56:14.346565Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Here we only use rescaling as all other parameters are not of use for us as we are now only predicting using the trained model","metadata":{}},{"cell_type":"code","source":"testing_gen=ImageDataGenerator(rescale=1./255)\nrealtest_image_gen=testing_gen.flow_from_directory(\"/kaggle/working/test1\",target_size=image_shape[:2],color_mode='grayscale',batch_size=batch_size,\n                                              class_mode='binary',shuffle=False)","metadata":{"execution":{"iopub.status.busy":"2022-02-14T19:56:24.785976Z","iopub.execute_input":"2022-02-14T19:56:24.786334Z","iopub.status.idle":"2022-02-14T19:56:25.126971Z","shell.execute_reply.started":"2022-02-14T19:56:24.786286Z","shell.execute_reply":"2022-02-14T19:56:25.125982Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Predicing the Images, the values returned are between 0 and 1 as last layer uses a Sigmoid Activation","metadata":{}},{"cell_type":"code","source":"predictions=model.predict_generator(realtest_image_gen, verbose=1)","metadata":{"execution":{"iopub.status.busy":"2022-02-14T19:56:33.956187Z","iopub.execute_input":"2022-02-14T19:56:33.956554Z","iopub.status.idle":"2022-02-14T19:57:17.316334Z","shell.execute_reply.started":"2022-02-14T19:56:33.956492Z","shell.execute_reply":"2022-02-14T19:57:17.315427Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Converting our predictions to either 1 or 0 based on the threshold of 0.5","metadata":{}},{"cell_type":"code","source":"preds=(predictions>0.5).astype(int)","metadata":{"execution":{"iopub.status.busy":"2022-02-14T19:58:03.851881Z","iopub.execute_input":"2022-02-14T19:58:03.852619Z","iopub.status.idle":"2022-02-14T19:58:03.858958Z","shell.execute_reply.started":"2022-02-14T19:58:03.852568Z","shell.execute_reply":"2022-02-14T19:58:03.857879Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds","metadata":{"execution":{"iopub.status.busy":"2022-02-14T19:58:14.938844Z","iopub.execute_input":"2022-02-14T19:58:14.939512Z","iopub.status.idle":"2022-02-14T19:58:14.947332Z","shell.execute_reply.started":"2022-02-14T19:58:14.939476Z","shell.execute_reply":"2022-02-14T19:58:14.945596Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Saving our Final Results in a DataFrame and Exporting it to CSV file. We use an id as index and save the relevant predictions in the label column","metadata":{}},{"cell_type":"code","source":"img_id=range(1,len(os.listdir(dest))+1)","metadata":{"execution":{"iopub.status.busy":"2022-02-14T20:01:43.328701Z","iopub.execute_input":"2022-02-14T20:01:43.329031Z","iopub.status.idle":"2022-02-14T20:01:43.344197Z","shell.execute_reply.started":"2022-02-14T20:01:43.328982Z","shell.execute_reply":"2022-02-14T20:01:43.343155Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_results = pd.DataFrame({\"id\": img_id, \"label\":preds.reshape(12500,)})","metadata":{"execution":{"iopub.status.busy":"2022-02-14T20:03:19.450005Z","iopub.execute_input":"2022-02-14T20:03:19.450331Z","iopub.status.idle":"2022-02-14T20:03:19.456766Z","shell.execute_reply.started":"2022-02-14T20:03:19.450300Z","shell.execute_reply":"2022-02-14T20:03:19.455450Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_results.to_csv(\"Submission.csv\",index=False)","metadata":{"execution":{"iopub.status.busy":"2022-02-14T20:03:55.170154Z","iopub.execute_input":"2022-02-14T20:03:55.170471Z","iopub.status.idle":"2022-02-14T20:03:55.199947Z","shell.execute_reply.started":"2022-02-14T20:03:55.170442Z","shell.execute_reply":"2022-02-14T20:03:55.199125Z"},"trusted":true},"execution_count":null,"outputs":[]}]}