{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\n#for dirname, _, filenames in os.walk('/kaggle/input'):\n#    for filename in filenames:\n#        print(os.path.join(dirname, filename))\n\n# You can write up to 5GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport cv2\nfrom glob import glob\nimport gc\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n%matplotlib inline\nimport matplotlib.pyplot as plt\nfrom IPython.display import Image,display\nimport seaborn as sns\nimport matplotlib.image as mpimg\nimport scipy.spatial.distance as dist\nfrom sklearn.model_selection import train_test_split\nfrom skimage.measure import compare_ssim\nimport os\n\n#for dirname, _, filenames in os.walk('/kaggle/input'):\n    #for filename in filenames:\n        #print(os.path.join(dirname, filename))\n\n# You can write up to 5GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"tr = pd.read_csv('/kaggle/input/landmark-recognition-2020/train.csv')\ntr.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(tr.landmark_id.nunique())\nprint(np.max(tr.landmark_id))\nprint(np.min(tr.landmark_id))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"tab = tr.landmark_id.value_counts()\nprint(tab.head(5))\nprint(tab.tail(5))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"tr[tr.landmark_id==197219]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"mainPath = '/kaggle/input/landmark-recognition-2020/train/'\nall_img_paths = [y for x in os.walk(mainPath) for y in glob(os.path.join(x[0], '*.jpg'))]\nids = [y for x in os.walk(mainPath) for y in glob(os.path.join(x[0]))]\nall_filenames = []\nfor filepath in all_img_paths:\n    FileName = os.path.basename(filepath)\n    all_filenames.append(FileName)\npath_dict = dict(zip(all_filenames,all_img_paths))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df=pd.DataFrame()\ndf['fname'] = all_filenames\ndf['pname'] = all_img_paths\ndf['id'] = list(map(lambda x: x[:-4], df.fname))\ndf.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(df.shape)\ntrain = pd.merge(tr, df, on = 'id')\ntrain.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"mainPath = '/kaggle/input/landmark-recognition-2020/test/'\nall_img_paths = [y for x in os.walk(mainPath) for y in glob(os.path.join(x[0], '*.jpg'))]\nids = [y for x in os.walk(mainPath) for y in glob(os.path.join(x[0]))]\nall_filenames = []\nfor filepath in all_img_paths:\n    FileName = os.path.basename(filepath)\n    all_filenames.append(FileName)\npath_dict = dict(zip(all_filenames,all_img_paths))\n\ntest=pd.DataFrame()\ntest['fname'] = all_filenames\ntest['pname'] = all_img_paths\nprint(test.head())\n\ntest['id'] = list(map(lambda x: x[:-4], test.fname))\nprint(test.head())","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test.shape","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Have a look of some images from train and test data","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"from PIL import Image\nimage = Image.open(train.pname[0])\nprint(image.size)\ndisplay(image)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"image = Image.open(train.pname[100])\nprint(image.size)\ndisplay(image)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"image = Image.open(test.pname[0])\nprint(image.size)\ndisplay(image)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"image = Image.open(test.pname[100])\nprint(image.size)\ndisplay(image)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#os.listdir('../input/siim-isic-melanoma-classification/jpeg/train/')\ndef imtocsv(data):\n    from PIL import Image\n    nrow = []\n    ncol = []\n    pix = []\n    for j in data.pname:\n        image = Image.open(j)\n        nrow.append(image.size[0])\n        ncol.append(image.size[1])\n        pix.append(image.size[0]*image.size[1])\n    out = {'nrow': nrow, 'ncol': ncol, 'pix':pix}\n    df= pd.DataFrame(out)\n    df.insert(0,'id',data.id,True)\n    return df","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"imd=imtocsv(train.iloc[0:4,:],5)\ntrain_50 = pd.merge(train.iloc[0:4,:], imd, on = 'id')\ntrain_50.head()","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"out=imtocsv(train)\ntrain_50 = pd.merge(train, out, on = 'id')\ntrain_50.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"del out\nout=imtocsv(test)\ntest_50 = pd.merge(test, out, on = 'id')\ntest_50.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_50.to_csv('train_summary.csv', index=False)\ntest_50.to_csv('test_summary.csv', index=False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import matplotlib.pyplot as plt\n%matplotlib inline","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.hist(train_50.pix) # add color='green',bins=20\nplt.xlabel('Pixels')\nplt.ylabel('Freq')\nplt.title('Pixel value distribution in train data')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.hist(test_50.pix) # add color='green',bins=20\nplt.xlabel('Pixels')\nplt.ylabel('Freq')\nplt.title('Pixel value distribution in test data')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"landmark_id == 138982 has maximum count in train data. Let's have a look at the pixel value distribution for this landmark.","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.hist(train_50.pix[train_50.landmark_id == 138982]) # add color='green',bins=20\nplt.xlabel('Pixels')\nplt.ylabel('Freq')\nplt.title('Pixel value distribution in train data with landmark id 138982')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### High and low resolution images in train and test sets","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"print('Maximum number of pixels: ', train_50.pix.max())\nprint('Minimum number of pixels: ', train_50.pix.min())\nprint('Maximum number of pixels: ', test_50.pix.max())\nprint('Minimum number of pixels: ', test_50.pix.min())","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Let's have a look of images with high and low resolution.","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"tmp = train_50.loc[train_50.pix == train_50.pix.max()]\ntmp.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"pname = list(tmp.pname)\nlen(pname)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"7592 Images with high resolution in Train data","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"### Lets go through some imaages in train data with high resolution","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"image = Image.open(pname[0])\nprint(image.size)\ndisplay(image)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"image = Image.open(pname[1])\nprint(image.size)\ndisplay(image)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"image = Image.open(pname[2])\nprint(image.size)\ndisplay(image)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"image = Image.open(pname[7590])\nprint(image.size)\ndisplay(image)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"image = Image.open(pname[7591])\nprint(image.size)\ndisplay(image)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Looks like there might be some relationship between train images with high resolution.\nLet's display multiple images together","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"fig=plt.figure(figsize=(12, 10))\ncolumns = 5\nrows = 5\nfor i in range(1, columns*rows +1):\n    img = Image.open(pname[i])\n    fig.add_subplot(rows, columns, i)\n    plt.imshow(img)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Lets go through some imaages in train data with low resolution","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"tmp = train_50.loc[train_50.pix == train_50.pix.min()]\ntmp.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Only one image with low resolution. ","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"pname = list(tmp.pname)\nprint(len(pname))\nimage = Image.open(pname[0])\nprint(image.size)\ndisplay(image)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"This is the image in training data with low resolation.","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"### Lets go through some imaages in test data with high resolution","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"tmp = test_50.loc[test_50.pix == test_50.pix.max()]\nprint(tmp.head())\npname = list(tmp.pname)\nprint('\\n',len(pname))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"There are 14 images in test data with high resolution.","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"image = Image.open(pname[0])\nprint(image.size)\ndisplay(image)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"image = Image.open(pname[1])\nprint(image.size)\ndisplay(image)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"image = Image.open(pname[13])\nprint(image.size)\ndisplay(image)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"image = Image.open(pname[12])\nprint(image.size)\ndisplay(image)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### There might be some relationship between test images with high resolution.\nLet's display multiple images together","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"fig=plt.figure(figsize=(12, 10))\ncolumns = 4\nrows = 3\nfor i in range(1, columns*rows +1):\n    img = Image.open(pname[i])\n    fig.add_subplot(rows, columns, i)\n    plt.imshow(img)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Lets go through some imaages in test data with low resolution","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"tmp = test_50.loc[test_50.pix == test_50.pix.min()]\nprint(tmp.head())\npname = list(tmp.pname)\nprint('\\n',len(pname))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Only one image in test data with low resolution.","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"image = Image.open(pname[0])\nprint(image.size)\ndisplay(image)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"This is the image with low resolution in test data.","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"train_50.to_csv('landmark_train_facts.csv', index = False)\ntest_50.to_csv('landmark_test_facts.csv', index = False)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Hope you will like this notebook. \n\n\n# Suggestions please...","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"","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}