{"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"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\n\nimport cv2\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt #for plotting\nimport seaborn as sns            #vizualisation\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-09-20T01:12:27.233329Z","iopub.execute_input":"2022-09-20T01:12:27.233996Z","iopub.status.idle":"2022-09-20T01:12:28.400900Z","shell.execute_reply.started":"2022-09-20T01:12:27.233957Z","shell.execute_reply":"2022-09-20T01:12:28.399864Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"DIRE = '../input/landmark-recognition-2020'","metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","execution":{"iopub.status.busy":"2022-09-20T01:13:10.954685Z","iopub.execute_input":"2022-09-20T01:13:10.955083Z","iopub.status.idle":"2022-09-20T01:13:10.959958Z","shell.execute_reply.started":"2022-09-20T01:13:10.955051Z","shell.execute_reply":"2022-09-20T01:13:10.958526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls {DIRE}","metadata":{"execution":{"iopub.status.busy":"2022-09-20T01:13:55.796961Z","iopub.execute_input":"2022-09-20T01:13:55.797347Z","iopub.status.idle":"2022-09-20T01:13:56.836152Z","shell.execute_reply.started":"2022-09-20T01:13:55.797315Z","shell.execute_reply":"2022-09-20T01:13:56.835142Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv(os.path.join(DIRE, 'train.csv'))","metadata":{"execution":{"iopub.status.busy":"2022-09-20T01:14:55.714422Z","iopub.execute_input":"2022-09-20T01:14:55.715150Z","iopub.status.idle":"2022-09-20T01:14:57.457293Z","shell.execute_reply.started":"2022-09-20T01:14:55.715103Z","shell.execute_reply":"2022-09-20T01:14:57.456168Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head(5)","metadata":{"execution":{"iopub.status.busy":"2022-09-20T01:15:10.542061Z","iopub.execute_input":"2022-09-20T01:15:10.542443Z","iopub.status.idle":"2022-09-20T01:15:10.554526Z","shell.execute_reply.started":"2022-09-20T01:15:10.542409Z","shell.execute_reply":"2022-09-20T01:15:10.553566Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(f'Total training images: {len(df)}')","metadata":{"execution":{"iopub.status.busy":"2022-09-20T01:16:24.318393Z","iopub.execute_input":"2022-09-20T01:16:24.318801Z","iopub.status.idle":"2022-09-20T01:16:24.324574Z","shell.execute_reply.started":"2022-09-20T01:16:24.318766Z","shell.execute_reply":"2022-09-20T01:16:24.323361Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(f'Total landmarks in training dataset: {df[\"landmark_id\"].nunique()}')\n","metadata":{"execution":{"iopub.status.busy":"2022-09-20T01:17:42.381753Z","iopub.execute_input":"2022-09-20T01:17:42.382376Z","iopub.status.idle":"2022-09-20T01:17:42.404830Z","shell.execute_reply.started":"2022-09-20T01:17:42.382332Z","shell.execute_reply":"2022-09-20T01:17:42.403863Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Total 81313 landmarks and 1580470 images.\n\n","metadata":{}},{"cell_type":"markdown","source":"# Distribution of All Landmarks\n","metadata":{}},{"cell_type":"code","source":"target_dist = df.groupby('landmark_id', as_index=False)['id'].count().sort_values('id', ascending=False).reset_index(drop=True)\ntarget_dist = target_dist.rename(columns={'id':'count'})\ntarget_dist","metadata":{"execution":{"iopub.status.busy":"2022-09-20T01:20:48.740555Z","iopub.execute_input":"2022-09-20T01:20:48.740948Z","iopub.status.idle":"2022-09-20T01:20:48.914393Z","shell.execute_reply.started":"2022-09-20T01:20:48.740917Z","shell.execute_reply":"2022-09-20T01:20:48.913341Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ad = sns.distplot(df['landmark_id'].value_counts()[:15])\nad.set(xlabel='Landmark Counts', ylabel='Probability Density', title='Distribution of top 15 landmarks')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-09-20T01:22:22.857864Z","iopub.execute_input":"2022-09-20T01:22:22.858225Z","iopub.status.idle":"2022-09-20T01:22:23.090096Z","shell.execute_reply.started":"2022-09-20T01:22:22.858195Z","shell.execute_reply":"2022-09-20T01:22:23.088874Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"let's plot the Probability density of rest of the landmarks\n\n","metadata":{}},{"cell_type":"code","source":"ad = sns.distplot(df['landmark_id'].value_counts()[51:])\nad.set(xlabel='Landmark Counts', ylabel='Probability Density')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-09-20T01:25:11.813087Z","iopub.execute_input":"2022-09-20T01:25:11.813453Z","iopub.status.idle":"2022-09-20T01:25:12.107107Z","shell.execute_reply.started":"2022-09-20T01:25:11.813423Z","shell.execute_reply":"2022-09-20T01:25:12.105804Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# TOP 6 Landmarks","metadata":{}},{"cell_type":"code","source":"def get_image(image_id):\n    img = cv2.imread(os.path.join(os.path.join(DIRE, 'train'), image_id[0], image_id[1], image_id[2], image_id + '.jpg'))\n    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n    return img\n\ndef get_image_id(landmark_id):\n    return df[df['landmark_id'] == landmark_id]['id'][:1].values[0]","metadata":{"execution":{"iopub.status.busy":"2022-09-20T01:27:18.052654Z","iopub.execute_input":"2022-09-20T01:27:18.053054Z","iopub.status.idle":"2022-09-20T01:27:18.060488Z","shell.execute_reply.started":"2022-09-20T01:27:18.053021Z","shell.execute_reply":"2022-09-20T01:27:18.059325Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ad = plt.subplots(nrows=2, ncols=3, figsize=(30, 15))\nad = ad.flatten()\nlandmark_ids = target_dist['landmark_id'][:6].values\n\nfor i in range(6):\n    ad[i].imshow(get_image(get_image_id(landmark_ids[i])))\n    ad[i].grid(False)\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2022-09-20T01:27:25.824109Z","iopub.execute_input":"2022-09-20T01:27:25.824541Z","iopub.status.idle":"2022-09-20T01:27:27.944727Z","shell.execute_reply.started":"2022-09-20T01:27:25.824495Z","shell.execute_reply":"2022-09-20T01:27:27.943382Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# BOTTOM Landmarks","metadata":{}},{"cell_type":"code","source":"fig, ad = plt.subplots(nrows=2, ncols=3, figsize=(30, 15))\nad = ad.flatten()\nlandmark_ids = target_dist['landmark_id'][-6:].values\n\nfor i in range(6):\n    ad[i].imshow(get_image(get_image_id(landmark_ids[i])))\n    ad[i].grid(False)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-09-20T01:30:17.953709Z","iopub.execute_input":"2022-09-20T01:30:17.954748Z","iopub.status.idle":"2022-09-20T01:30:19.745264Z","shell.execute_reply.started":"2022-09-20T01:30:17.954698Z","shell.execute_reply":"2022-09-20T01:30:19.744215Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]}