{"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":"none","dataSources":[{"sourceId":91498,"databundleVersionId":11655853,"sourceType":"competition"}],"dockerImageVersionId":31012,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\nfrom pathlib import Path\nimport random\nfrom PIL import Image\nimport matplotlib.pyplot as plt","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-05-11T11:11:34.210930Z","iopub.execute_input":"2025-05-11T11:11:34.211303Z","iopub.status.idle":"2025-05-11T11:11:34.215797Z","shell.execute_reply.started":"2025-05-11T11:11:34.211277Z","shell.execute_reply":"2025-05-11T11:11:34.214812Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"fpath = Path(\"/kaggle/input/image-matching-challenge-2025\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-11T10:39:56.576646Z","iopub.execute_input":"2025-05-11T10:39:56.577035Z","iopub.status.idle":"2025-05-11T10:39:56.583038Z","shell.execute_reply.started":"2025-05-11T10:39:56.577008Z","shell.execute_reply":"2025-05-11T10:39:56.581323Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"TEST_DIR = fpath / \"test\"\nTRAIN_DIR = fpath / \"train\"\nSAM_SUB = pd.read_csv(fpath / \"sample_submission.csv\")\nLABELS_TRAIN = pd.read_csv(fpath / \"train_labels.csv\")\nTHRESH_TRAIN = pd.read_csv(fpath / \"train_thresholds.csv\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-11T11:02:19.162306Z","iopub.execute_input":"2025-05-11T11:02:19.162646Z","iopub.status.idle":"2025-05-11T11:02:19.208402Z","shell.execute_reply.started":"2025-05-11T11:02:19.162621Z","shell.execute_reply":"2025-05-11T11:02:19.207535Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"LABELS_TRAIN.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-11T10:42:59.223070Z","iopub.execute_input":"2025-05-11T10:42:59.223389Z","iopub.status.idle":"2025-05-11T10:42:59.236196Z","shell.execute_reply.started":"2025-05-11T10:42:59.223366Z","shell.execute_reply":"2025-05-11T10:42:59.234822Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"LABELS_TRAIN.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-11T10:44:38.546063Z","iopub.execute_input":"2025-05-11T10:44:38.546867Z","iopub.status.idle":"2025-05-11T10:44:38.569763Z","shell.execute_reply.started":"2025-05-11T10:44:38.546835Z","shell.execute_reply":"2025-05-11T10:44:38.568857Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"THRESH_TRAIN.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-11T10:43:31.899081Z","iopub.execute_input":"2025-05-11T10:43:31.899382Z","iopub.status.idle":"2025-05-11T10:43:31.908853Z","shell.execute_reply.started":"2025-05-11T10:43:31.899359Z","shell.execute_reply":"2025-05-11T10:43:31.907880Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"THRESH_TRAIN.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-11T10:49:20.694846Z","iopub.execute_input":"2025-05-11T10:49:20.695175Z","iopub.status.idle":"2025-05-11T10:49:20.706739Z","shell.execute_reply.started":"2025-05-11T10:49:20.695155Z","shell.execute_reply":"2025-05-11T10:49:20.705456Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"os.listdir(fpath)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-11T10:54:43.742191Z","iopub.execute_input":"2025-05-11T10:54:43.742871Z","iopub.status.idle":"2025-05-11T10:54:43.749858Z","shell.execute_reply.started":"2025-05-11T10:54:43.742844Z","shell.execute_reply":"2025-05-11T10:54:43.748976Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"os.listdir(TRAIN_DIR)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-11T11:01:49.495908Z","iopub.execute_input":"2025-05-11T11:01:49.496522Z","iopub.status.idle":"2025-05-11T11:01:49.506551Z","shell.execute_reply.started":"2025-05-11T11:01:49.496470Z","shell.execute_reply":"2025-05-11T11:01:49.505469Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_subdirs = [d for d in os.listdir(TRAIN_DIR) if os.path.isdir(TRAIN_DIR / d)]\n\ndef display_close_triplet_compact():\n    random_subdir = random.choice(train_subdirs)\n    subdir_path = TRAIN_DIR / random_subdir\n    image_files = sorted([f for f in os.listdir(subdir_path) if f.endswith(('.png', '.jpg', '.jpeg'))])\n\n    if len(image_files) >= 3:\n        start_idx = random.randint(0, len(image_files) - 3)\n        selected_files = image_files[start_idx : start_idx + 3]\n\n        plt.figure(figsize=(15, 5))\n        for i, img_file in enumerate(selected_files):\n            img_path = subdir_path / img_file\n            try:\n                img = Image.open(img_path)\n                plt.subplot(1, 3, i + 1)\n                plt.imshow(img)\n                plt.title(f\"{random_subdir}\\n{img_file}\")\n                plt.axis('off')\n            except Exception as e:\n                print(f\"Error loading {img_path}: {e}\")\n                return False\n        plt.tight_layout()\n        plt.show()\n        return True\n    else:\n        print(f\"Not enough images in {random_subdir} for a triplet.\")\n        return False\n\n# Display one such triplet\nprint(\"Close triplet:\")\ndisplay_close_triplet()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-11T11:16:29.728244Z","iopub.execute_input":"2025-05-11T11:16:29.728605Z","iopub.status.idle":"2025-05-11T11:16:31.145773Z","shell.execute_reply.started":"2025-05-11T11:16:29.728580Z","shell.execute_reply":"2025-05-11T11:16:31.144778Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}