{"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\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","trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Introduction to competition","metadata":{}},{"cell_type":"markdown","source":"⚪ The goal of this competition is to reconstruct accurate 3D maps from many different views, mapping the world from assorted and noisy data sources, such as images uploaded by users to services like Google Maps.\n\n⚪ The work in helping to build accurate 3D models may have applications to photography, cultural heritage preservation, and many services across Google.\n\n⚪ The process of reconstructing a 3D model of an environment from a collection of images is called Structure from Motion (SfM). Combining photos from different sources can create a more complete, three-dimensional view of any given thing.\n\n⚪ The competition is hosted by Google in collaboration with Haiper and Kaggle.","metadata":{}},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow import keras\nimport cv2\nimport matplotlib.pyplot as plt","metadata":{"execution":{"iopub.status.busy":"2023-05-06T07:50:12.168312Z","iopub.execute_input":"2023-05-06T07:50:12.169318Z","iopub.status.idle":"2023-05-06T07:50:12.539407Z","shell.execute_reply.started":"2023-05-06T07:50:12.169267Z","shell.execute_reply":"2023-05-06T07:50:12.538466Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"# Load CSV file","metadata":{"execution":{"iopub.status.busy":"2023-05-06T07:16:04.737520Z","iopub.execute_input":"2023-05-06T07:16:04.738383Z","iopub.status.idle":"2023-05-06T07:16:04.742364Z","shell.execute_reply.started":"2023-05-06T07:16:04.738336Z","shell.execute_reply":"2023-05-06T07:16:04.741601Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\ndf_train_labels = pd.read_csv('/kaggle/input/image-matching-challenge-2023/train/train_labels.csv')\ndf_train_labels.head()","metadata":{"execution":{"iopub.status.busy":"2023-05-06T07:19:15.234263Z","iopub.execute_input":"2023-05-06T07:19:15.234676Z","iopub.status.idle":"2023-05-06T07:19:15.265754Z","shell.execute_reply.started":"2023-05-06T07:19:15.234646Z","shell.execute_reply":"2023-05-06T07:19:15.264803Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Information about the csv dataset","metadata":{}},{"cell_type":"code","source":"df_train_labels.info()","metadata":{"execution":{"iopub.status.busy":"2023-05-06T07:22:11.828465Z","iopub.execute_input":"2023-05-06T07:22:11.828824Z","iopub.status.idle":"2023-05-06T07:22:11.859794Z","shell.execute_reply.started":"2023-05-06T07:22:11.828797Z","shell.execute_reply":"2023-05-06T07:22:11.858564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_labels.shape","metadata":{"execution":{"iopub.status.busy":"2023-05-06T07:23:06.404667Z","iopub.execute_input":"2023-05-06T07:23:06.405066Z","iopub.status.idle":"2023-05-06T07:23:06.411901Z","shell.execute_reply.started":"2023-05-06T07:23:06.405036Z","shell.execute_reply":"2023-05-06T07:23:06.411144Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_labels.columns","metadata":{"execution":{"iopub.status.busy":"2023-05-06T07:29:26.640404Z","iopub.execute_input":"2023-05-06T07:29:26.640791Z","iopub.status.idle":"2023-05-06T07:29:26.647557Z","shell.execute_reply.started":"2023-05-06T07:29:26.640761Z","shell.execute_reply":"2023-05-06T07:29:26.646764Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_labels['scene'].unique()","metadata":{"execution":{"iopub.status.busy":"2023-05-06T07:30:46.647340Z","iopub.execute_input":"2023-05-06T07:30:46.647700Z","iopub.status.idle":"2023-05-06T07:30:46.655344Z","shell.execute_reply.started":"2023-05-06T07:30:46.647673Z","shell.execute_reply":"2023-05-06T07:30:46.654183Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_labels['dataset'].unique()","metadata":{"execution":{"iopub.status.busy":"2023-05-06T07:31:01.442686Z","iopub.execute_input":"2023-05-06T07:31:01.443136Z","iopub.status.idle":"2023-05-06T07:31:01.450496Z","shell.execute_reply.started":"2023-05-06T07:31:01.443087Z","shell.execute_reply":"2023-05-06T07:31:01.449346Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Pic chart for the dataset","metadata":{}},{"cell_type":"code","source":"plt.pie(df_train_labels['dataset'].value_counts(),startangle=90,autopct='%.3f',labels=['urban', 'heritage', 'haiper'],shadow=True)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-05-06T07:32:08.673931Z","iopub.execute_input":"2023-05-06T07:32:08.674318Z","iopub.status.idle":"2023-05-06T07:32:08.879115Z","shell.execute_reply.started":"2023-05-06T07:32:08.674275Z","shell.execute_reply":"2023-05-06T07:32:08.877862Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.pie(df_train_labels['scene'].value_counts(),startangle=90,autopct='%.3f',labels=['kyiv-puppet-theater', 'dioscuri', 'cyprus', 'bike', 'chairs',\n       'fountain', 'wall'],shadow=True)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-05-06T07:32:29.893825Z","iopub.execute_input":"2023-05-06T07:32:29.894197Z","iopub.status.idle":"2023-05-06T07:32:30.131022Z","shell.execute_reply.started":"2023-05-06T07:32:29.894171Z","shell.execute_reply":"2023-05-06T07:32:30.129626Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Image dataset","metadata":{}},{"cell_type":"code","source":"!pip install mediapy -q\n\n\n\n%cd /kaggle/working/\n!rm -rf /kaggle/working/Hierarchical-Localization\n!git clone --quiet --recursive https://github.com/cvg/Hierarchical-Localization/\n%cd /kaggle/working/Hierarchical-Localization\n!pip install -e .\n\nfrom hloc import extract_features, match_features, reconstruction, visualization, pairs_from_exhaustive\nfrom hloc.visualization import plot_images, read_image\nfrom hloc.utils import viz_3d\n\n%cd /kaggle/working/\n\n","metadata":{"execution":{"iopub.status.busy":"2023-05-06T07:51:17.993340Z","iopub.execute_input":"2023-05-06T07:51:17.993704Z","iopub.status.idle":"2023-05-06T07:52:05.924794Z","shell.execute_reply.started":"2023-05-06T07:51:17.993678Z","shell.execute_reply":"2023-05-06T07:52:05.923716Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport cv2\nimport pycolmap\n\nimport numpy as np\nimport mediapy as media\nimport pandas as pd\nimport plotly.express as px\nimport plotly.graph_objects as go\n\nfrom glob import glob\nfrom pathlib import Path\nfrom time import time","metadata":{"execution":{"iopub.status.busy":"2023-05-06T07:53:43.119768Z","iopub.execute_input":"2023-05-06T07:53:43.121446Z","iopub.status.idle":"2023-05-06T07:53:43.854420Z","shell.execute_reply.started":"2023-05-06T07:53:43.121396Z","shell.execute_reply":"2023-05-06T07:53:43.853501Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Heritage","metadata":{}},{"cell_type":"code","source":"dataset = 'heritage'\nscene = 'wall'\nsrc = f'/kaggle/input/image-matching-challenge-2023/train/{dataset}/{scene}'\n\nlimit = 12\nimages = [cv2.cvtColor(cv2.imread(im), cv2.COLOR_BGR2RGB) for im in glob(f'{src}/images/*')[:limit]]\nmedia.show_images(images, height=300, columns=3)\n\n","metadata":{"execution":{"iopub.status.busy":"2023-05-06T07:54:10.329410Z","iopub.execute_input":"2023-05-06T07:54:10.329803Z","iopub.status.idle":"2023-05-06T07:54:24.657095Z","shell.execute_reply.started":"2023-05-06T07:54:10.329773Z","shell.execute_reply":"2023-05-06T07:54:24.656304Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset = 'heritage'\nscene = 'dioscuri'\nsrc = f'/kaggle/input/image-matching-challenge-2023/train/{dataset}/{scene}'\n\nlimit = 12\nimages = [cv2.cvtColor(cv2.imread(im), cv2.COLOR_BGR2RGB) for im in glob(f'{src}/images/*')[:limit]]\nmedia.show_images(images, height=300, columns=3)","metadata":{"execution":{"iopub.status.busy":"2023-05-06T07:58:27.304689Z","iopub.execute_input":"2023-05-06T07:58:27.305083Z","iopub.status.idle":"2023-05-06T07:58:28.760090Z","shell.execute_reply.started":"2023-05-06T07:58:27.305052Z","shell.execute_reply":"2023-05-06T07:58:28.758986Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset = 'heritage'\nscene = 'cyprus'\nsrc = f'/kaggle/input/image-matching-challenge-2023/train/{dataset}/{scene}'\n\nlimit = 12\nimages = [cv2.cvtColor(cv2.imread(im), cv2.COLOR_BGR2RGB) for im in glob(f'{src}/images/*')[:limit]]\nmedia.show_images(images, height=300, columns=3)","metadata":{"execution":{"iopub.status.busy":"2023-05-06T08:01:15.847573Z","iopub.execute_input":"2023-05-06T08:01:15.848021Z","iopub.status.idle":"2023-05-06T08:01:30.156346Z","shell.execute_reply.started":"2023-05-06T08:01:15.847990Z","shell.execute_reply":"2023-05-06T08:01:30.155160Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset = 'urban'\nscene = 'kyiv-puppet-theater'\nsrc = f'/kaggle/input/image-matching-challenge-2023/train/{dataset}/{scene}'\n\nlimit = 12\nimages = [cv2.cvtColor(cv2.imread(im), cv2.COLOR_BGR2RGB) for im in glob(f'{src}/images/*')[:limit]]\nmedia.show_images(images, height=300, columns=3)","metadata":{"execution":{"iopub.status.busy":"2023-05-06T08:03:47.384743Z","iopub.execute_input":"2023-05-06T08:03:47.385193Z","iopub.status.idle":"2023-05-06T08:03:48.864387Z","shell.execute_reply.started":"2023-05-06T08:03:47.385160Z","shell.execute_reply":"2023-05-06T08:03:48.863382Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset = 'haiper'\nscene = 'fountain'\nsrc = f'/kaggle/input/image-matching-challenge-2023/train/{dataset}/{scene}'\n\nlimit = 12\nimages = [cv2.cvtColor(cv2.imread(im), cv2.COLOR_BGR2RGB) for im in glob(f'{src}/images/*')[:limit]]\nmedia.show_images(images, height=300, columns=3)","metadata":{"execution":{"iopub.status.busy":"2023-05-06T08:12:22.989345Z","iopub.execute_input":"2023-05-06T08:12:22.989704Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}