{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.11","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":91498,"databundleVersionId":11655853,"sourceType":"competition"},{"sourceId":8571511,"sourceType":"datasetVersion","datasetId":3204501},{"sourceId":11890648,"sourceType":"datasetVersion","datasetId":7185924},{"sourceId":11909458,"sourceType":"datasetVersion","datasetId":7487001},{"sourceId":12008724,"sourceType":"datasetVersion","datasetId":7105843},{"sourceId":4534,"sourceType":"modelInstanceVersion","modelInstanceId":3326,"modelId":986},{"sourceId":17191,"sourceType":"modelInstanceVersion","modelInstanceId":14317,"modelId":21716},{"sourceId":17555,"sourceType":"modelInstanceVersion","modelInstanceId":14611,"modelId":22086}],"dockerImageVersionId":31011,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!pip config set global.disable-pip-version-check true","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-05-22T13:54:10.958679Z","iopub.execute_input":"2025-05-22T13:54:10.959212Z","iopub.status.idle":"2025-05-22T13:54:11.472957Z","shell.execute_reply.started":"2025-05-22T13:54:10.959189Z","shell.execute_reply":"2025-05-22T13:54:11.47204Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!cp /kaggle/input/glomap/glomap_build/glomap /usr/local/bin/\n!chmod 755 /usr/local/bin/glomap\n\n!cp -r /kaggle/input/glomap/glomap_build glomap_lib\n!rm glomap_lib/librt.so.1  # conflict\n!rm glomap_lib/libdl.so.2\n!rm glomap_lib/libnvJitLink.so.12*","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T13:54:17.674514Z","iopub.execute_input":"2025-05-22T13:54:17.674867Z","iopub.status.idle":"2025-05-22T13:54:33.224268Z","shell.execute_reply.started":"2025-05-22T13:54:17.674833Z","shell.execute_reply":"2025-05-22T13:54:33.223469Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!cp -r /kaggle/input/ns64-imc2025lib/lib_py311_t4/custom_ops ./\n!cp /kaggle/input/ns64-imc2025lib/lib_py311_t4/score_computation_cuda.cpython-311-x86_64-linux-gnu.so ./\n!cp /kaggle/input/ns64-imc2025lib/lib_py311_t4/value_aggregation_cuda.cpython-311-x86_64-linux-gnu.so ./","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T13:54:44.34567Z","iopub.execute_input":"2025-05-22T13:54:44.346441Z","iopub.status.idle":"2025-05-22T13:54:45.102291Z","shell.execute_reply.started":"2025-05-22T13:54:44.346415Z","shell.execute_reply":"2025-05-22T13:54:45.101114Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!pip install --no-deps /kaggle/input/ns64-imc2025lib/ns64_imc2025lib-0.1.50-py3-none-any.whl","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T13:54:45.533637Z","iopub.execute_input":"2025-05-22T13:54:45.533973Z","iopub.status.idle":"2025-05-22T13:54:49.020596Z","shell.execute_reply.started":"2025-05-22T13:54:45.533944Z","shell.execute_reply":"2025-05-22T13:54:49.019662Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!pip install --no-deps /kaggle/input/ns64-imc2025lib/addict-2.4.0-py3-none-any.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/asmk-0.1-cp311-cp311-linux_x86_64.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/attrs-25.3.0-py3-none-any.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/cholespy-2.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/croco-0.1.2-py3-none-any.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/curope-0.0.0-cp311-cp311-linux_x86_64.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/dad-0.2.0-py3-none-any.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/dedode-0.0.1-py3-none-any.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/dotmap-1.3.30-py3-none-any.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/dsine-0.0.0-py3-none-any.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/dust3r-0.1.0-py3-none-any.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/e2cnn-0.2.3-py3-none-any.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/einops-0.8.1-py3-none-any.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/faiss_cpu-1.10.0-cp311-cp311-manylinux_2_28_x86_64.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/flask-3.1.0-py3-none-any.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/glcontext-3.0.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/hloc-1.5-py3-none-any.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/HTML4Vision-0.5.0-py2.py3-none-any.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/huggingface_hub-0.30.2-py3-none-any.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/hydra_core-1.3.2-py3-none-any.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/iglovikov_helper_functions-0.0.53-py2.py3-none-any.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/kornia_moons-0.2.9-py3-none-any.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/lightglue-0.0-py3-none-any.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/lightning-2.5.1-py3-none-any.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/loguru-0.7.3-py3-none-any.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/mast3r-0.1.0-py3-none-any.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/mmengine-0.10.7-py3-none-any.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/moderngl-5.12.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/moge-1.0.0-py3-none-any.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/mono-0.0.0-py3-none-any.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/mpsfm-0.1.0-py3-none-any.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/plyfile-1.1-py3-none-any.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/pyceres-2.4-cp311-cp311-manylinux_2_28_x86_64.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/pycolmap-3.11.1-cp311-cp311-manylinux_2_28_x86_64.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/superglue_pretrained_network-0.0.0-py3-none-any.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/utils3d-0.0.2-py3-none-any.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/vggt-0.0.1-py3-none-any.whl\n!pip install --no-deps /kaggle/input/ns64-imc2025lib/yacs-0.1.8-py3-none-any.whl","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T13:54:49.022088Z","iopub.execute_input":"2025-05-22T13:54:49.022355Z","iopub.status.idle":"2025-05-22T13:55:51.649676Z","shell.execute_reply.started":"2025-05-22T13:54:49.022325Z","shell.execute_reply":"2025-05-22T13:55:51.64896Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!mkdir -p hf_grounding_dino_base\n!mkdir -p hf_sam_vit_base\n!mkdir -p hf_vggt_1b\n!mkdir -p siglip2_so400m_patch14_384\n\n!ln -s /kaggle/input/imc2023models/grounded_sam/models--IDEA-Research--grounding-dino-base/blobs/5548f844c928c4b6f411fa8cbcc2bfa8dbbba437cb1d513975519f93c2a9ed21 ./hf_grounding_dino_base/model.safetensors\n!ln -s /kaggle/input/imc2023models/grounded_sam/models--IDEA-Research--grounding-dino-base/blobs/5a7f6206a1e488c54316e1f594311dd47a03a41b ./hf_grounding_dino_base/config.json\n!ln -s /kaggle/input/imc2023models/grounded_sam/models--IDEA-Research--grounding-dino-base/blobs/5cb45d963917ed130ce46a93204b349cbec21131 ./hf_grounding_dino_base/preprocessor_config.json\n!ln -s /kaggle/input/imc2023models/grounded_sam/models--IDEA-Research--grounding-dino-base/blobs/688882a79f44442ddc1f60d70334a7ff5df0fb47 ./hf_grounding_dino_base/tokenizer.json\n!ln -s /kaggle/input/imc2023models/grounded_sam/models--IDEA-Research--grounding-dino-base/blobs/a8b3208c2884c4efb86e49300fdd3dc877220cdf ./hf_grounding_dino_base/special_tokens_map.json\n!ln -s /kaggle/input/imc2023models/grounded_sam/models--IDEA-Research--grounding-dino-base/blobs/ed97a84add5f9b2091e756765ad3ba087a345e17 ./hf_grounding_dino_base/tokenizer_config.json\n!ln -s /kaggle/input/imc2023models/grounded_sam/models--IDEA-Research--grounding-dino-base/blobs/fb140275c155a9c7c5a3b3e0e77a9e839594a938 ./hf_grounding_dino_base/vocab.txt\n\n!ln -s /kaggle/input/imc2023models/grounded_sam/models--facebook--sam-vit-base/blobs/5880e4f874dbeb2a1921c9cf3bb44da529e46bf4 ./hf_sam_vit_base/config.json\n!ln -s /kaggle/input/imc2023models/grounded_sam/models--facebook--sam-vit-base/blobs/732fbaf0c512b97d8d9161f51bc157bfb2873d12 ./hf_sam_vit_base/preprocessor_config.json\n!ln -s /kaggle/input/imc2023models/grounded_sam/models--facebook--sam-vit-base/blobs/892c410e496344e527255ccdcb2cb7244a609acb5389c7c4fdba1288f861c579 ./hf_sam_vit_base/model.safetensors\n\n!ln -s /kaggle/input/imc2025models/models--facebook--VGGT-1B/blobs/303bf21400e2723e8ff9c0c7ceb6d86859b1ddeb ./hf_vggt_1b/config.json\n!ln -s /kaggle/input/imc2025models/models--facebook--VGGT-1B/blobs/f164acf60724910d8fe1578bb499d800850c7bb0948db7555c413f9fbe60467e ./hf_vggt_1b/model.safetensors\n\n!ln -s /kaggle/input/imc2025models/models--google--siglip2-so400m-patch14-384/blobs/7c1e0ed1759922fc4eb362d3b405958e829f364d ./siglip2_so400m_patch14_384/config.json\n!ln -s /kaggle/input/imc2025models/models--google--siglip2-so400m-patch14-384/blobs/e9e084ab5a0d74573432f1dcf11c1bdd8d9b3655 ./siglip2_so400m_patch14_384/preprocessor_config.json\n!ln -s /kaggle/input/imc2025models/models--google--siglip2-so400m-patch14-384/blobs/9f4f4a49f908ef0c979bce8ff5a5c0e88882dc6c5dc4304387cbbd152558e2c2 ./siglip2_so400m_patch14_384/model.safetensors","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T13:57:31.743788Z","iopub.execute_input":"2025-05-22T13:57:31.744624Z","iopub.status.idle":"2025-05-22T13:57:33.899382Z","shell.execute_reply.started":"2025-05-22T13:57:31.744596Z","shell.execute_reply":"2025-05-22T13:57:33.8986Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import numpy as np\nimport yaml\nimport os\nimport sys\nsys.path.insert(0, '/usr/local/lib/python3.11/dist-packages/ns64_imc2025lib')\nos.environ[\"OPEN3D_DISABLE_WEB_VISUALIZER\"] = \"true\"\nos.environ['DEFAULT_DATASET_DIR'] = '/kaggle/input/image-matching-challenge-2025'\nos.environ['DEFAULT_TMP_DIR'] = '/kaggle/tmp'\nos.environ['DEFAULT_MODEL_LIST_PATH'] = '/kaggle/input/ns64-imc2025lib/models.yaml'\nos.environ[\"TRANSFORMERS_OFFLINE\"] = \"1\"\nos.environ[\"HF_HUB_OFFLINE\"] = \"1\"\n#os.environ['DEFAULT_MODEL_LIST_PATH'] = '/kaggle/input/imc2023models/models.yaml'\n#os.environ['SCENE_SPACE_DIR_PERSISTENT'] = 'yes'","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T13:57:35.263262Z","iopub.execute_input":"2025-05-22T13:57:35.263978Z","iopub.status.idle":"2025-05-22T13:57:35.289889Z","shell.execute_reply.started":"2025-05-22T13:57:35.26395Z","shell.execute_reply":"2025-05-22T13:57:35.289232Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"os.environ['CUBLAS_WORKSPACE_CONFIG'] = ':4096:8'\nimport torch\ntorch.use_deterministic_algorithms(True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T13:57:40.825318Z","iopub.execute_input":"2025-05-22T13:57:40.82579Z","iopub.status.idle":"2025-05-22T13:57:44.946162Z","shell.execute_reply.started":"2025-05-22T13:57:40.82576Z","shell.execute_reply":"2025-05-22T13:57:44.945429Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from ns64_imc2025lib.config import SubmissionConfig\nfrom ns64_imc2025lib.kernel import run_and_save_submission\nfrom ns64_imc2025lib.data import on_kaggle_kernel_rerun","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T13:57:44.947351Z","iopub.execute_input":"2025-05-22T13:57:44.947975Z","iopub.status.idle":"2025-05-22T13:58:15.946299Z","shell.execute_reply.started":"2025-05-22T13:57:44.947949Z","shell.execute_reply":"2025-05-22T13:58:15.945681Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"conf = SubmissionConfig.load_config_from_pipeline_config_string(\"\"\"\n# conf/pipeline/imc2025/mast3rhybrid/mast3rhybrid-022-b.yaml\n# ------------------------------------\n# ------------------------------------\ntype: imc2025\n\nimc2025_pipeline:\n  point_tracking_matchers:\n    - type: mast3r_hybrid\n      impl_version: v2\n      local_features:\n        - type: lightglue_aliked\n          lightglue_aliked:\n            weight_path: ALIKED_LIGHTGLUE_N16\n            max_num_keypoints: 4096\n          resize:\n            func: lightglue\n            lg_resize: 1280\n        - type: magicleap_superpoint\n          magicleap_superpoint:\n            weight_path: MAGICLEAP_SUPERPOINT\n            nms_radius: 4\n            keypoint_threshold: 0.0005\n            max_keypoints: 4096\n            remove_borders: 4\n            fix_sampling: true\n          resize:\n            func: magicleap\n            ml_resize: 1600\n      mast3r_hybrid:\n        size: 512\n        dense_min_matches: 15\n        dense_subsample: 8\n        dense_pixel_tol: 5\n        dense_match_threshold: 1.001\n        dense_match_topk: null  # Use all\n        sparse_min_matches: 15\n        sparse_match_threshold: 1.001\n        sparse_match_topk: null  \n        model:\n          use_amp: true\n          weight_path: MAST3R\n\n  shortlist_generator: \n    type: ensemble\n    ensemble:\n      all_pairs_fallback_threshold: 0\n      shortlist_generators:\n        - type: mast3r_retrieval_asmk\n          mast3r_retrieval_asmk_fallback_threshold: 0\n          mast3r_retrieval_asmk_remove_swapped_pairs: true\n          mast3r_retrieval_asmk_make_pairs_fps_n: 10\n          mast3r_retrieval_asmk_make_pairs_fps_k: 25\n          mast3r_retrieval_asmk_make_pairs_fps_dist_threshold: null\n          mast3r_retrieval_asmk:\n            mast3r:\n              weight_path: MAST3R\n              retrieval_weight_path: MAST3R_RETRIEVAL\n              retrieval_codebook_path: MAST3R_RETRIEVAL_CODEBOOK\n        - type: global_desc\n          global_desc_model: mast3r_retrieval_spoc\n          global_desc_batch_size: 1\n          global_desc_num_workers: 1\n          global_desc_similar_distance_threshold: 9999\n          global_desc_topk: 10\n          global_desc_fallback_threshold: 0\n          global_desc_remove_swapped_pairs: true\n          global_desc_num_refills_when_no_matches: 10\n          mast3r_retrieval_spoc:\n            mast3r:\n              weight_path: MAST3R\n              retrieval_weight_path: MAST3R_RETRIEVAL\n              retrieval_codebook_path: MAST3R_RETRIEVAL_CODEBOOK\n            global_desc_type: retrieval_spoc\n        - type: global_desc\n          global_desc_model: dinov2\n          global_desc_batch_size: 1\n          global_desc_num_workers: 1\n          global_desc_similar_distance_threshold: 9999\n          global_desc_topk: 10\n          global_desc_fallback_threshold: 0\n          global_desc_remove_swapped_pairs: true\n          global_desc_num_refills_when_no_matches: 10\n          dinov2:\n            pretrained_model: DINOV2_BASE\n        - type: global_desc\n          global_desc_model: isc\n          global_desc_batch_size: 1\n          global_desc_num_workers: 1\n          global_desc_similar_distance_threshold: 9999\n          global_desc_topk: 10\n          global_desc_fallback_threshold: 0\n          global_desc_remove_swapped_pairs: true\n          global_desc_num_refills_when_no_matches: 10\n          isc:\n            weight_path: ISC\n  \n  reconstruction:\n    fill_zero_Rt: false\n    fill_nan_Rt: false\n    fill_nearest_position: false\n    mapper_min_model_size: 3\n    mapper_max_num_models: 25\n  \n  clustering: null\n\"\"\")\nprint(conf.model_dump_json(indent=4))\n\nwith open(\"config.yaml\", \"w\") as fp:\n    yaml.safe_dump(conf.model_dump(), fp)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T13:58:16.801672Z","iopub.execute_input":"2025-05-22T13:58:16.802784Z","iopub.status.idle":"2025-05-22T13:58:16.855859Z","shell.execute_reply.started":"2025-05-22T13:58:16.80276Z","shell.execute_reply":"2025-05-22T13:58:16.855107Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!PYTHONPATH=/usr/local/lib/python3.11/dist-packages/ns64_imc2025lib:$PYTHONPATH OMP_NUM_THREADS=1 MKL_NUM_THREADS=1 \\\n LD_LIBRARY_PATH=./glomap_lib:$LD_LIBRARY_PATH \\\n OPEN3D_DISABLE_WEB_VISUALIZER=true HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1 DEFAULT_DATASET_DIR=/kaggle/input/image-matching-challenge-2025 \\\n CUBLAS_WORKSPACE_CONFIG=':4096:8' \\\n DEFAULT_TMP_DIR=/kaggle/tmp DEFAULT_MODEL_LIST_PATH=/kaggle/input/ns64-imc2025lib/models.yaml \\\n torchrun --nnodes 1 --nproc_per_node 2 --standalone -m ns64_imc2025lib.kernel -c config.yaml --env-name kernel --dist --kaggle-submit","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T13:59:05.491867Z","iopub.execute_input":"2025-05-22T13:59:05.492191Z","iopub.status.idle":"2025-05-22T14:03:31.285876Z","shell.execute_reply.started":"2025-05-22T13:59:05.492167Z","shell.execute_reply":"2025-05-22T14:03:31.284917Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"RUN_SINGLE_PROCESS = False\nif RUN_SINGLE_PROCESS:\n    print(\"RUN_SINGLE_PROCESS=True\")\n    if on_kaggle_kernel_rerun():\n        run_and_save_submission(conf)\n    else:\n        conf.target_data_type = 'submission-fast-commit'\n        run_and_save_submission(conf)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T14:03:53.583551Z","iopub.execute_input":"2025-05-22T14:03:53.584233Z","iopub.status.idle":"2025-05-22T14:03:53.588637Z","shell.execute_reply.started":"2025-05-22T14:03:53.584204Z","shell.execute_reply":"2025-05-22T14:03:53.587894Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!ls submission.csv","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-22T14:03:54.803567Z","iopub.execute_input":"2025-05-22T14:03:54.804335Z","iopub.status.idle":"2025-05-22T14:03:54.957438Z","shell.execute_reply.started":"2025-05-22T14:03:54.804299Z","shell.execute_reply":"2025-05-22T14:03:54.956647Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}