{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":71885,"databundleVersionId":8143495,"sourceType":"competition"}],"dockerImageVersionId":30673,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# <div style=\"padding: 25px;color:white;margin:10;font-size:60%;text-align:left;display:fill;border-radius:10px;background-color:#FFFFFF;overflow:hidden;background-color:#87CEEB\"><b><span style='color:#FFFFFF'></span></b> <b>1. Domain Explanation</b></div>","metadata":{}},{"cell_type":"markdown","source":"#### <b><span style='color:#87CEEB'> |</span> The Previous Competition</b>","metadata":{}},{"cell_type":"markdown","source":"📌**[2023 Edition of the competiton](https://www.kaggle.com/competitions/image-matching-challenge-2023)**: Reconstruct 3D scenes form 2D images \n\n📌 **[2022 Edition of the competition](https://www.kaggle.com/competitions/image-matching-challenge-2022)**: Register two images from different viewpoints","metadata":{}},{"cell_type":"markdown","source":"#### <b><span style='color:#87CEEB'> |</span> The Goal of this Competition</b>","metadata":{}},{"cell_type":"markdown","source":"<b>*Construct precise 3D maps using sets of images in diverse scenarios and environments*</b>","metadata":{}},{"cell_type":"markdown","source":"#### <b><span style='color:#87CEEB'> |</span> Six Different Domains</b>","metadata":{}},{"cell_type":"markdown","source":"- <b><span style='color:#1E90FF'> Phototourism and historical preservation</span></b>: different viewpoints, sensor types, time of day/year, and occlusions. Ancient historical sites add a unique set of challenges\n\n- <b><span style='color:#1E90FF'>Night vs day and temporal changes</span></b>: combination of day and night photographs, including poor lighting, or photographs taken months or years apart, in \ndifferent weather\n\n- <b><span style='color:#1E90FF'>Aerial and mixed aerial-ground</span></b>:  images from drones, featuring arbitrary in-plane rotations, matched against similar images and also images taken from the ground\n\n- <b><span style='color:#1E90FF'>Repeated structures</span></b>: symmetrical objects require details to disambiguate perspective\n\n- <b><span style='color:#1E90FF'>Natural environments</span></b>: highly non-regular structures such as trees and foliage\n\n- <b><span style='color:#1E90FF'>Transparencies and reflections</span></b>: objects like glassware are lacking in texture and create reflections and specularities which pose a different set of problems","metadata":{}},{"cell_type":"markdown","source":"# <div style=\"padding: 25px;color:white;margin:10;font-size:60%;text-align:left;display:fill;border-radius:10px;background-color:#FFFFFF;overflow:hidden;background-color:#87CEEB\"><b><span style='color:#FFFFFF'></span></b> <b>2. Import and Read Data</b></div>","metadata":{}},{"cell_type":"code","source":"import os\nimport gc\nimport ctypes\nimport random\nimport sys\n\nfrom tqdm import tqdm\nfrom time import time, sleep\n\nfrom pathlib import Path\nimport numpy as np, pandas as pd \nimport matplotlib.pyplot as plt \nimport seaborn as sns \n\nimport torch\nimport torch.nn as nn\n\nimport warnings\nwarnings.filterwarnings('ignore')\n\nSEED = 2024","metadata":{"execution":{"iopub.status.busy":"2024-04-09T04:38:20.313843Z","iopub.execute_input":"2024-04-09T04:38:20.314316Z","iopub.status.idle":"2024-04-09T04:38:26.559745Z","shell.execute_reply.started":"2024-04-09T04:38:20.314268Z","shell.execute_reply":"2024-04-09T04:38:26.558448Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Clean Memory*","metadata":{}},{"cell_type":"code","source":"def clean_memory():\n    ctypes.CDLL('libc.so.6').malloc_trim(0)\n    gc.collect()\n    \nclean_memory() ","metadata":{"execution":{"iopub.status.busy":"2024-04-09T04:38:26.564245Z","iopub.execute_input":"2024-04-09T04:38:26.564749Z","iopub.status.idle":"2024-04-09T04:38:26.698203Z","shell.execute_reply.started":"2024-04-09T04:38:26.564718Z","shell.execute_reply":"2024-04-09T04:38:26.696986Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Seed Everything*","metadata":{}},{"cell_type":"code","source":"def seed_everything():\n    random.seed(SEED)\n    os.environ['PYTHONHASHSEED'] = str(SEED)\n    np.random.seed(SEED)\n    torch.manual_seed(SEED)\n    torch.cuda.manual_seed(SEED)\n    torch.backends.cudnn.deterministric = True\n    torch.backends.cudnn.benchmark = True \n    \nseed_everything()    ","metadata":{"execution":{"iopub.status.busy":"2024-04-09T04:38:26.699829Z","iopub.execute_input":"2024-04-09T04:38:26.700504Z","iopub.status.idle":"2024-04-09T04:38:26.711284Z","shell.execute_reply.started":"2024-04-09T04:38:26.700451Z","shell.execute_reply":"2024-04-09T04:38:26.710423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Dataset Description","metadata":{}},{"cell_type":"markdown","source":"#### <b><span style='color:#87CEEB'> |</span> [train/test]images</b>","metadata":{}},{"cell_type":"markdown","source":"📌 A batch of images all taken near the same location. Some of training datasets may also contain a folder named images_full with additional images. The published test folder comprises a subset of the church scene from train and is provided solely for example purposes. The training data usually has a sequential capture ordering and significant image-to-image content overlap while the test set has limited image-to-image overlap and the image ordering is randomized.","metadata":{}},{"cell_type":"markdown","source":"#### <b><span style='color:#87CEEB'> |</span> train/smf</b>","metadata":{}},{"cell_type":"markdown","source":"📌 A 3-D reconstruction for this batch of images, which can be opened with colmap, the 3-D structure-from-motion library bundled with this competition","metadata":{}},{"cell_type":"markdown","source":"#### <b><span style='color:#87CEEB'> |</span> train/LICENSE.txt</b>","metadata":{}},{"cell_type":"markdown","source":"📌 The license for this dataset","metadata":{}},{"cell_type":"markdown","source":"#### <b><span style='color:#87CEEB'> |</span> train_labels.csv</b>","metadata":{}},{"cell_type":"markdown","source":"- `dataset`: The unique identifier for the dataset\n\n- `scene`: The unique identifier for the scene \n\n- `image_name`:  The image filename\n\n- `rotation_matrix`: The first target column. A 3X3 matrix, flattened into a vector in row-major convention with values separated by ;\n\n- `translation_vetcor`: The second target column. A 3-D dimensional vetcor, with values separated by ; ","metadata":{}},{"cell_type":"code","source":"train_labels = pd.read_csv('/kaggle/input/image-matching-challenge-2024/train/train_labels.csv')\nprint('Shape of train_labels:', train_labels.shape)\nprint(display(train_labels))","metadata":{"execution":{"iopub.status.busy":"2024-04-09T04:38:26.713330Z","iopub.execute_input":"2024-04-09T04:38:26.713916Z","iopub.status.idle":"2024-04-09T04:38:26.779835Z","shell.execute_reply.started":"2024-04-09T04:38:26.713886Z","shell.execute_reply":"2024-04-09T04:38:26.778719Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12,6))\n\nplt.subplot(1,2,1)\nsns.countplot(x=train_labels['dataset'])\nplt.xticks(rotation=90)\nplt.title(\"Distribution of Dataset\")\n\n\nplt.subplot(1,2,2)\nsns.countplot(x=train_labels['scene'])\nplt.xticks(rotation=90)\nplt.title('Distribution of Scene')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-04-09T04:38:26.781268Z","iopub.execute_input":"2024-04-09T04:38:26.781594Z","iopub.status.idle":"2024-04-09T04:38:27.335035Z","shell.execute_reply.started":"2024-04-09T04:38:26.781567Z","shell.execute_reply":"2024-04-09T04:38:27.333881Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_labels.loc[train_labels['scene'] != train_labels['dataset']]","metadata":{"execution":{"iopub.status.busy":"2024-04-09T04:39:07.829544Z","iopub.execute_input":"2024-04-09T04:39:07.829933Z","iopub.status.idle":"2024-04-09T04:39:07.842359Z","shell.execute_reply.started":"2024-04-09T04:39:07.829890Z","shell.execute_reply":"2024-04-09T04:39:07.841204Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### <b><span style='color:#87CEEB'> |</span> categories.csv</b>","metadata":{}},{"cell_type":"markdown","source":"- **`chruch`**: <b><span style='color:#1E90FF'>symmetries-and-repeats</span></b>\n\n- **`dioscuri`**: <b><span style='color:#1E90FF'>historical_pressrvation;air-to-ground</span></b>\n\n- **`lizard`**: <b><span style='color:#1E90FF'>day-night;temporal</span></b>\n\n- **`multi-temporal-temple-baalshamin`**: <b><span style='color:#1E90FF'>historical_presservation;temporal</span></b>\n\n- **`pond`**: <b><span style='color:#1E90FF'>day-night;temporal;nature</span></b>\n\n- **`transp_obj_glass_cup`**: <b><span style='color:#1E90FF'>symmetries-and-repeats;transparent</span></b>\n\n- **`transp_obj_glass_cylinder`**: <b><span style='color:#1E90FF'>symmetries-and-repeats;transparent</span></b>","metadata":{}},{"cell_type":"code","source":"category = pd.read_csv('/kaggle/input/image-matching-challenge-2024/train/categories.csv')\n\nexplode = (0.01, 0.01, 0.01, 0.01, 0.01, 0.01)\nlabels = category['categories'].unique()\n\nplt.figure(figsize=(12,6))\nplt.title(\"Distribution of Category\")\nplt.pie(category['categories'].value_counts(), labels=labels, explode=explode, autopct='%.1f%%')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-04-09T05:09:08.243121Z","iopub.execute_input":"2024-04-09T05:09:08.243558Z","iopub.status.idle":"2024-04-09T05:09:08.499108Z","shell.execute_reply.started":"2024-04-09T05:09:08.243526Z","shell.execute_reply":"2024-04-09T05:09:08.497865Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### <b><span style='color:#87CEEB'> |</span> sample_submission.csv</b>","metadata":{}},{"cell_type":"markdown","source":"- `image_path`: The image filename, including the path\n\n- `dataset`: The unique identifier for the dataset\n\n- `scene`:  The unique identifier for the scene\n\n- `rotation_matrix`: The first target column. A 3X3 matrix, flattened into a vector in row-major convention with values separated by ;\n\n- `translation_vetcor`: The second target column. A 3-D dimensional vetcor, with values separated by ; ","metadata":{}},{"cell_type":"code","source":"sample_submission = pd.read_csv('/kaggle/input/image-matching-challenge-2024/sample_submission.csv')\nprint(display(sample_submission.head()))","metadata":{"execution":{"iopub.status.busy":"2024-04-09T05:15:17.396057Z","iopub.execute_input":"2024-04-09T05:15:17.396437Z","iopub.status.idle":"2024-04-09T05:15:17.414496Z","shell.execute_reply.started":"2024-04-09T05:15:17.396408Z","shell.execute_reply":"2024-04-09T05:15:17.412965Z"},"trusted":true},"execution_count":null,"outputs":[]}]}