{"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":"nvidiaTeslaT4","dataSources":[{"sourceId":49349,"databundleVersionId":5447706,"sourceType":"competition"},{"sourceId":5706785,"sourceType":"datasetVersion","datasetId":3278289},{"sourceId":5887486,"sourceType":"datasetVersion","datasetId":3374783},{"sourceId":6003552,"sourceType":"datasetVersion","datasetId":3270798},{"sourceId":6004068,"sourceType":"datasetVersion","datasetId":3286300},{"sourceId":7884485,"sourceType":"datasetVersion","datasetId":4628051},{"sourceId":8550018,"sourceType":"datasetVersion","datasetId":5098107}],"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Copy Inputs","metadata":{}},{"cell_type":"code","source":"!pip install /kaggle/input/imc2024-packages-lightglue-rerun-kornia/pycolmap-0.6.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl","metadata":{"execution":{"iopub.status.busy":"2024-05-29T13:55:03.110065Z","iopub.execute_input":"2024-05-29T13:55:03.110807Z","iopub.status.idle":"2024-05-29T13:55:35.189762Z","shell.execute_reply.started":"2024-05-29T13:55:03.110764Z","shell.execute_reply":"2024-05-29T13:55:35.188855Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# copy retrieval weights\n!mkdir -p /root/.cache/torch/hub/netvlad\n!cp /kaggle/input/imc-23-weigths/Pitts30K_struct.mat /root/.cache/torch/hub/netvlad/VGG16-NetVLAD-Pitts30K.mat\n!cp -r /kaggle/input/imc-23-weigths/cosplace/gmberton_cosplace_main /root/.cache/torch/hub/gmberton_CosPlace_main\n!cp -r /kaggle/input/imc-23-weigths/cosplace/checkpoints /root/.cache/torch/hub/checkpoints\n\n# copy rotation prediction\n!mkdir -p /root/.cache/huggingface/\n!cp -r /kaggle/input/orientation-prediction-model/hub /root/.cache/huggingface/\n\n# copy run_pixsfm.py script to working directory and make it executable \n!cp /kaggle/input/imc2023repo/IMC-2023-master/run_pixsfm.py /kaggle/working/run_pixsfm.py\n!chmod 777 run_pixsfm.py\n\n# copy hloc_reconstruction.py script to working directory and make it executable\n!cp /kaggle/input/imc2023repo/IMC-2023-master/hloc_reconstruction.py /kaggle/working/hloc_reconstruction.py\n!chmod 777 hloc_reconstruction.py","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-05-29T13:55:35.192215Z","iopub.execute_input":"2024-05-29T13:55:35.192606Z","iopub.status.idle":"2024-05-29T13:55:53.602688Z","shell.execute_reply.started":"2024-05-29T13:55:35.192555Z","shell.execute_reply":"2024-05-29T13:55:53.601663Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Create venv for PixSfM","metadata":{}},{"cell_type":"code","source":"!python -m venv venv","metadata":{"execution":{"iopub.status.busy":"2024-05-29T13:55:53.604019Z","iopub.execute_input":"2024-05-29T13:55:53.604317Z","iopub.status.idle":"2024-05-29T13:55:58.521054Z","shell.execute_reply.started":"2024-05-29T13:55:53.604289Z","shell.execute_reply":"2024-05-29T13:55:58.520051Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!cp -r /kaggle/input/imc-23-repo/venv .","metadata":{"execution":{"iopub.status.busy":"2024-05-29T13:55:58.522456Z","iopub.execute_input":"2024-05-29T13:55:58.522756Z","iopub.status.idle":"2024-05-29T13:58:46.839218Z","shell.execute_reply.started":"2024-05-29T13:55:58.522729Z","shell.execute_reply":"2024-05-29T13:58:46.838076Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# copy pixsfm d2net\n!mkdir -p /kaggle/working/venv/lib/python3.10/site-packages/pixsfm/features/models/checkpoints\n!cp /kaggle/input/imc-23-weigths/s2dnet_weights.pth /kaggle/working/venv/lib/python3.10/site-packages/pixsfm/features/models/checkpoints/s2dnet_weights.pth","metadata":{"execution":{"iopub.status.busy":"2024-05-29T13:58:46.841994Z","iopub.execute_input":"2024-05-29T13:58:46.842325Z","iopub.status.idle":"2024-05-29T13:58:49.294764Z","shell.execute_reply.started":"2024-05-29T13:58:46.842293Z","shell.execute_reply":"2024-05-29T13:58:49.293264Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls venv/bin","metadata":{"execution":{"iopub.status.busy":"2024-05-29T13:58:49.296436Z","iopub.execute_input":"2024-05-29T13:58:49.296818Z","iopub.status.idle":"2024-05-29T13:58:50.308961Z","shell.execute_reply.started":"2024-05-29T13:58:49.296775Z","shell.execute_reply":"2024-05-29T13:58:50.307736Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Install Dependencies","metadata":{}},{"cell_type":"code","source":"# install hloc\n# %pip install -q /kaggle/input/imc-23-repo/IMC-2023/wheels/hloc-1.3-py3-none-any.whl --no-deps\n\n# install disk deps\n!pip install -q /kaggle/input/imc-23-repo/IMC-2023/wheels/torch_dimcheck-0.0.1-py3-none-any.whl\n!pip install -q /kaggle/input/imc-23-repo/IMC-2023/wheels/unets-0.2.0-py3-none-any.whl\n!pip install -q /kaggle/input/imc-23-repo/IMC-2023/wheels/torch_localize-0.1.0-py3-none-any.whl\n\n# install lightglue deps\n!pip install -q /kaggle/input/imc-23-repo/IMC-2023/wheels/einops-0.6.1-py3-none-any.whl\n\n# install rotation predition\n!pip install -q /kaggle/input/imc-23-repo/IMC-2023/wheels/dioad-1.0.0-py3-none-any.whl\n\n# install ALIKED deps\n!pip install -q /kaggle/input/imc-23-repo/IMC-2023/wheels/thop-0.1.1.post2209072238-py3-none-any.whl --no-deps","metadata":{"execution":{"iopub.status.busy":"2024-05-29T13:58:50.310804Z","iopub.execute_input":"2024-05-29T13:58:50.311764Z","iopub.status.idle":"2024-05-29T14:01:54.583686Z","shell.execute_reply.started":"2024-05-29T13:58:50.311720Z","shell.execute_reply":"2024-05-29T14:01:54.582612Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# tf version of original env\n# !pip install -q /kaggle/input/imc-23-repo/IMC-2023/wheels/protobuf-3.19.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl --no-deps\n# !pip install -q /kaggle/input/imc-23-repo/IMC-2023/wheels/google_auth-2.19.1-py2.py3-none-any.whl --no-deps\n# !pip install -q /kaggle/input/imc-23-repo/IMC-2023/wheels/google_auth_oauthlib-0.4.6-py2.py3-none-any.whl --no-deps\n# !pip install -q /kaggle/input/imc-23-repo/IMC-2023/wheels/tensorboard_data_server-0.6.1-py3-none-manylinux2010_x86_64.whl --no-deps\n# !pip install -q /kaggle/input/imc-23-repo/IMC-2023/wheels/tensorboard_plugin_wit-1.8.1-py3-none-any.whl --no-deps\n# !pip install -q /kaggle/input/imc-23-repo/IMC-2023/wheels/tensorboard-2.11.2-py3-none-any.whl --no-deps\n# !pip install -q /kaggle/input/imc-23-repo/IMC-2023/wheels/tensorflow_estimator-2.11.0-py2.py3-none-any.whl --no-deps\n# !pip install -q /kaggle/input/imc-23-repo/IMC-2023/wheels/tensorflow_io_gcs_filesystem-0.32.0-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl --no-deps\n# !pip install -q /kaggle/input/imc-23-repo/IMC-2023/wheels/keras-2.11.0-py2.py3-none-any.whl --no-deps\n# !pip install -q /kaggle/input/imc-23-repo/IMC-2023/wheels/tensorflow-2.11.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl","metadata":{"execution":{"iopub.status.busy":"2024-05-29T14:01:54.585388Z","iopub.execute_input":"2024-05-29T14:01:54.585764Z","iopub.status.idle":"2024-05-29T14:01:54.591404Z","shell.execute_reply.started":"2024-05-29T14:01:54.585728Z","shell.execute_reply":"2024-05-29T14:01:54.590519Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Run Pipeline","metadata":{}},{"cell_type":"code","source":"!pwd","metadata":{"execution":{"iopub.status.busy":"2024-05-29T14:01:54.592582Z","iopub.execute_input":"2024-05-29T14:01:54.592839Z","iopub.status.idle":"2024-05-29T14:01:55.553362Z","shell.execute_reply.started":"2024-05-29T14:01:54.592817Z","shell.execute_reply":"2024-05-29T14:01:55.552480Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls","metadata":{"execution":{"iopub.status.busy":"2024-05-29T14:01:55.554727Z","iopub.execute_input":"2024-05-29T14:01:55.555026Z","iopub.status.idle":"2024-05-29T14:01:56.501501Z","shell.execute_reply.started":"2024-05-29T14:01:55.554999Z","shell.execute_reply":"2024-05-29T14:01:56.500267Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Adjust pixsfm config\nimport yaml\n\nconf_path = \"/kaggle/input/imc2023repo/IMC-2023-master/ext_deps/pixel-perfect-sfm/pixsfm/configs/low_memory.yaml\"\n\nwith open(conf_path, 'r') as f:\n    conf = yaml.load(f, Loader=yaml.FullLoader)\n\nconf[\"mapping\"][\"BA\"][\"optimizer\"][\"refine_focal_length\"] = True\nconf[\"mapping\"][\"BA\"][\"optimizer\"][\"refine_extra_params\"] = True\nconf[\"mapping\"][\"BA\"][\"optimizer\"][\"refine_extrinsics\"] = True\n\nwith open(\"pixsfm.yaml\", 'w') as f:\n    yaml.dump(conf, f)","metadata":{"execution":{"iopub.status.busy":"2024-05-29T14:01:56.502998Z","iopub.execute_input":"2024-05-29T14:01:56.503269Z","iopub.status.idle":"2024-05-29T14:01:56.585469Z","shell.execute_reply.started":"2024-05-29T14:01:56.503243Z","shell.execute_reply":"2024-05-29T14:01:56.584800Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%pwd","metadata":{"execution":{"iopub.status.busy":"2024-05-29T14:01:56.586829Z","iopub.execute_input":"2024-05-29T14:01:56.587214Z","iopub.status.idle":"2024-05-29T14:01:56.594393Z","shell.execute_reply.started":"2024-05-29T14:01:56.587184Z","shell.execute_reply":"2024-05-29T14:01:56.593533Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import sys\n\nsys.path.append(\"/kaggle/input/imc2023repo/IMC-2023-master\")\nsys.path.append(\"/kaggle/input/imc2023repo/IMC-2023-master/ext_deps/Hierarchical-Localization\")\nsys.path.append(\"/kaggle/input/imc2023repo/IMC-2023-master/ext_deps/dioad\")\n\nimport os\nimport argparse\n\nfrom main import main\n\nargs = {\n    \"data\": \"/kaggle/input/image-matching-challenge-2024\",\n    \"configs\": [\"ALIKED2K\", \"DISK\", \"SIFT\"],\n    \"retrieval\": \"netvlad\",\n    \"n_retrieval\": 30,\n    \"mode\": \"test\",\n    \"output\": \"/kaggle/temp\",\n    \"pixsfm\": True,\n    \"pixsfm_max_imgs\": 9999,\n    \"pixsfm_low_mem_threshold\": 9999,\n    \"pixsfm_config\": \"/kaggle/working/pixsfm.yaml\",\n    \"pixsfm_script_path\": \"/kaggle/input/imc2023repo/IMC-2023-master/run_pixsfm.py\",\n    \"rotation_matching\": False,\n    \"rotation_wrapper\": False,\n    \"resize\": None,\n    \"shared_camera\": True,\n    \"overwrite\": True,\n    \"kaggle\": True,\n    \"cropping\": False,\n    \"max_rel_crop_size\": 1,\n    \"min_rel_crop_size\": 0,\n    \"localize_unregistered\": True,\n    \"skip_scenes\": None,\n}\n\nargs = argparse.Namespace(**args)\nos.makedirs(args.output, exist_ok=True)\n\nmain(args)","metadata":{"execution":{"iopub.status.busy":"2024-05-29T14:01:56.595575Z","iopub.execute_input":"2024-05-29T14:01:56.595906Z","iopub.status.idle":"2024-05-29T14:02:54.277773Z","shell.execute_reply.started":"2024-05-29T14:01:56.595856Z","shell.execute_reply":"2024-05-29T14:02:54.275455Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%pwd","metadata":{"execution":{"iopub.status.busy":"2024-05-29T14:02:54.279086Z","iopub.status.idle":"2024-05-29T14:02:54.279452Z","shell.execute_reply.started":"2024-05-29T14:02:54.279281Z","shell.execute_reply":"2024-05-29T14:02:54.279296Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat /kaggle/working/IMC-2023-master/main.py ","metadata":{"execution":{"iopub.status.busy":"2024-05-29T14:02:54.280605Z","iopub.status.idle":"2024-05-29T14:02:54.280999Z","shell.execute_reply.started":"2024-05-29T14:02:54.280781Z","shell.execute_reply":"2024-05-29T14:02:54.280796Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!python /kaggle/working/IMC-2023-master/main.py args","metadata":{"execution":{"iopub.status.busy":"2024-05-29T14:02:54.282164Z","iopub.status.idle":"2024-05-29T14:02:54.282505Z","shell.execute_reply.started":"2024-05-29T14:02:54.282319Z","shell.execute_reply":"2024-05-29T14:02:54.282332Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"python /kaggle/working/IMC-2023-master/main.py","metadata":{"execution":{"iopub.status.busy":"2024-05-29T14:02:54.283461Z","iopub.status.idle":"2024-05-29T14:02:54.283935Z","shell.execute_reply.started":"2024-05-29T14:02:54.283680Z","shell.execute_reply":"2024-05-29T14:02:54.283700Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!rm -rf venv","metadata":{"execution":{"iopub.status.busy":"2024-05-29T14:02:54.284996Z","iopub.status.idle":"2024-05-29T14:02:54.285304Z","shell.execute_reply.started":"2024-05-29T14:02:54.285149Z","shell.execute_reply":"2024-05-29T14:02:54.285162Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls -l","metadata":{"execution":{"iopub.status.busy":"2024-05-29T14:02:54.286264Z","iopub.status.idle":"2024-05-29T14:02:54.286601Z","shell.execute_reply.started":"2024-05-29T14:02:54.286432Z","shell.execute_reply":"2024-05-29T14:02:54.286446Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls ../temp","metadata":{"execution":{"iopub.status.busy":"2024-05-29T14:02:54.287483Z","iopub.status.idle":"2024-05-29T14:02:54.287782Z","shell.execute_reply.started":"2024-05-29T14:02:54.287631Z","shell.execute_reply":"2024-05-29T14:02:54.287644Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%writefile","metadata":{"execution":{"iopub.status.busy":"2024-05-29T14:02:54.288920Z","iopub.status.idle":"2024-05-29T14:02:54.289237Z","shell.execute_reply.started":"2024-05-29T14:02:54.289081Z","shell.execute_reply":"2024-05-29T14:02:54.289094Z"},"trusted":true},"execution_count":null,"outputs":[]}]}