{"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\n#import numpy as np # linear algebra\n#import 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\n#import os\n#for dirname, _, filenames in os.walk('/kaggle/input'):\n    #for filename in filenames:\n        #print(os.path.join(dirname, filename))\n        #break\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":"2023-10-18T06:58:16.8421Z","iopub.execute_input":"2023-10-18T06:58:16.842477Z","iopub.status.idle":"2023-10-18T06:58:16.869413Z","shell.execute_reply.started":"2023-10-18T06:58:16.842448Z","shell.execute_reply":"2023-10-18T06:58:16.868561Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Import All Libraries","metadata":{}},{"cell_type":"code","source":"import warnings\nwarnings.filterwarnings('ignore')\n\nimport os\nimport pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\n%matplotlib inline\nimport seaborn as sns\nfrom sklearn.metrics import classification_report , confusion_matrix , accuracy_score , auc\nfrom sklearn.model_selection import train_test_split\n\nimport cv2\nfrom PIL import Image \nimport tensorflow as tf\nfrom tensorflow import keras\nfrom keras import Sequential\nfrom keras.layers import Input, Dense,Conv2D , MaxPooling2D, Flatten,BatchNormalization,Dropout\nfrom tensorflow.keras.preprocessing import image_dataset_from_directory\nimport tensorflow_hub as hub ","metadata":{"execution":{"iopub.status.busy":"2023-10-18T12:48:00.440279Z","iopub.execute_input":"2023-10-18T12:48:00.44083Z","iopub.status.idle":"2023-10-18T12:48:00.446547Z","shell.execute_reply.started":"2023-10-18T12:48:00.440802Z","shell.execute_reply":"2023-10-18T12:48:00.44598Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class_labels = ['CC', 'EC', 'HGSC', 'LGSC', 'MC']","metadata":{"execution":{"iopub.status.busy":"2023-10-18T12:48:01.0531Z","iopub.execute_input":"2023-10-18T12:48:01.053574Z","iopub.status.idle":"2023-10-18T12:48:01.056876Z","shell.execute_reply.started":"2023-10-18T12:48:01.053546Z","shell.execute_reply":"2023-10-18T12:48:01.056176Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Test Image Data Preprocessing ","metadata":{}},{"cell_type":"code","source":"path = \"/kaggle/input/UBC-OCEAN/test.csv\"\ntest_df = pd.read_csv(path)\ntest_df","metadata":{"execution":{"iopub.status.busy":"2023-10-18T12:48:01.918605Z","iopub.execute_input":"2023-10-18T12:48:01.919205Z","iopub.status.idle":"2023-10-18T12:48:01.966327Z","shell.execute_reply.started":"2023-10-18T12:48:01.919176Z","shell.execute_reply":"2023-10-18T12:48:01.96567Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df['is_tma']=((test_df['image_width'] < 5000) & (test_df['image_height'] < 5000))\ntest_df","metadata":{"execution":{"iopub.status.busy":"2023-10-18T12:48:02.921203Z","iopub.execute_input":"2023-10-18T12:48:02.921872Z","iopub.status.idle":"2023-10-18T12:48:02.936277Z","shell.execute_reply.started":"2023-10-18T12:48:02.92184Z","shell.execute_reply":"2023-10-18T12:48:02.935654Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df['is_tma']=test_df['is_tma'].astype(\"int8\")\ntest_df","metadata":{"execution":{"iopub.status.busy":"2023-10-18T12:48:02.966081Z","iopub.execute_input":"2023-10-18T12:48:02.968696Z","iopub.status.idle":"2023-10-18T12:48:02.982135Z","shell.execute_reply.started":"2023-10-18T12:48:02.968656Z","shell.execute_reply":"2023-10-18T12:48:02.981165Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Image.MAX_IMAGE_PIXELS = 10000000000\n# Define patch size and overlap (if needed)\npatch_size = (128,128)  # Adjust this according to your requirements\noverlap = 0  # Adjust this if you want overlapping patches\n\nimage_data_1 = []\nempty_img=0\nfor img_id, tma in zip(test_df['image_id'], test_df['is_tma']):\n    #print(img_id, label,  tma)\n    if tma==0:\n        img_name = str(img_id)+\"_thumbnail.png\"\n        large_image = Image.open(\"/kaggle/input/UBC-OCEAN/test_thumbnails/\"+img_name)\n        single_image_patches = []\n        for y in range(0, large_image.height, patch_size[0] - overlap): # (0,2523,192)\n            for x in range(0, large_image.width, patch_size[1] - overlap):  # (0,3000,192)  224-32=192\n                patch = large_image.crop((x, y, x+patch_size[1], y+patch_size[0]))\n                image = np.array(patch)\n                if np.sum(image)==0:\n                    empty_img+=1\n                elif (np.sum(image[0:,0:50])==0) or (np.sum(image[0:,50:])==0) or (np.sum(image[0:,100:])==0):\n                    empty_img+=1\n                elif (np.sum(image[0:50,0:])==0) or (np.sum(image[50:,0:])==0) or (np.sum(image[100:,0:])==0):\n                    empty_img+=1\n                elif (np.sum(image[0:50,0:50])==0) or (np.sum(image[0:50,50:])==0):\n                    empty_img+=1\n                elif (np.sum(image[50:100,0:50])==0) or (np.sum(image[50:100,50:])==0):\n                    empty_img+=1\n                elif (np.sum(image[50:,0:100])==0) or (np.sum(image[80:,80:])==0):\n                    empty_img+=1\n                elif (np.sum(image[0:50,75:])==0) or (np.sum(image[50:,75:])==0):\n                    empty_img+=1\n                elif (np.sum(image[0:40,80:])==0) or (np.sum(image[80:,80:])==0):\n                    empty_img+=1\n                elif (np.sum(image[0:35,0:])==0) or (np.sum(image[80:,0:])==0):\n                    empty_img+=1\n                elif (np.sum(image[0:25,0:50])==0) or (np.sum(image[0:25,100:])==0):\n                    empty_img+=1\n                elif (np.sum(image[0:20,0:25])==0) or (np.sum(image[0:20,25:50])==0) or (np.sum(image[0:20,50:80])==0) or (np.sum(image[0:20,90:])==0):\n                    empty_img+=1\n                elif (np.sum(image[0:25,0:25])==0) or (np.sum(image[0:25,100:])==0) or (np.sum(image[100:,0:25])==0) or (np.sum(image[100:,100:])==0):\n                    empty_img+=1\n                elif (np.sum(image[0:15,0:])==0) or (np.sum(image[115:,0:])==0):\n                    empty_img+=1\n                elif (np.sum(image[0:,0:15])==0) or (np.sum(image[0:,115:])==0):\n                    empty_img+=1\n                elif (np.sum(image[0:20,0:20])==0) or (np.sum(image[0:20,110:])==0) or (np.sum(image[110:,0:20])==0) or (np.sum(image[110:,110:])==0):\n                    empty_img+=1\n                elif (np.sum(image[0:10,0:10])==0) or (np.sum(image[0:10,115:])==0) or (np.sum(image[0:10,40:60])==0) or (np.sum(image[0:10,80:100])==0):\n                    empty_img+=1\n                elif (np.sum(image[40:50,0:10])==0) or (np.sum(image[110:,80:100])==0) or (np.sum(image[70:85,70:90])==0) or (np.sum(image[50:60,110:])==0):\n                    empty_img+=1\n\n                else:\n                    single_image_patches.append(image)\n        image_data_1.append(single_image_patches)\n        \n    elif tma==1:\n        img_name = str(img_id)+\".png\"\n        large_image = Image.open(\"/kaggle/input/UBC-OCEAN/test_images/\"+img_name)\n        for y in range(0, large_image.height, patch_size[0] - overlap): # (0,2523,192)\n            for x in range(0, large_image.width, patch_size[1] - overlap):  # (0,3000,192)  224-32=192\n                patch = large_image.crop((x, y, x+patch_size[1], y+patch_size[0]))\n                image = np.array(patch)\n                if np.sum(image)==0:\n                    empty_img+=1\n                elif (np.sum(image[0:,0:50])==0) or (np.sum(image[0:,50:])==0) or (np.sum(image[0:,100:])==0):\n                    empty_img+=1\n                elif (np.sum(image[0:50,0:])==0) or (np.sum(image[50:,0:])==0) or (np.sum(image[100:,0:])==0):\n                    empty_img+=1\n                elif (np.sum(image[0:50,0:50])==0) or (np.sum(image[0:50,50:])==0):\n                    empty_img+=1\n                elif (np.sum(image[50:100,0:50])==0) or (np.sum(image[50:100,50:])==0):\n                    empty_img+=1\n                elif (np.sum(image[50:,0:100])==0) or (np.sum(image[80:,80:])==0):\n                    empty_img+=1\n                elif (np.sum(image[0:50,75:])==0) or (np.sum(image[50:,75:])==0):\n                    empty_img+=1\n                elif (np.sum(image[0:40,80:])==0) or (np.sum(image[80:,80:])==0):\n                    empty_img+=1\n                elif (np.sum(image[0:35,0:])==0) or (np.sum(image[80:,0:])==0):\n                    empty_img+=1\n                elif (np.sum(image[0:25,0:50])==0) or (np.sum(image[0:25,100:])==0):\n                    empty_img+=1\n                elif (np.sum(image[0:20,0:25])==0) or (np.sum(image[0:20,25:50])==0) or (np.sum(image[0:20,50:80])==0) or (np.sum(image[0:20,90:])==0):\n                    empty_img+=1\n                elif (np.sum(image[0:25,0:25])==0) or (np.sum(image[0:25,100:])==0) or (np.sum(image[100:,0:25])==0) or (np.sum(image[100:,100:])==0):\n                    empty_img+=1\n                elif (np.sum(image[0:15,0:])==0) or (np.sum(image[115:,0:])==0):\n                    empty_img+=1\n                elif (np.sum(image[0:,0:15])==0) or (np.sum(image[0:,115:])==0):\n                    empty_img+=1\n                elif (np.sum(image[0:20,0:20])==0) or (np.sum(image[0:20,110:])==0) or (np.sum(image[110:,0:20])==0) or (np.sum(image[110:,110:])==0):\n                    empty_img+=1\n                elif (np.sum(image[0:10,0:10])==0) or (np.sum(image[0:10,115:])==0) or (np.sum(image[0:10,40:60])==0) or (np.sum(image[0:10,80:100])==0):\n                    empty_img+=1\n                elif (np.sum(image[40:50,0:10])==0) or (np.sum(image[110:,80:100])==0) or (np.sum(image[70:85,70:90])==0) or (np.sum(image[50:60,110:])==0):\n                    empty_img+=1\n                    \n                else:\n                    single_image_patches.append(image)\n        image_data_1.append(single_image_patches)","metadata":{"execution":{"iopub.status.busy":"2023-10-18T12:48:03.224106Z","iopub.execute_input":"2023-10-18T12:48:03.225285Z","iopub.status.idle":"2023-10-18T12:48:03.64934Z","shell.execute_reply.started":"2023-10-18T12:48:03.22524Z","shell.execute_reply":"2023-10-18T12:48:03.648604Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(image_data_1)","metadata":{"execution":{"iopub.status.busy":"2023-10-18T12:48:03.650768Z","iopub.execute_input":"2023-10-18T12:48:03.650996Z","iopub.status.idle":"2023-10-18T12:48:03.655743Z","shell.execute_reply.started":"2023-10-18T12:48:03.650976Z","shell.execute_reply":"2023-10-18T12:48:03.655144Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"type(image_data_1[0])","metadata":{"execution":{"iopub.status.busy":"2023-10-18T12:48:03.656765Z","iopub.execute_input":"2023-10-18T12:48:03.657315Z","iopub.status.idle":"2023-10-18T12:48:03.665919Z","shell.execute_reply.started":"2023-10-18T12:48:03.657294Z","shell.execute_reply":"2023-10-18T12:48:03.665144Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(image_data_1[0])","metadata":{"execution":{"iopub.status.busy":"2023-10-18T12:48:03.667241Z","iopub.execute_input":"2023-10-18T12:48:03.667458Z","iopub.status.idle":"2023-10-18T12:48:03.676154Z","shell.execute_reply.started":"2023-10-18T12:48:03.66744Z","shell.execute_reply":"2023-10-18T12:48:03.675458Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(empty_img)","metadata":{"execution":{"iopub.status.busy":"2023-10-18T12:48:03.691978Z","iopub.execute_input":"2023-10-18T12:48:03.692175Z","iopub.status.idle":"2023-10-18T12:48:03.695303Z","shell.execute_reply.started":"2023-10-18T12:48:03.692159Z","shell.execute_reply":"2023-10-18T12:48:03.69483Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## list of patch image array\ntest_patch_image_array_folder = []\nfor img in image_data_1:\n    single_image = np.array(img)\n    test_patch_image_array_folder.append(single_image)","metadata":{"execution":{"iopub.status.busy":"2023-10-18T12:48:03.733066Z","iopub.execute_input":"2023-10-18T12:48:03.733283Z","iopub.status.idle":"2023-10-18T12:48:03.740739Z","shell.execute_reply.started":"2023-10-18T12:48:03.733266Z","shell.execute_reply":"2023-10-18T12:48:03.740078Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Testing Images Visualization","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(40,40))\nj=1\nfor i in test_patch_image_array_folder[0][:100]:\n    plt.subplot(10,10,j)\n    plt.imshow(i)\n    j+=1","metadata":{"execution":{"iopub.status.busy":"2023-10-18T12:48:06.014997Z","iopub.execute_input":"2023-10-18T12:48:06.015606Z","iopub.status.idle":"2023-10-18T12:48:24.536419Z","shell.execute_reply.started":"2023-10-18T12:48:06.015576Z","shell.execute_reply":"2023-10-18T12:48:24.535635Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# print(len(test_image_folder))\n# print(len(test_thumbnail_folder))","metadata":{"execution":{"iopub.status.busy":"2023-10-18T06:58:50.919908Z","iopub.status.idle":"2023-10-18T06:58:50.920952Z","shell.execute_reply.started":"2023-10-18T06:58:50.920703Z","shell.execute_reply":"2023-10-18T06:58:50.920724Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#print(len(image_data_1))\n#print(len(empty_img))","metadata":{"execution":{"iopub.status.busy":"2023-10-18T06:58:50.921955Z","iopub.status.idle":"2023-10-18T06:58:50.922463Z","shell.execute_reply.started":"2023-10-18T06:58:50.922295Z","shell.execute_reply":"2023-10-18T06:58:50.922313Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_patch_image_array_folder[0].shape","metadata":{"execution":{"iopub.status.busy":"2023-10-18T12:49:56.096464Z","iopub.execute_input":"2023-10-18T12:49:56.097144Z","iopub.status.idle":"2023-10-18T12:49:56.101515Z","shell.execute_reply.started":"2023-10-18T12:49:56.097108Z","shell.execute_reply":"2023-10-18T12:49:56.100951Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Load The Model ","metadata":{}},{"cell_type":"code","source":"import tensorflow as tf\nimport tensorflow_hub as hub","metadata":{"execution":{"iopub.status.busy":"2023-10-18T06:58:50.936089Z","iopub.status.idle":"2023-10-18T06:58:50.936454Z","shell.execute_reply.started":"2023-10-18T06:58:50.936288Z","shell.execute_reply":"2023-10-18T06:58:50.936305Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Recreate the exact same model, including its weights and the optimizer\n# path = \"/kaggle/input/mobilenet-model/mobilenet_model_1.h5\"\n# path2 = \"/kaggle/input/mobilenet-model-2/mobilenet_model_2.h5\"\n# path3 = \"/kaggle/input/mobilenet-model-3/mobilenet_model_3.h5\"\n\npath4 = \"/kaggle/input/my-model/mobilenet_model_4.h5\"\n\nmy_model = tf.keras.models.load_model(\n       (path4),\n       custom_objects={'KerasLayer':hub.KerasLayer}\n)\n# Show the model architecture\nmy_model.summary()","metadata":{"execution":{"iopub.status.busy":"2023-10-18T12:50:39.690571Z","iopub.execute_input":"2023-10-18T12:50:39.690887Z","iopub.status.idle":"2023-10-18T12:50:47.339592Z","shell.execute_reply.started":"2023-10-18T12:50:39.690866Z","shell.execute_reply":"2023-10-18T12:50:47.339047Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Predicting Testing Images for Submission","metadata":{}},{"cell_type":"code","source":"#test_patch_image_array_folder[0].shape","metadata":{"execution":{"iopub.status.busy":"2023-10-18T06:58:50.940042Z","iopub.status.idle":"2023-10-18T06:58:50.940622Z","shell.execute_reply.started":"2023-10-18T06:58:50.940438Z","shell.execute_reply":"2023-10-18T06:58:50.940456Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from collections import Counter\n\n#class_labels = ['CC', 'EC', 'HGSC', 'LGSC', 'MC']","metadata":{"execution":{"iopub.status.busy":"2023-10-18T12:50:57.420728Z","iopub.execute_input":"2023-10-18T12:50:57.421309Z","iopub.status.idle":"2023-10-18T12:50:57.424166Z","shell.execute_reply.started":"2023-10-18T12:50:57.421283Z","shell.execute_reply":"2023-10-18T12:50:57.423626Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in test_patch_image_array_folder:\n    output = my_model.predict(i)\n    output = [np.argmax(j) for j in output]","metadata":{"execution":{"iopub.status.busy":"2023-10-18T12:51:02.329091Z","iopub.execute_input":"2023-10-18T12:51:02.329691Z","iopub.status.idle":"2023-10-18T12:51:11.350241Z","shell.execute_reply.started":"2023-10-18T12:51:02.329662Z","shell.execute_reply":"2023-10-18T12:51:11.349549Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(output)","metadata":{"execution":{"iopub.status.busy":"2023-10-18T12:51:20.601399Z","iopub.execute_input":"2023-10-18T12:51:20.602049Z","iopub.status.idle":"2023-10-18T12:51:20.607432Z","shell.execute_reply.started":"2023-10-18T12:51:20.602009Z","shell.execute_reply":"2023-10-18T12:51:20.606912Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(35,75))\nj=0\nfor i in test_patch_image_array_folder[0][:100]:\n    plt.subplot(15,7,j+1)\n    plt.imshow(i)\n    plt.title(f\"Predicted label:{class_labels[output[j]]}\")\n    j+=1","metadata":{"execution":{"iopub.status.busy":"2023-10-18T12:59:23.00444Z","iopub.execute_input":"2023-10-18T12:59:23.004763Z","iopub.status.idle":"2023-10-18T12:59:47.549552Z","shell.execute_reply.started":"2023-10-18T12:59:23.004738Z","shell.execute_reply":"2023-10-18T12:59:47.548835Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_submission_label = []\nfor i in test_patch_image_array_folder:\n    output = my_model.predict(i)\n    output = [np.argmax(j) for j in output]\n    \n    ## Use Counter to find most common\n    count = Counter(output)\n    result = count.most_common(1)[0][0]\n    \n    test_submission_label.append(class_labels[result])","metadata":{"execution":{"iopub.status.busy":"2023-10-18T13:00:46.175805Z","iopub.execute_input":"2023-10-18T13:00:46.176419Z","iopub.status.idle":"2023-10-18T13:00:46.3982Z","shell.execute_reply.started":"2023-10-18T13:00:46.176392Z","shell.execute_reply":"2023-10-18T13:00:46.397295Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"count.most_common()","metadata":{"execution":{"iopub.status.busy":"2023-10-18T13:00:47.624819Z","iopub.execute_input":"2023-10-18T13:00:47.625432Z","iopub.status.idle":"2023-10-18T13:00:47.629778Z","shell.execute_reply.started":"2023-10-18T13:00:47.625409Z","shell.execute_reply":"2023-10-18T13:00:47.629184Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_submission_label","metadata":{"execution":{"iopub.status.busy":"2023-10-18T13:00:49.419585Z","iopub.execute_input":"2023-10-18T13:00:49.420208Z","iopub.status.idle":"2023-10-18T13:00:49.424536Z","shell.execute_reply.started":"2023-10-18T13:00:49.420181Z","shell.execute_reply":"2023-10-18T13:00:49.423666Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Final submission","metadata":{}},{"cell_type":"code","source":"## Sample Submission\npath = \"/kaggle/input/UBC-OCEAN/sample_submission.csv\"\nsample_df = pd.read_csv(path)\nsample_df","metadata":{"execution":{"iopub.status.busy":"2023-10-18T13:01:00.203318Z","iopub.execute_input":"2023-10-18T13:01:00.203808Z","iopub.status.idle":"2023-10-18T13:01:00.218488Z","shell.execute_reply.started":"2023-10-18T13:01:00.203781Z","shell.execute_reply":"2023-10-18T13:01:00.21785Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df","metadata":{"execution":{"iopub.status.busy":"2023-10-18T13:01:01.016329Z","iopub.execute_input":"2023-10-18T13:01:01.017119Z","iopub.status.idle":"2023-10-18T13:01:01.024092Z","shell.execute_reply.started":"2023-10-18T13:01:01.01709Z","shell.execute_reply":"2023-10-18T13:01:01.023465Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Assuming 'test_ids' are the IDs of test samples, and 'predictions' are the predicted values\nsubmission = pd.DataFrame({'image_id':test_df['image_id'] , 'label':test_submission_label })\nsubmission.to_csv('submission.csv', index=False)  # Save the CSV file","metadata":{"execution":{"iopub.status.busy":"2023-10-18T13:01:02.09236Z","iopub.execute_input":"2023-10-18T13:01:02.09298Z","iopub.status.idle":"2023-10-18T13:01:02.098227Z","shell.execute_reply.started":"2023-10-18T13:01:02.09295Z","shell.execute_reply":"2023-10-18T13:01:02.09766Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_submission = pd.read_csv(\"submission.csv\")\nfinal_submission","metadata":{"execution":{"iopub.status.busy":"2023-10-18T13:01:02.534353Z","iopub.execute_input":"2023-10-18T13:01:02.534988Z","iopub.status.idle":"2023-10-18T13:01:02.543869Z","shell.execute_reply.started":"2023-10-18T13:01:02.534955Z","shell.execute_reply":"2023-10-18T13:01:02.543038Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}