{"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 numpy as np\nimport pandas as pd\nfrom pandas import Series\nimport matplotlib\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom PIL import Image\nimport cv2\n\nimport h5py","metadata":{"execution":{"iopub.status.busy":"2022-12-23T14:59:27.855407Z","iopub.execute_input":"2022-12-23T14:59:27.856578Z","iopub.status.idle":"2022-12-23T14:59:27.861513Z","shell.execute_reply.started":"2022-12-23T14:59:27.856540Z","shell.execute_reply":"2022-12-23T14:59:27.860107Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.listdir('../input/landmark-recognition-2021/')","metadata":{"execution":{"iopub.status.busy":"2022-12-23T14:51:48.529624Z","iopub.execute_input":"2022-12-23T14:51:48.529991Z","iopub.status.idle":"2022-12-23T14:51:48.539427Z","shell.execute_reply.started":"2022-12-23T14:51:48.529962Z","shell.execute_reply":"2022-12-23T14:51:48.538258Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BASE_PATH = '../input/landmark-recognition-2021'\n\nTRAIN_DIR = f'{BASE_PATH}/train'\nTEST_DIR = f'{BASE_PATH}/test'\n\nprint('Reading data...')\ntrain = pd.read_csv(f'{BASE_PATH}/train.csv')\nsubmission = pd.read_csv(f'{BASE_PATH}/sample_submission.csv')\nprint('Reading data completed')","metadata":{"execution":{"iopub.status.busy":"2022-12-23T14:51:49.962959Z","iopub.execute_input":"2022-12-23T14:51:49.963323Z","iopub.status.idle":"2022-12-23T14:51:51.453077Z","shell.execute_reply.started":"2022-12-23T14:51:49.963290Z","shell.execute_reply":"2022-12-23T14:51:51.451731Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Shape of Train data: \", train.shape)\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2022-12-23T14:51:52.836256Z","iopub.execute_input":"2022-12-23T14:51:52.836620Z","iopub.status.idle":"2022-12-23T14:51:52.852363Z","shell.execute_reply.started":"2022-12-23T14:51:52.836588Z","shell.execute_reply":"2022-12-23T14:51:52.850959Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"unique_landmarks = train.landmark_id.value_counts()\nunique_landmarks = Series.to_frame(unique_landmarks)\nunique_landmarks = unique_landmarks.reset_index()\nunique_landmarks.rename(columns = {'index':'landmark_id', 'landmark_id': 'frequency'}, inplace = True)\nunique_landmarks","metadata":{"execution":{"iopub.status.busy":"2022-12-23T14:51:55.335968Z","iopub.execute_input":"2022-12-23T14:51:55.337227Z","iopub.status.idle":"2022-12-23T14:51:55.397138Z","shell.execute_reply.started":"2022-12-23T14:51:55.337186Z","shell.execute_reply":"2022-12-23T14:51:55.395672Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# unique_landmarks_df = pd.DataFrame({'landmark_id':unique_landmarks.index, 'frequency':unique_landmarks.values}).head(15)\n# unique_landmarks_df = unique_landmarks_df.sort_values('frequency', ascending = False).reset_index(drop=True)\ndf = unique_landmarks.head(20)\ndf","metadata":{"execution":{"iopub.status.busy":"2022-12-23T14:51:57.467892Z","iopub.execute_input":"2022-12-23T14:51:57.469117Z","iopub.status.idle":"2022-12-23T14:51:57.478531Z","shell.execute_reply.started":"2022-12-23T14:51:57.469064Z","shell.execute_reply":"2022-12-23T14:51:57.477581Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.barplot(data=df, x=\"frequency\", y=\"landmark_id\", orient=\"h\")","metadata":{"execution":{"iopub.status.busy":"2022-12-23T14:51:59.715132Z","iopub.execute_input":"2022-12-23T14:51:59.715504Z","iopub.status.idle":"2022-12-23T14:52:00.019365Z","shell.execute_reply.started":"2022-12-23T14:51:59.715469Z","shell.execute_reply":"2022-12-23T14:52:00.018030Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['frequency'][0]","metadata":{"execution":{"iopub.status.busy":"2022-12-23T14:52:01.596005Z","iopub.execute_input":"2022-12-23T14:52:01.596349Z","iopub.status.idle":"2022-12-23T14:52:01.603133Z","shell.execute_reply.started":"2022-12-23T14:52:01.596321Z","shell.execute_reply":"2022-12-23T14:52:01.602293Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"one = 0    #0-100\ntwo = 0    #100-500\nthree = 0  #500-1000\nfour = 0   #1000-2000\nfive = 0   #2000-3000\nsix = 0    #3000-40000\nseven = 0  #4000-50000\neight = 0  #5000-60000\nnine = 0   #6000-70000\n\nfor i in range(len(unique_landmarks['frequency'])):\n    if unique_landmarks['frequency'][i]<100:\n        one += 1\n    elif unique_landmarks['frequency'][i]<500:\n        two += 1\n    elif unique_landmarks['frequency'][i]<1000:\n        three += 1\n    elif unique_landmarks['frequency'][i]<2000:\n        four += 1\n    elif unique_landmarks['frequency'][i]<3000:\n        five += 1\n    elif unique_landmarks['frequency'][i]<4000:\n        six += 1\n    elif unique_landmarks['frequency'][i]<5000:\n        seven += 1\n    elif unique_landmarks['frequency'][i]<6000:\n        eight += 1\n    elif unique_landmarks['frequency'][i]<7000:\n        nine += 1\n        \nhist_dict = {'0-100':one, '100-500':two, '500-1000':three, '1000-2000':four, '2000-3000':five, '3000-4000':six, '4000-5000':seven, '5000-6000':eight, '6000-7000':nine}","metadata":{"execution":{"iopub.status.busy":"2022-12-23T14:56:02.178536Z","iopub.execute_input":"2022-12-23T14:56:02.178873Z","iopub.status.idle":"2022-12-23T14:56:02.664918Z","shell.execute_reply.started":"2022-12-23T14:56:02.178845Z","shell.execute_reply":"2022-12-23T14:56:02.663882Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_dist = pd.DataFrame.from_dict(hist_dict, orient='index', columns=['numOfSamples']).reset_index()\nimg_dist.rename(columns = {'index':'numOfSamples-range', 'numOfSamples': 'numOfLandmarks'}, inplace = True)\nimg_dist","metadata":{"execution":{"iopub.status.busy":"2022-12-23T14:56:09.798330Z","iopub.execute_input":"2022-12-23T14:56:09.799438Z","iopub.status.idle":"2022-12-23T14:56:09.811078Z","shell.execute_reply.started":"2022-12-23T14:56:09.799388Z","shell.execute_reply":"2022-12-23T14:56:09.810141Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.barplot(data=img_dist, y=\"numOfSamples-range\", x=\"numOfLandmarks\", orient=\"h\")","metadata":{"execution":{"iopub.status.busy":"2022-12-23T14:56:13.949584Z","iopub.execute_input":"2022-12-23T14:56:13.949960Z","iopub.status.idle":"2022-12-23T14:56:14.144697Z","shell.execute_reply.started":"2022-12-23T14:56:13.949930Z","shell.execute_reply":"2022-12-23T14:56:14.143504Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def display_images(images, title=None): \n    f, ax = plt.subplots(5,5, figsize=(18,22))\n    if title:\n        f.suptitle(title, fontsize = 30)\n\n    for i, image_id in enumerate(images):\n        image_path = os.path.join(TRAIN_DIR, f'{image_id[0]}/{image_id[1]}/{image_id[2]}/{image_id}.jpg')\n        image = Image.open(image_path)\n        \n        ax[i//5, i%5].imshow(image) \n        image.close()       \n        ax[i//5, i%5].axis('off')\n\n        landmark_id = train[train.id==image_id.split('.')[0]].landmark_id.values[0]\n        ax[i//5, i%5].set_title(f\"ID: {image_id.split('.')[0]}\\nLandmark_id: {landmark_id}\", fontsize=\"12\")\n\n    plt.show() ","metadata":{"execution":{"iopub.status.busy":"2022-12-23T14:58:31.301008Z","iopub.execute_input":"2022-12-23T14:58:31.301380Z","iopub.status.idle":"2022-12-23T14:58:31.309895Z","shell.execute_reply.started":"2022-12-23T14:58:31.301351Z","shell.execute_reply":"2022-12-23T14:58:31.308535Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"samples = train.sample(25).id.values\ndisplay_images(samples)","metadata":{"execution":{"iopub.status.busy":"2022-12-23T15:01:53.147259Z","iopub.execute_input":"2022-12-23T15:01:53.147938Z","iopub.status.idle":"2022-12-23T15:01:58.708293Z","shell.execute_reply.started":"2022-12-23T15:01:53.147905Z","shell.execute_reply":"2022-12-23T15:01:58.707506Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"samples = train[train.landmark_id == 89894].sample(25).id.values\ndisplay_images(samples)","metadata":{"execution":{"iopub.status.busy":"2022-12-23T15:00:46.296766Z","iopub.execute_input":"2022-12-23T15:00:46.297191Z","iopub.status.idle":"2022-12-23T15:00:51.865805Z","shell.execute_reply.started":"2022-12-23T15:00:46.297157Z","shell.execute_reply":"2022-12-23T15:00:51.864664Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}