{"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":"none","dataSources":[{"sourceId":71885,"databundleVersionId":8143495,"sourceType":"competition"}],"dockerImageVersionId":30673,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nimport random\n\nfrom pathlib import Path","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-04-05T09:59:49.382522Z","iopub.execute_input":"2024-04-05T09:59:49.382916Z","iopub.status.idle":"2024-04-05T09:59:50.524610Z","shell.execute_reply.started":"2024-04-05T09:59:49.382888Z","shell.execute_reply":"2024-04-05T09:59:50.523440Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train = pd.read_csv(\"../input/image-matching-challenge-2024/train/train_labels.csv\")\n\n# add image_path\ndf_train[\"image_path\"] = Path(\"train\") / df_train[\"dataset\"] / \"images\" / df_train[\"image_name\"]\n\nprint(\"*** initial scene count ***\")\nprint(df_train[\"scene\"].value_counts())\n\n# remove temple_of_ba_al_shamin_palmyra_syria.png\ndf_train = df_train[df_train[\"image_name\"] != \"temple_of_ba_al_shamin_palmyra_syria.png\"]\n# remove temle_ba_al_shamin_4.png\ndf_train = df_train[df_train[\"image_name\"] != \"temle_ba_al_shamin_4.png\"]\n\nprint(\"*** after remove duplicated image_path ***\")\nprint(df_train[\"scene\"].value_counts())\n\n# remove row if image_path does not exist\n# https://www.kaggle.com/competitions/image-matching-challenge-2024/discussion/487806\nfor idx, row in df_train.iterrows():\n    image_path = row[\"image_path\"]\n    if not Path(f\"../input/image-matching-challenge-2024/{image_path}\").exists():\n        df_train.drop(idx, inplace=True)\n\nprint(\"*** after remove row ***\")\nprint(df_train[\"scene\"].value_counts())\n\n# randomly reduce size just to speed-up the examples\n\nn = 55 # expected number of cameras per scenes\n\nscene_count = {}\nfor scene in df_train[\"scene\"].unique():\n    scene_count[scene] = len(df_train[df_train[\"scene\"] == scene])\n\nfor idx, row in df_train.iterrows():\n    if random.random() > n / scene_count[row[\"dataset\"]]:\n        df_train.drop(idx, inplace=True)\n\nprint(\"*** final scene count ***\")\nprint(df_train[\"scene\"].value_counts())\n\n# save as a further csv\ndf_train.to_csv(\"validation.csv\", index=False, index_label=False)","metadata":{"execution":{"iopub.status.busy":"2024-04-05T09:59:54.487636Z","iopub.execute_input":"2024-04-05T09:59:54.488438Z","iopub.status.idle":"2024-04-05T10:00:01.943977Z","shell.execute_reply.started":"2024-04-05T09:59:54.488403Z","shell.execute_reply":"2024-04-05T10:00:01.942703Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}