{"cells":[{"metadata":{},"cell_type":"markdown","source":"It looks like distractors are present in the test dataset.","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"from PIL import Image","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"Image.open('../input/landmark-recognition-2020/test/0/0/0/000b15b043eb8cf0.jpg')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Doesn't look like a landmark to me ;)\n\nFun tip: you can use Google Image search to look for landmark ids of some images from test dataset. Let's test it with both the image above and the more \"landmarky\" one below.","execution_count":null},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"Image.open('../input/landmark-recognition-2020/test/0/0/0/00084cdf8f600d00.jpg')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Search results for the first image:\nhttps://www.google.com/search?tbs=sbi:AMhZZitbSNBbwBc_1Es7LNl5gOW-G7Pazc1FYd7uFt2dIOvkDfVoTuVGeaaadUERLmlqNiS9ypYPOMCgt7UFV2_1U_1fsrgb1i12bdPJEBCIumBz-r1lLnEij7MN-b7miIzzuK4Okx2WFDxQ9ANToQ4W-hvbx3MTo4p3yyaRI4IzVXX2Qm091HqIBdAZqjB0TzLM4kN2IfMn6JijsTS3iFR7A2qexnH1qjXxceRCCgwy5rkDOtaL4Z9Ewr_1A1Vkbl_1u1FeaxO-Eu0BUh4_1-reE_14E4QX2QETvoDBhA8CWX96WnmGNIaUw2nW4X1hfvtqmRldLX1ohA8WWz5mTruDAKJdPrDZbfQB4ZVBA&hl=pl\n\nSearch results for the second image:\nhttps://www.google.com/search?tbs=sbi:AMhZZiu7KXNSsTANv1lQrar5V4TrL4UaDLz5-ZCUs1TvL7wj6XuELzoBJ7YuEzCt2_15pvxSwkXaa9e4f51lJ48I_1lHnNm7KGcnvPfAJBskn1FwNHEYGtCoIu_1n_1k3y0CwSJMB5k9x16SlZI0PjWhmKXlNcnNwtYpX354dXft3Bwrz92ucb1L7uqB3pdktj6C-4tR5v73lnmBG2SpTwTRxmNmuXMr1aMY6vn03WT-kqyHpnZnGIbhb3lg9jtKd7tT3oCUhKqce3G_1yk2d-uP8L-Kxj0wAs311-Athv-sWiiOeOvjw0aYIhFgMLa-9xv57NiF8ZERRnNUC9PqjauzeXI6G8DQb4J5Z2A&hl=pl","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"It looks like first image is a picture of Italian actress Gaia Germani and the second image is a landmark indeed - it's Saint Nicolas Tower located in France.","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"But maybe Gaia Germani is also a landmark ;)\n\nActually, there is a way to check that. If you click on photos of Gaia Germani and Saint Nicolas Tower on Wikipedia, you can find out that they correspond to the following categories:\n\nGaia Germani\n- http://commons.wikimedia.org/wiki/Category:I_complessi\n- http://commons.wikimedia.org/wiki/Category:Films_by_Luigi_Filippo_D%27Amico\n- http://commons.wikimedia.org/wiki/Category:1965_films\n- http://commons.wikimedia.org/wiki/Category:Gaia_Germani\n\nSaint Nicolas Tower:\n- http://commons.wikimedia.org/wiki/Category:Tour_Saint-Nicolas","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"Google published mapping from train landmark ids to those categories. It's available at https://s3.amazonaws.com/google-landmark/metadata/train_label_to_category.csv\n\nLet's download it and load into pandas to see whether we can find correct landmark ids.","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"!wget https://s3.amazonaws.com/google-landmark/metadata/train_label_to_category.csv","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"TRAIN_LABEL_TO_CATEGORY = 'train_label_to_category.csv'\n\nGAIA_CATEGORIES = [\n    'http://commons.wikimedia.org/wiki/Category:I_complessi',\n    'http://commons.wikimedia.org/wiki/Category:Films_by_Luigi_Filippo_D%27Amico',\n    'http://commons.wikimedia.org/wiki/Category:1965_films',\n    'http://commons.wikimedia.org/wiki/Category:Gaia_Germani'\n]\n\nTOWER_CATEGORIES = [\n    'http://commons.wikimedia.org/wiki/Category:Tour_Saint-Nicolas'\n]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import pandas as pd","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df = pd.read_csv(TRAIN_LABEL_TO_CATEGORY)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"landmark_categories = set(df.category.values)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Now, that all category names are loaded, let's check whether Gaia Germani or Saint Nicolas Tower is indeed a landmark.","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"gaia_is_landmark = False\n\nfor cat_name in GAIA_CATEGORIES:\n    if cat_name in landmark_categories:\n        gaia_is_landmark = True\n\nif gaia_is_landmark:\n    print('Gaia Germani IS a landmark')\nelse:\n    print('Gaia Germani IS NOT a landmark')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"tower_is_landmark = False\n\nfor cat_name in TOWER_CATEGORIES:\n    if cat_name in landmark_categories:\n        tower_is_landmark = True\n\nif tower_is_landmark:\n    print('Saint Nicolas Tower IS a landmark')\nelse:\n    print('Saint Nicolas Tower IS NOT a landmark')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"This experiment shows that, with high confidence, distractors are indeed present in the test dataset. You should avoid making any predictions for such distractors, since it will lower your Leaderboard score.","execution_count":null}],"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}