{"cells":[{"metadata":{},"cell_type":"markdown","source":"Check this discussion for more details: https://www.kaggle.com/c/landmark-retrieval-2020/discussion/163390","execution_count":null},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# Load dependencies\nimport urllib.parse\nimport pandas as pd\nimport tensorflow as tf\nimport matplotlib.pyplot as plt\n\nPATH = '../input/landmark-retrieval-2020/'\n\n# Get labels\nlabels = pd.read_csv(PATH+'train.csv', index_col='id')['landmark_id'].to_dict()\n\n# Download csn and get classes\nurl = 'https://s3.amazonaws.com/google-landmark/metadata/train_label_to_category.csv'\nCLASSES = pd.read_csv(url, index_col = 'landmark_id', encoding='latin', engine='python')['category'].to_dict()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"# Input image\nimage_id = 'cd41bf948edc0340' # try changing this id to see a different landmark and its name\nimage_path = f'{PATH}/train/{image_id[0]}/{image_id[1]}/{image_id[2]}/{image_id}.jpg'\n\n# Read file and decode\nimage = tf.io.read_file(image_path)\nimage = tf.image.decode_jpeg(image, channels=3)\nimage = tf.cast(image, tf.int64)\n\n# Identify the landmark id and name\nlandmark_id = labels[image_id]\nlandmark_name = urllib.parse.unquote(CLASSES[labels[image_id]].replace('http://commons.wikimedia.org/wiki/Category:', ''))\ntitle = f'{landmark_id}: {landmark_name}'\nprint (title)\n\n# Show the image with title\nplt.figure(figsize=(20,10))\nplt.axis('off')\nplt.imshow(image)\nplt.title(title, fontsize=16)\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}