{"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"},"kaggle":{"accelerator":"gpu","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}],"dockerImageVersionId":30512,"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":"# 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/imc-23-repo/IMC-2023/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/imc-23-repo/IMC-2023/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":"2023-06-14T13:23:56.712378Z","iopub.execute_input":"2023-06-14T13:23:56.712746Z","iopub.status.idle":"2023-06-14T13:24:17.049011Z","shell.execute_reply.started":"2023-06-14T13:23:56.712694Z","shell.execute_reply":"2023-06-14T13:24:17.047598Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Create venv for PixSfM","metadata":{}},{"cell_type":"code","source":"!python -m venv venv","metadata":{"execution":{"iopub.status.busy":"2023-06-14T13:24:17.051892Z","iopub.execute_input":"2023-06-14T13:24:17.052313Z","iopub.status.idle":"2023-06-14T13:24:22.619662Z","shell.execute_reply.started":"2023-06-14T13:24:17.052275Z","shell.execute_reply":"2023-06-14T13:24:22.618397Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!cp -r /kaggle/input/imc-23-repo/venv .","metadata":{"execution":{"iopub.status.busy":"2023-06-14T13:24:22.621507Z","iopub.execute_input":"2023-06-14T13:24:22.62196Z","iopub.status.idle":"2023-06-14T13:27:27.949466Z","shell.execute_reply.started":"2023-06-14T13:24:22.621917Z","shell.execute_reply":"2023-06-14T13:27:27.948228Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-06-14T13:27:27.95278Z","iopub.execute_input":"2023-06-14T13:27:27.953161Z","iopub.status.idle":"2023-06-14T13:27:30.524934Z","shell.execute_reply.started":"2023-06-14T13:27:27.953124Z","shell.execute_reply":"2023-06-14T13:27:30.523701Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!ls venv/bin","metadata":{"execution":{"iopub.status.busy":"2023-06-14T13:27:30.527623Z","iopub.execute_input":"2023-06-14T13:27:30.528272Z","iopub.status.idle":"2023-06-14T13:27:31.494893Z","shell.execute_reply.started":"2023-06-14T13:27:30.528231Z","shell.execute_reply":"2023-06-14T13:27:31.493797Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-06-14T13:27:31.496418Z","iopub.execute_input":"2023-06-14T13:27:31.497132Z","iopub.status.idle":"2023-06-14T13:30:30.65596Z","shell.execute_reply.started":"2023-06-14T13:27:31.497094Z","shell.execute_reply":"2023-06-14T13:30:30.65479Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-06-14T13:30:30.658605Z","iopub.execute_input":"2023-06-14T13:30:30.659343Z","iopub.status.idle":"2023-06-14T13:30:30.665608Z","shell.execute_reply.started":"2023-06-14T13:30:30.659301Z","shell.execute_reply":"2023-06-14T13:30:30.664451Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Run Pipeline","metadata":{}},{"cell_type":"code","source":"!pwd","metadata":{"execution":{"iopub.status.busy":"2023-06-14T13:30:30.667638Z","iopub.execute_input":"2023-06-14T13:30:30.668315Z","iopub.status.idle":"2023-06-14T13:30:31.603594Z","shell.execute_reply.started":"2023-06-14T13:30:30.66828Z","shell.execute_reply":"2023-06-14T13:30:31.602407Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!ls","metadata":{"execution":{"iopub.status.busy":"2023-06-14T13:30:31.605642Z","iopub.execute_input":"2023-06-14T13:30:31.606026Z","iopub.status.idle":"2023-06-14T13:30:32.535067Z","shell.execute_reply.started":"2023-06-14T13:30:31.605988Z","shell.execute_reply":"2023-06-14T13:30:32.533969Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Adjust pixsfm config\nimport yaml\n\nconf_path = \"/kaggle/input/imc-23-repo/IMC-2023/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":"2023-06-14T13:30:32.539956Z","iopub.execute_input":"2023-06-14T13:30:32.540269Z","iopub.status.idle":"2023-06-14T13:30:32.575283Z","shell.execute_reply.started":"2023-06-14T13:30:32.54024Z","shell.execute_reply":"2023-06-14T13:30:32.574467Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import sys\n\nsys.path.append(\"/kaggle/input/imc-23-repo/IMC-2023\")\nsys.path.append(\"/kaggle/input/imc-23-repo/IMC-2023/ext_deps/Hierarchical-Localization\")\nsys.path.append(\"/kaggle/input/imc-23-repo/IMC-2023/ext_deps/dioad\")\n\nimport os\nimport argparse\n\nfrom main import main\n\nargs = {\n    \"data\": \"/kaggle/input/image-matching-challenge-2023\",\n    \"configs\": [\"ALIKED2K\", \"DISK\", \"SP\"],\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/imc-23-repo/IMC-2023/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":"2023-06-14T13:51:09.641831Z","iopub.execute_input":"2023-06-14T13:51:09.642187Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!rm -rf venv","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!ls -l","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!ls ../temp","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{},"outputs":[],"execution_count":null}]}