{"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\nimport random\n\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport cv2","metadata":{"execution":{"iopub.status.busy":"2021-08-15T19:42:43.773390Z","iopub.execute_input":"2021-08-15T19:42:43.773947Z","iopub.status.idle":"2021-08-15T19:42:43.778601Z","shell.execute_reply.started":"2021-08-15T19:42:43.773915Z","shell.execute_reply":"2021-08-15T19:42:43.777555Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#This work is a Tribute to Yaroslav Isaienkov to show all the admiration, respect and gratitude for the work he shared with Kaggle community.","metadata":{}},{"cell_type":"code","source":"os.listdir('../input/landmark-retrieval-2021/')","metadata":{"execution":{"iopub.status.busy":"2021-08-15T19:03:50.350939Z","iopub.execute_input":"2021-08-15T19:03:50.351466Z","iopub.status.idle":"2021-08-15T19:03:50.360389Z","shell.execute_reply.started":"2021-08-15T19:03:50.351434Z","shell.execute_reply":"2021-08-15T19:03:50.359560Z"},"_kg_hide-output":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Forever Yaroslav Isaienkov \n\nhttps://www.kaggle.com/ihelon/google-landmark-retrieval-2020-eda ","metadata":{}},{"cell_type":"code","source":"df = pd.read_csv('../input/landmark-retrieval-2021/train.csv', index_col=0)\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2021-08-15T19:21:41.946750Z","iopub.execute_input":"2021-08-15T19:21:41.947408Z","iopub.status.idle":"2021-08-15T19:21:43.719838Z","shell.execute_reply.started":"2021-08-15T19:21:41.947372Z","shell.execute_reply":"2021-08-15T19:21:43.718851Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code By Yaroslav Isaienkov https://www.kaggle.com/ihelon/google-landmark-retrieval-2020-eda\n\ndef create_full_path(name):\n    return os.path.join(\n        '../input/landmark-retrieval-2021/train/',\n        name[0],\n        name[1],\n        name[2],\n        f'{name}.jpg'\n    )","metadata":{"execution":{"iopub.status.busy":"2021-08-15T19:23:39.613737Z","iopub.execute_input":"2021-08-15T19:23:39.614119Z","iopub.status.idle":"2021-08-15T19:23:39.618793Z","shell.execute_reply.started":"2021-08-15T19:23:39.614087Z","shell.execute_reply":"2021-08-15T19:23:39.617953Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code By Yaroslav Isaienkov https://www.kaggle.com/ihelon/google-landmark-retrieval-2020-eda\n\ndef vis(_id):\n    arr = df[df['landmark_id'] == _id].index.tolist()\n\n    plt.figure(figsize=(16, 16))\n    for i, name in enumerate(arr):\n        img = cv2.imread(create_full_path(name))\n        plt.subplot(4, 3, i + 1)\n        plt.imshow(img)\n        plt.xticks([])\n        plt.yticks([])\n        if i >= 11:\n            break\n    plt.suptitle(_id)\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2021-08-15T19:23:44.878100Z","iopub.execute_input":"2021-08-15T19:23:44.878793Z","iopub.status.idle":"2021-08-15T19:23:44.885219Z","shell.execute_reply.started":"2021-08-15T19:23:44.878749Z","shell.execute_reply":"2021-08-15T19:23:44.884222Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code By Yaroslav Isaienkov https://www.kaggle.com/ihelon/google-landmark-retrieval-2020-eda\n\nvis(random.choice(df['landmark_id'].unique()))","metadata":{"execution":{"iopub.status.busy":"2021-08-15T19:23:49.132965Z","iopub.execute_input":"2021-08-15T19:23:49.133357Z","iopub.status.idle":"2021-08-15T19:23:50.783951Z","shell.execute_reply.started":"2021-08-15T19:23:49.133326Z","shell.execute_reply":"2021-08-15T19:23:50.783157Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch\nimport fastai\nfrom fastai.tabular.all import *\nfrom fastai.text.all import *\nfrom fastai.vision.all import *\nfrom fastai.medical.imaging import *\nfrom fastai import *\n\n%reload_ext autoreload\n%autoreload 2\n%matplotlib inline\nimport warnings\nwarnings.simplefilter(action='ignore', category=Warning)","metadata":{"execution":{"iopub.status.busy":"2021-08-15T19:43:22.234085Z","iopub.execute_input":"2021-08-15T19:43:22.234479Z","iopub.status.idle":"2021-08-15T19:43:22.339550Z","shell.execute_reply.started":"2021-08-15T19:43:22.234445Z","shell.execute_reply":"2021-08-15T19:43:22.338795Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from PIL import Image\n\nimg = Image.open(\"../input/landmark-retrieval-2021/train/0/0/0/00001b2ba2c69ac5.jpg\")\nimg","metadata":{"execution":{"iopub.status.busy":"2021-08-15T19:38:59.191379Z","iopub.execute_input":"2021-08-15T19:38:59.192038Z","iopub.status.idle":"2021-08-15T19:38:59.388714Z","shell.execute_reply.started":"2021-08-15T19:38:59.191973Z","shell.execute_reply":"2021-08-15T19:38:59.387734Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Yaroslav Isaienkov https://www.kaggle.com/ihelon/monet-eda-and-visualization-techniques\n\ndef visualize_images(path, n_images, is_random=True, figsize=(16, 16)):\n    plt.figure(figsize=figsize)\n    w = int(n_images ** .5)\n    h = math.ceil(n_images / w)\n    \n    all_names = os.listdir(path)\n    image_names = all_names[:n_images]   \n    if is_random:\n        image_names = random.sample(all_names, n_images)\n            \n    for ind, image_name in enumerate(image_names):\n        img = cv2.imread(os.path.join(path, image_name))\n        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) \n        plt.subplot(h, w, ind + 1)\n        plt.imshow(img)\n        plt.xticks([])\n        plt.yticks([])\n    \n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2021-08-15T19:47:56.366021Z","iopub.execute_input":"2021-08-15T19:47:56.366422Z","iopub.status.idle":"2021-08-15T19:47:56.450484Z","shell.execute_reply.started":"2021-08-15T19:47:56.366391Z","shell.execute_reply":"2021-08-15T19:47:56.449608Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"landmarks_JPG_PATH = '../input/landmark-retrieval-2021/train/0/0/0'","metadata":{"execution":{"iopub.status.busy":"2021-08-15T19:49:37.103867Z","iopub.execute_input":"2021-08-15T19:49:37.104414Z","iopub.status.idle":"2021-08-15T19:49:37.183049Z","shell.execute_reply.started":"2021-08-15T19:49:37.104371Z","shell.execute_reply":"2021-08-15T19:49:37.182085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"visualize_images(landmarks_JPG_PATH, 9)","metadata":{"execution":{"iopub.status.busy":"2021-08-15T19:52:08.190188Z","iopub.execute_input":"2021-08-15T19:52:08.190663Z","iopub.status.idle":"2021-08-15T19:52:09.493040Z","shell.execute_reply.started":"2021-08-15T19:52:08.190628Z","shell.execute_reply":"2021-08-15T19:52:09.492149Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Yaroslav Isaienkov https://www.kaggle.com/ihelon/monet-eda-and-visualization-techniques\n\ndef show_color_histogram(path):\n    image_names = os.listdir(path)\n    image_name = random.choice(image_names)\n    img = cv2.imread(os.path.join(path, image_name))\n    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) \n    fig = make_subplots(1, 2)\n\n    fig.add_trace(go.Image(z=img), 1, 1)\n    for channel, color in enumerate(['red', 'green', 'blue']):\n        fig.add_trace(\n            go.Histogram(\n                x=img[..., channel].ravel(), \n                opacity=0.5,\n                marker_color=color, \n                name='%s channel' %color\n            ), 1, 2)\n    fig.update_layout(height=400)\n    fig.show()","metadata":{"execution":{"iopub.status.busy":"2021-08-15T19:52:31.575288Z","iopub.execute_input":"2021-08-15T19:52:31.575646Z","iopub.status.idle":"2021-08-15T19:52:31.659813Z","shell.execute_reply.started":"2021-08-15T19:52:31.575617Z","shell.execute_reply":"2021-08-15T19:52:31.658881Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Yaroslav Isaienkov https://www.kaggle.com/ihelon/monet-eda-and-visualization-techniques\n\ndef color_hist_visualization(image_path, figsize=(16, 4)):\n    plt.figure(figsize=figsize)\n    \n    img = cv2.imread(image_path)\n    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) \n    plt.subplot(1, 4, 1)\n    plt.imshow(img)\n    plt.axis(\"off\")\n    \n    colors = [\"red\", \"green\", \"blue\"]\n    for i in range(len(colors)):\n        plt.subplot(1, 4, i + 2)\n        plt.hist(\n            img[:, :, i].reshape(-1),\n            bins=25,\n            alpha=0.5,\n            color=colors[i],\n            density=True\n        )\n        plt.xlim(0, 255)\n        plt.xticks([])\n        plt.yticks([])","metadata":{"execution":{"iopub.status.busy":"2021-08-15T19:52:53.820911Z","iopub.execute_input":"2021-08-15T19:52:53.821277Z","iopub.status.idle":"2021-08-15T19:52:53.903881Z","shell.execute_reply.started":"2021-08-15T19:52:53.821246Z","shell.execute_reply":"2021-08-15T19:52:53.902873Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Yaroslav Isaienkov https://www.kaggle.com/ihelon/monet-eda-and-visualization-techniques\n\nimg_path = '../input/landmark-retrieval-2021/train/0/0/0/0000fb2148d6c0e4.jpg'\ncolor_hist_visualization(img_path)\n\nimg_path = '../input/landmark-retrieval-2021/train/2/0/2/20200a7671167ac4.jpg'\ncolor_hist_visualization(img_path)\n\nimg_path = '../input/landmark-retrieval-2021/train/6/0/0/6000a31590ca910f.jpg'\ncolor_hist_visualization(img_path)","metadata":{"execution":{"iopub.status.busy":"2021-08-15T20:03:00.013234Z","iopub.execute_input":"2021-08-15T20:03:00.013620Z","iopub.status.idle":"2021-08-15T20:03:01.473000Z","shell.execute_reply.started":"2021-08-15T20:03:00.013588Z","shell.execute_reply":"2021-08-15T20:03:01.471950Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Yaroslav Isaienkov https://www.kaggle.com/ihelon/monet-eda-and-visualization-techniques\n\nimport plotly.graph_objs as go\nfrom plotly.subplots import make_subplots\n\nshow_color_histogram(landmarks_JPG_PATH)","metadata":{"execution":{"iopub.status.busy":"2021-08-15T20:04:06.243452Z","iopub.execute_input":"2021-08-15T20:04:06.243887Z","iopub.status.idle":"2021-08-15T20:04:08.477040Z","shell.execute_reply.started":"2021-08-15T20:04:06.243850Z","shell.execute_reply":"2021-08-15T20:04:08.475840Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Yaroslav Isaienkov https://www.kaggle.com/ihelon/monet-eda-and-visualization-techniques\n\ndef batch_visualization(path, n_images, is_random=True, figsize=(16, 16)):\n    plt.figure(figsize=figsize)\n    \n    w = int(n_images ** .5)\n    h = math.ceil(n_images / w)\n    \n    all_names = os.listdir(path)\n    \n    image_names = all_names[:n_images]\n    if is_random:\n        image_names = random.sample(all_names, n_images)\n    \n    for ind, image_name in enumerate(image_names):\n        img = cv2.imread(os.path.join(path, image_name))\n        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) \n        plt.subplot(h, w, ind + 1)\n        plt.imshow(img)\n        plt.axis(\"off\")\n    \n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2021-08-15T20:05:03.702369Z","iopub.execute_input":"2021-08-15T20:05:03.702763Z","iopub.status.idle":"2021-08-15T20:05:03.787441Z","shell.execute_reply.started":"2021-08-15T20:05:03.702722Z","shell.execute_reply":"2021-08-15T20:05:03.786350Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"batch_visualization(landmarks_JPG_PATH, 1, is_random=True, figsize=(5, 5))","metadata":{"execution":{"iopub.status.busy":"2021-08-15T20:05:42.247692Z","iopub.execute_input":"2021-08-15T20:05:42.248077Z","iopub.status.idle":"2021-08-15T20:05:42.490942Z","shell.execute_reply.started":"2021-08-15T20:05:42.248044Z","shell.execute_reply":"2021-08-15T20:05:42.489905Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"batch_visualization(landmarks_JPG_PATH, 4, is_random=True, figsize=(10, 10))","metadata":{"execution":{"iopub.status.busy":"2021-08-15T20:06:15.747694Z","iopub.execute_input":"2021-08-15T20:06:15.748073Z","iopub.status.idle":"2021-08-15T20:06:16.480577Z","shell.execute_reply.started":"2021-08-15T20:06:15.748041Z","shell.execute_reply":"2021-08-15T20:06:16.479508Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Thank you Yaroslav Isaienkov for all the wonderful work you shared with us.","metadata":{}}]}