{"cells":[{"metadata":{"_kg_hide-input":true,"_kg_hide-output":true,"trusted":true},"cell_type":"code","source":"from IPython.display import HTML\nfile = open(\"../input/notebookassets/custom.css\")\nHTML(f\"<style>{file.read()}</style>\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Importing Libraries and Data 📚"},{"metadata":{},"cell_type":"markdown","source":"<strong style=\"color:red\">If you like this notebook, please give it an upvote! ⬆️</strong>"},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport os\nfrom colorama import Fore, Style\nimport cv2\n\nimport plotly.express as px\nimport plotly.graph_objs as go\nimport plotly.figure_factory as ff","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-input":true,"_kg_hide-output":true,"trusted":true},"cell_type":"code","source":"def cout(string: str, color: str, end='\\n') -> str:\n    \"\"\"\n    Prints a string in the required color\n    \"\"\"\n    print(color+string+Style.RESET_ALL, end=end)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"TRAIN_DIR = \"../input/hpa-single-cell-image-classification/train\"\nTEST_DIR = \"../input/hpa-single-cell-image-classification/test\"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"data = pd.read_csv(\"../input/hpa-single-cell-image-classification/train.csv\")\ndata.sample(10)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Top-10 Most Occurring Labels in the Training Dataset\n\nLet's start by looking at the Top-10 most occurring labels in the training dataset."},{"metadata":{"trusted":true},"cell_type":"code","source":"top_10_keys = list(dict(data['Label'].value_counts()).keys())[:10]\ntop_10_values = list(dict(data['Label'].value_counts()).values())[:10]\n\ncout(\"Top-10 Labels in the Dataset:\\n\", color=Fore.BLUE)\nfor i, (x, y) in enumerate(zip(top_10_keys, top_10_values)):\n    cout(f\"Rank: {i+1}\", color=Fore.CYAN, end=' \\t')\n    cout(\"Label: \", color=Fore.GREEN, end=' ')\n    cout(f\"{x} \", color=Fore.RED, end='\\t')\n    cout(\"Values: \", color=Fore.GREEN, end=' ')\n    cout(f\"{y} \", color=Fore.RED, end='\\n')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Top-10 Least Occurring Labels in the Training Dataset\n\nNow let us at the Top-10 least occuring labels in the training dataset."},{"metadata":{"trusted":true},"cell_type":"code","source":"top_10_keys = list(dict(data['Label'].value_counts()).keys())[-10:]\ntop_10_values = list(dict(data['Label'].value_counts()).values())[-10:]\n\ncout(\"Top-10 (least occurring) Labels in the Dataset:\\n\", color=Fore.BLUE)\nfor i, (x, y) in enumerate(zip(top_10_keys, top_10_values)):\n    cout(\"Label: \", color=Fore.GREEN, end=' ')\n    cout(f\"{x} \", color=Fore.RED, end='\\t')\n    cout(\"Values: \", color=Fore.GREEN, end=' ')\n    cout(f\"{y} \", color=Fore.RED, end='\\n')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Are IDs repeated?\n\nNo they are not. But we do have 4 Different Color Images for every single ID.\n\nThese 4 different colors (`Red`, `Blue`, `Yellow`, `Green`) are 4 filters for specific ROIs."},{"metadata":{},"cell_type":"markdown","source":"## Visualizing Images of a Few Top-Categories\n\nLet's now visualize the images of a few top categories and see what we find."},{"metadata":{},"cell_type":"markdown","source":"### Category: 0"},{"metadata":{"trusted":true},"cell_type":"code","source":"# Get all 4 color grade images for a single id\ncategory_0 = data[data['Label'] == '0']['ID']\nrdm_cat0_img = np.random.choice(category_0.tolist())\nall_imgs_current = []\nfor x in os.listdir(TRAIN_DIR):\n    if rdm_cat0_img in x:\n        all_imgs_current.append(x)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"#### Microtube Channels (Red)"},{"metadata":{"trusted":true},"cell_type":"code","source":"current_red = None\nfor x in all_imgs_current:\n    if \"red\" in x:\n        current_red = x\ncurrent_red = cv2.imread(os.path.join(TRAIN_DIR, current_red), 0)\nfig = px.imshow(current_red, title='Category: 0, [Microtube Channels (Red)]')\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"#### Nuclei Channels (Blue)"},{"metadata":{"trusted":true},"cell_type":"code","source":"current_blue = None\nfor x in all_imgs_current:\n    if \"blue\" in x:\n        current_blue = x\ncurrent_blue = cv2.imread(os.path.join(TRAIN_DIR, current_blue), 0)\nfig = px.imshow(current_blue, title='Category: 0, [Nuclei Channels (Blue)]')\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"#### Endoplasmic Reticulum - ER Channels(Yellow)"},{"metadata":{"trusted":true},"cell_type":"code","source":"current_yellow = None\nfor x in all_imgs_current:\n    if \"yellow\" in x:\n        current_yellow = x\ncurrent_yellow = cv2.imread(os.path.join(TRAIN_DIR, current_yellow), 0)\nfig = px.imshow(current_yellow, title='Category: 0, [ER Channels (Yellow)]')\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"#### Protein of Interest"},{"metadata":{"trusted":true},"cell_type":"code","source":"current_green = None\nfor x in all_imgs_current:\n    if \"green\" in x:\n        current_green = x\ncurrent_green = cv2.imread(os.path.join(TRAIN_DIR, current_green), 0)\nfig = px.imshow(current_green, title='Category: 0, [Protein of Interest (Green)]')\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Category: 16|0"},{"metadata":{"trusted":true},"cell_type":"code","source":"# Get all 4 color grade images for a single id\ncategory_16_0 = data[data['Label'] == '16|0']['ID']\nrdm_cat16_0_img = np.random.choice(category_16_0.tolist())\nall_imgs_current = []\nfor x in os.listdir(TRAIN_DIR):\n    if rdm_cat16_0_img in x:\n        all_imgs_current.append(x)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"#### Microtube Channels (Red)"},{"metadata":{"trusted":true},"cell_type":"code","source":"current_red = None\nfor x in all_imgs_current:\n    if \"red\" in x:\n        current_red = x\ncurrent_red = cv2.imread(os.path.join(TRAIN_DIR, current_red), 0)\nfig = px.imshow(current_red, title='Category: 16|0, [Microtube Channels (Red)]')\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"#### Nuclei Channels (Blue)"},{"metadata":{"trusted":true},"cell_type":"code","source":"current_blue = None\nfor x in all_imgs_current:\n    if \"blue\" in x:\n        current_blue = x\ncurrent_blue = cv2.imread(os.path.join(TRAIN_DIR, current_blue), 0)\nfig = px.imshow(current_blue, title='Category: 16|0, [Nuclei Channels (Blue)]')\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"#### Endoplasmic Reticulum - ER Channels(Yellow)"},{"metadata":{"trusted":true},"cell_type":"code","source":"current_yellow = None\nfor x in all_imgs_current:\n    if \"yellow\" in x:\n        current_yellow = x\ncurrent_yellow = cv2.imread(os.path.join(TRAIN_DIR, current_yellow), 0)\nfig = px.imshow(current_yellow, title='Category: 16|0, [ER Channels (Yellow)]')\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"#### Protein of Interest"},{"metadata":{"trusted":true},"cell_type":"code","source":"current_green = None\nfor x in all_imgs_current:\n    if \"green\" in x:\n        current_green = x\ncurrent_green = cv2.imread(os.path.join(TRAIN_DIR, current_green), 0)\nfig = px.imshow(current_green, title='Category: 16|0, [Protein of Interest (Green)]')\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### UNDER WORK 🛠️ ============="}],"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}