{"cells":[{"metadata":{},"cell_type":"markdown","source":"Google Landmark Recognition - Image Shape Distribution\n---\nThe train dataset contains ~1.5 million images in varying shapes. While the majority of the images have an aspect ratio of ~1, some images are in the form of horizontal or vertical strips. This notebook presents some examples of such images. \n\nTraditionally, convolutional neural networks (CNNs), used in the state of the art recognition solutions, are trained on square images. Therefore, the images have to be resized during preprocessing step. The methods (cropping, zeropadding, or a combination of both) used to resize these vertical (or horizontal) strips may affect the performance of CNNs.","execution_count":null},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import os\nimport imageio\nimport tensorflow as tf\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n%matplotlib inline","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# load the train_csv file with the image properties\nbase_dir = '../input/landmark-recognition-2020/'\ntrain_csv = pd.read_csv('../input/landmark-recognition-multiprocessing-image-size/train_featured.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# This swaps the values of xsize with ysize columns as they were assigned wrongly in a previous kernel.\nys_temp = train_csv.xsize.copy()\ntrain_csv.xsize = train_csv.ysize\ntrain_csv.ysize = ys_temp\ndel ys_temp","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_csv.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Xsize vs Ysize\n---","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"g = sns.jointplot(x=\"xsize\", y=\"ysize\", data=train_csv)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print('Range of xsize and ysize:')\nprint('---'*8)\nprint(train_csv.xsize.min(), '<= xsize <=', train_csv.xsize.max())\nprint(train_csv.ysize.min(), '<= ysize <=', train_csv.ysize.max())","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print('The most commonly observed 3 values of xsize and ysize:')\nxcount = train_csv.xsize.value_counts()\nycount = train_csv.ysize.value_counts()\nprint(xcount[:3])\nprint(ycount[:3])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_csv[(train_csv.ysize < 100) & (train_csv.xsize > 600)]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def load_image(idx):\n    impath = base_dir + 'train/' + '/'.join(list(idx[:3])) + '/' + idx + '.jpg'\n    return imageio.imread(impath)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.imshow(load_image(train_csv.loc[43027, 'id']))\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.imshow(load_image(train_csv.loc[491551, 'id']))\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.imshow(load_image(train_csv.loc[1289336, 'id']))\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_csv[(train_csv.xsize < 200) & (train_csv.ysize > 600)]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.imshow(load_image(train_csv.loc[338829, 'id']))\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.imshow(load_image(train_csv.loc[546929, 'id']))\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.imshow(load_image(train_csv.loc[965744, 'id']))\nplt.show()","execution_count":null,"outputs":[]}],"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":4,"nbformat_minor":4}