{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.10","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"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},{"sourceId":12028728,"sourceType":"datasetVersion","datasetId":7568008}],"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":"2025-06-01T18:32:49.985326Z","iopub.execute_input":"2025-06-01T18:32:49.986199Z","iopub.status.idle":"2025-06-01T18:33:09.189743Z","shell.execute_reply.started":"2025-06-01T18:32:49.986166Z","shell.execute_reply":"2025-06-01T18:33:09.18845Z"},"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":"2025-06-01T18:33:09.191688Z","iopub.execute_input":"2025-06-01T18:33:09.191973Z","iopub.status.idle":"2025-06-01T18:33:12.240881Z","shell.execute_reply.started":"2025-06-01T18:33:09.191947Z","shell.execute_reply":"2025-06-01T18:33:12.239753Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!cp -r /kaggle/input/imc-23-repo/venv .","metadata":{"execution":{"iopub.status.busy":"2025-06-01T18:33:12.242173Z","iopub.execute_input":"2025-06-01T18:33:12.242419Z"},"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":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!ls venv/bin","metadata":{"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":{"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":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Run Pipeline","metadata":{}},{"cell_type":"code","source":"!pwd","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!ls","metadata":{"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":{"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\": [\"ALIKED2Kh\", \"DISKh\", \"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/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":{"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":{"trusted":true},"outputs":[],"execution_count":null}]}