{"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":"markdown","source":"# HuBMAP + HPA - Hacking the Human Body\nThe task here in this competition is to segment the tissue units found in organs like lungs, kidney etc...\n\n![Competition Image](https://storage.googleapis.com/kaggle-competitions/kaggle/34547/logos/header.png?t=2022-02-15-22-37-27)\n\n## Table of Contents\n1. [Goals](#Goals)\n2. [Getting Started](#Getting-Started)\n    1. [Train Data](#Train-Data)\n    2. [Test Data](#Test-Data)\n3. [Visualizations](#Visualizations)\n    1. [Train Images](#Train-Images)\n    2. [Test Image](#Test-Image)\n4. [Detailed view of Train Images by category and sex](#Detailed-view-of-Train-Images-by-category-and-sex)\n    1. [Spleen Male](#Spleen-Male:-19360)\n    2. [Spleen Female](#Spleen-Female:-18792)\n    3. [Kindney Male](#Kidney-Male:-15192)\n    4. [Kindney Female](#Kidney-Female:-24522)\n    5. [Lung Male](#Lung-Male:-24782)\n    6. [Lung Female](#Lung-Female:-27232)\n    7. [Prostate](#Prostate:-30424)\n    8. [Large Intestine Male](#Large-Intestine-Male:-21812)\n    9. [Large Intestine Female](#Large-Intestine-Female:-4062)\n5. [Analyzing the Meta-Data](#Analyzing-the-Meta-Data)\n\n## Goals\nThe goal of this competition is to identify the locations of each functional tissue unit (FTU) in biopsy slides from several different organs. The underlying data includes imagery from different sources prepared with different protocols at a variety of resolutions, reflecting typical challenges for working with medical data.\n\n<br>\n\n<font size=4 color='blue'>If you find this notebook useful, leave an upvote, that motivates me to write more such notebooks.</font>\n\n<br>\n\n---\n**NOTE:**\n\n<font size=4 color='red'> This notebook is still a work in progress! </font>\n\n---","metadata":{}},{"cell_type":"markdown","source":"## Getting Started <a name=\"getting-started\"></a>","metadata":{}},{"cell_type":"code","source":"import os\n\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nplt.style.use(\"ggplot\")\n\nimport seaborn as sns\n\nimport tifffile\nimport cv2","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:27:34.73532Z","iopub.execute_input":"2022-06-25T10:27:34.735738Z","iopub.status.idle":"2022-06-25T10:27:35.378856Z","shell.execute_reply.started":"2022-06-25T10:27:34.735653Z","shell.execute_reply":"2022-06-25T10:27:35.378024Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"RANDOM_SEED = 42 \nBASE_DIR = \"../input/hubmap-organ-segmentation\"\nTRAIN_DIR = \"../input/hubmap-organ-segmentation/train_images\"\nTEST_DIR = \"../input/hubmap-organ-segmentation/test_images\"\nLABEL_DIR = \"../input/hubmap-organ-segmentation/train_annotations\"","metadata":{"execution":{"iopub.status.busy":"2022-06-25T10:27:35.380104Z","iopub.execute_input":"2022-06-25T10:27:35.380943Z","iopub.status.idle":"2022-06-25T10:27:35.385716Z","shell.execute_reply.started":"2022-06-25T10:27:35.380907Z","shell.execute_reply":"2022-06-25T10:27:35.384571Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def seed_everything(seed):\n    \"\"\"\n    Seeds basic parameters for reproductibility of results\n    \n    Arg:\n        seed {int} -- Number for the seed\n    \"\"\"\n#     random.seed(seed)\n    os.environ[\"PYTHONHASHSEED\"] = str(seed)\n    np.random.seed(seed)\n#     torch.manual_seed(seed)\n#     torch.cuda.manual_seed(seed)\n#     torch.backends.cudnn.deterministic = True\n#     torch.backends.cudnn.benchmark = False\n\nseed_everything(RANDOM_SEED)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:27:35.387285Z","iopub.execute_input":"2022-06-25T10:27:35.387639Z","iopub.status.idle":"2022-06-25T10:27:35.397906Z","shell.execute_reply.started":"2022-06-25T10:27:35.387611Z","shell.execute_reply":"2022-06-25T10:27:35.39665Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Train Data\n`train.csv` contains the RLE encoded masks and some metadata which could be very useful. ","metadata":{}},{"cell_type":"code","source":"train_df = pd.read_csv(os.path.join(BASE_DIR, \"train.csv\"))\ntrain_df.sample(5)","metadata":{"execution":{"iopub.status.busy":"2022-06-25T10:27:35.40074Z","iopub.execute_input":"2022-06-25T10:27:35.401765Z","iopub.status.idle":"2022-06-25T10:27:35.606461Z","shell.execute_reply.started":"2022-06-25T10:27:35.40173Z","shell.execute_reply":"2022-06-25T10:27:35.605703Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The number of images in the training only just over 350.\n\nThis might push us more towards external data found in the HuBMAP website [https://portal.hubmapconsortium.org](https://portal.hubmapconsortium.org/), Transfer Learning, heavy augmentations etc...\n","metadata":{}},{"cell_type":"code","source":"train_df.info()","metadata":{"execution":{"iopub.status.busy":"2022-06-25T10:27:35.607551Z","iopub.execute_input":"2022-06-25T10:27:35.607996Z","iopub.status.idle":"2022-06-25T10:27:35.621937Z","shell.execute_reply.started":"2022-06-25T10:27:35.607967Z","shell.execute_reply":"2022-06-25T10:27:35.620676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"`pixel_size` and `tissue_thickness` might be more or less the same throughout the dataset.","metadata":{}},{"cell_type":"code","source":"train_df.describe()","metadata":{"execution":{"iopub.status.busy":"2022-06-25T10:27:35.623468Z","iopub.execute_input":"2022-06-25T10:27:35.624412Z","iopub.status.idle":"2022-06-25T10:27:35.655277Z","shell.execute_reply.started":"2022-06-25T10:27:35.624377Z","shell.execute_reply":"2022-06-25T10:27:35.65453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Test Data","metadata":{}},{"cell_type":"markdown","source":"This competition uses a hidden test dataset. It is mentioned in the data description that we can expect around 550 images in the test set.","metadata":{}},{"cell_type":"code","source":"test_df = pd.read_csv(os.path.join(BASE_DIR, \"test.csv\"))\ntest_df","metadata":{"execution":{"iopub.status.busy":"2022-06-25T10:27:35.656379Z","iopub.execute_input":"2022-06-25T10:27:35.657057Z","iopub.status.idle":"2022-06-25T10:27:35.670893Z","shell.execute_reply.started":"2022-06-25T10:27:35.657025Z","shell.execute_reply":"2022-06-25T10:27:35.669785Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Credits: https://www.kaggle.com/code/ihelon/hubmap-exploratory-data-analysis\n\n# https://www.kaggle.com/paulorzp/rle-functions-run-lenght-encode-decode\ndef rle2mask(mask_rle, shape):\n    '''\n    mask_rle: run-length as string formated (start length)\n    shape: (width,height) of array to return \n    Returns numpy array, 1 - mask, 0 - background\n\n    '''\n    s = mask_rle.split()\n    starts, lengths = [\n        np.asarray(x, dtype=int) for x in (s[0:][::2], s[1:][::2])\n    ]\n    starts -= 1\n    ends = starts + lengths\n    img = np.zeros(shape[0] * shape[1], dtype=np.uint8)\n    for lo, hi in zip(starts, ends):\n        img[lo : hi] = 1\n    return img.reshape(shape).T\n\n\ndef read_image(image_id, scale=None, verbose=1):\n    image = tifffile.imread(\n        os.path.join(BASE_DIR, f\"train_images/{image_id}.tiff\")\n    )\n    if len(image.shape) == 5:\n        image = image.squeeze().transpose(1, 2, 0)\n    \n    mask = rle2mask(\n        train_df[train_df[\"id\"] == image_id][\"rle\"].values[0], \n        (image.shape[1], image.shape[0])\n    )\n    \n    if verbose:\n        print(f\"[{image_id}] Image shape: {image.shape}\")\n        print(f\"[{image_id}] Mask shape: {mask.shape}\")\n    \n    if scale:\n        new_size = (image.shape[1] // scale, image.shape[0] // scale)\n        image = cv2.resize(image, new_size)\n        mask = cv2.resize(mask, new_size)\n        \n        if verbose:\n            print(f\"[{image_id}] Resized Image shape: {image.shape}\")\n            print(f\"[{image_id}] Resized Mask shape: {mask.shape}\")\n        \n    return image, mask\n\n\ndef read_test_image(image_id, scale=None, verbose=1):\n    image = tifffile.imread(\n        os.path.join(BASE_DIR, f\"test_images/{image_id}.tiff\")\n    )\n    if len(image.shape) == 5:\n        image = image.squeeze().transpose(1, 2, 0)\n    \n    if verbose:\n        print(f\"[{image_id}] Image shape: {image.shape}\")\n    \n    if scale:\n        new_size = (image.shape[1] // scale, image.shape[0] // scale)\n        image = cv2.resize(image, new_size)\n        \n        if verbose:\n            print(f\"[{image_id}] Resized Image shape: {image.shape}\")\n        \n    return image\n\n\ndef plot_image_and_mask(image, mask, image_id, cmap):\n    plt.figure(figsize=(16, 10))\n    \n    plt.subplot(1, 3, 1)\n    plt.imshow(image)\n    plt.grid(visible=False)\n    plt.title(f\"Image {image_id}\", fontsize=18)\n    \n    plt.subplot(1, 3, 2)\n    plt.imshow(image)\n    plt.grid(visible=False)\n    plt.imshow(mask, cmap=cmap, alpha=0.5)\n    plt.title(f\"Image {image_id} + mask\", fontsize=18)    \n    \n    plt.subplot(1, 3, 3)\n    plt.grid(visible=False)\n    plt.imshow(mask, cmap=cmap)\n    plt.title(f\"Mask\", fontsize=18)    \n\n    plt.show()\n    \n    \ndef plot_grid_image_with_mask(image, mask):\n    plt.figure(figsize=(16, 16))\n    \n    w_len = image.shape[0]\n    h_len = image.shape[1]\n    \n    min_len = min(w_len, h_len)\n    w_start = (w_len - min_len) // 2\n    h_start = (h_len - min_len) // 2\n    \n    plt.imshow(image[w_start : w_start + min_len, h_start : h_start + min_len])\n    plt.imshow(\n        mask[w_start : w_start + min_len, h_start : h_start + min_len], cmap=\"hot\", alpha=0.5,\n    )\n    plt.axis(\"off\")\n            \n    plt.show()\n    \n\ndef plot_slice_image_and_mask(image, mask, start_h, end_h, start_w, end_w, cmap):\n    plt.figure(figsize=(16, 5))\n    \n    sub_image = image[start_h:end_h, start_w:end_w, :]\n    sub_mask = mask[start_h:end_h, start_w:end_w]\n    \n    plt.subplot(1, 3, 1)\n    plt.imshow(sub_image)\n    plt.axis(\"off\")\n    \n    plt.subplot(1, 3, 2)\n    plt.imshow(sub_image)\n    plt.imshow(sub_mask, cmap=cmap, alpha=0.5)\n    plt.axis(\"off\")\n    \n    plt.subplot(1, 3, 3)\n    plt.imshow(sub_mask, cmap=cmap)\n    plt.axis(\"off\")\n    \n    plt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:27:35.672264Z","iopub.execute_input":"2022-06-25T10:27:35.672841Z","iopub.status.idle":"2022-06-25T10:27:35.696865Z","shell.execute_reply.started":"2022-06-25T10:27:35.672809Z","shell.execute_reply":"2022-06-25T10:27:35.695923Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df[train_df.organ == \"largeintestine\"].sample(1)","metadata":{"execution":{"iopub.status.busy":"2022-06-25T10:27:35.698034Z","iopub.execute_input":"2022-06-25T10:27:35.699046Z","iopub.status.idle":"2022-06-25T10:27:35.723179Z","shell.execute_reply.started":"2022-06-25T10:27:35.69901Z","shell.execute_reply":"2022-06-25T10:27:35.72201Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sampled_ids = [24782, 24522, 19360, 29238, 27232, 18792, 30424, 21812]\ntrain_df[train_df[\"id\"].isin(sampled_ids)]","metadata":{"execution":{"iopub.status.busy":"2022-06-25T10:27:35.724427Z","iopub.execute_input":"2022-06-25T10:27:35.724762Z","iopub.status.idle":"2022-06-25T10:27:35.745198Z","shell.execute_reply.started":"2022-06-25T10:27:35.724732Z","shell.execute_reply":"2022-06-25T10:27:35.744282Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Visualizations","metadata":{}},{"cell_type":"markdown","source":"### Train Images","metadata":{}},{"cell_type":"code","source":"sampled_images = []\nsampled_masks = []\n\nfor sampled_id in sampled_ids:\n    tmp_image, tmp_mask = read_image(sampled_id, scale=20, verbose=0)\n    sampled_images.append(tmp_image)\n    sampled_masks.append(tmp_mask)\n\ndef get_image_masks_with_id(sampled_ids):\n    sampled_images = []\n    sampled_masks = []\n\n    for sampled_id in sampled_ids:\n        tmp_image, tmp_mask = read_image(sampled_id, scale=20, verbose=0)\n        sampled_images.append(tmp_image)\n        sampled_masks.append(tmp_mask)\n    \n    return sampled_images, sampled_masks","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:27:35.746263Z","iopub.execute_input":"2022-06-25T10:27:35.747059Z","iopub.status.idle":"2022-06-25T10:27:36.436794Z","shell.execute_reply.started":"2022-06-25T10:27:35.747015Z","shell.execute_reply":"2022-06-25T10:27:36.435649Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(16, 16))\nfor ind, (tmp_id, tmp_image) in enumerate(zip(sampled_ids, sampled_images)):\n    plt.subplot(3, 3, ind + 1)\n    plt.imshow(tmp_image)\n    plt.axis(\"off\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:27:36.438346Z","iopub.execute_input":"2022-06-25T10:27:36.438819Z","iopub.status.idle":"2022-06-25T10:27:37.059181Z","shell.execute_reply.started":"2022-06-25T10:27:36.438775Z","shell.execute_reply":"2022-06-25T10:27:37.057648Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(16, 16))\nfor ind, (tmp_id, tmp_image, tmp_mask) in enumerate(zip(sampled_ids, sampled_images, sampled_masks)):\n    plt.subplot(3, 3, ind + 1)\n    plt.imshow(tmp_image)\n    plt.imshow(tmp_mask, cmap=\"bwr\", alpha=0.5)\n    plt.axis(\"off\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:27:37.065521Z","iopub.execute_input":"2022-06-25T10:27:37.065997Z","iopub.status.idle":"2022-06-25T10:27:37.774236Z","shell.execute_reply.started":"2022-06-25T10:27:37.065956Z","shell.execute_reply":"2022-06-25T10:27:37.773075Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Test Image","metadata":{}},{"cell_type":"code","source":"image_id = 10078\ntest_image = read_test_image(image_id, scale=2, verbose=0)\n\nplt.figure(figsize=(16, 16))\nplt.imshow(test_image)\nplt.axis(\"off\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:27:37.775695Z","iopub.execute_input":"2022-06-25T10:27:37.776034Z","iopub.status.idle":"2022-06-25T10:27:38.510321Z","shell.execute_reply.started":"2022-06-25T10:27:37.776003Z","shell.execute_reply":"2022-06-25T10:27:38.50885Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Detailed view of Train Images by category and sex","metadata":{}},{"cell_type":"markdown","source":"### Spleen Male: 19360","metadata":{}},{"cell_type":"code","source":"image_id = 19360\nimage, mask = read_image(image_id, 2)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:27:38.512647Z","iopub.execute_input":"2022-06-25T10:27:38.513568Z","iopub.status.idle":"2022-06-25T10:27:38.629135Z","shell.execute_reply.started":"2022-06-25T10:27:38.51351Z","shell.execute_reply":"2022-06-25T10:27:38.627814Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_image_and_mask(image, mask, image_id, \"bwr\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:27:38.630785Z","iopub.execute_input":"2022-06-25T10:27:38.631193Z","iopub.status.idle":"2022-06-25T10:27:40.069804Z","shell.execute_reply.started":"2022-06-25T10:27:38.631155Z","shell.execute_reply":"2022-06-25T10:27:40.06832Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_slice_image_and_mask(image, mask, 625, 1300, 70, 400, \"plasma\")\nplot_slice_image_and_mask(image, mask, 1200, 1450, 390, 600, \"plasma\")\nplot_slice_image_and_mask(image, mask, 450, 950, 380, 720, \"plasma\")\nplot_slice_image_and_mask(image, mask, 470, 900, 1050, 1450, \"plasma\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:27:40.071295Z","iopub.execute_input":"2022-06-25T10:27:40.07166Z","iopub.status.idle":"2022-06-25T10:27:41.32088Z","shell.execute_reply.started":"2022-06-25T10:27:40.071623Z","shell.execute_reply":"2022-06-25T10:27:41.319771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_grid_image_with_mask(image, mask)","metadata":{"execution":{"iopub.status.busy":"2022-06-25T10:27:41.322332Z","iopub.execute_input":"2022-06-25T10:27:41.322654Z","iopub.status.idle":"2022-06-25T10:27:42.487667Z","shell.execute_reply.started":"2022-06-25T10:27:41.32262Z","shell.execute_reply":"2022-06-25T10:27:42.486473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ids_sampled = train_df[(train_df[\"organ\"] == \"spleen\") & (train_df[\"sex\"] == \"Male\")].sample(6, random_state=RANDOM_SEED).id.tolist()\n\nsampled_images, sampled_masks = get_image_masks_with_id(ids_sampled)\n\nplt.figure(figsize=(16, 16))\nfor ind, (tmp_id, tmp_image, tmp_mask) in enumerate(zip(ids_sampled, sampled_images, sampled_masks)):\n    plt.subplot(3, 3, ind + 1)\n    plt.imshow(tmp_image)\n    plt.imshow(tmp_mask, cmap=\"hot\", alpha=0.5)\n    plt.title(f\"Male Spleen: {tmp_id}\")\n    plt.axis(\"off\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:27:42.489121Z","iopub.execute_input":"2022-06-25T10:27:42.489444Z","iopub.status.idle":"2022-06-25T10:27:43.604478Z","shell.execute_reply.started":"2022-06-25T10:27:42.489413Z","shell.execute_reply":"2022-06-25T10:27:43.603365Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Spleen Female: 18792","metadata":{}},{"cell_type":"code","source":"image_id = 18792\nimage, mask = read_image(image_id, 2)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:27:43.605886Z","iopub.execute_input":"2022-06-25T10:27:43.606214Z","iopub.status.idle":"2022-06-25T10:27:43.704235Z","shell.execute_reply.started":"2022-06-25T10:27:43.606183Z","shell.execute_reply":"2022-06-25T10:27:43.703035Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_image_and_mask(image, mask, image_id, \"bwr\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:27:43.705941Z","iopub.execute_input":"2022-06-25T10:27:43.706644Z","iopub.status.idle":"2022-06-25T10:27:45.106494Z","shell.execute_reply.started":"2022-06-25T10:27:43.706596Z","shell.execute_reply":"2022-06-25T10:27:45.105466Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_slice_image_and_mask(image, mask, 550, 870, 180, 460, \"plasma\")\nplot_slice_image_and_mask(image, mask, 500, 1150, 350, 1150, \"plasma\")\nplot_slice_image_and_mask(image, mask, 710, 900, 950, 1400, \"plasma\")\nplot_slice_image_and_mask(image, mask, 1000, 1400, 720, 1100, \"plasma\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:27:45.107987Z","iopub.execute_input":"2022-06-25T10:27:45.10923Z","iopub.status.idle":"2022-06-25T10:27:46.291749Z","shell.execute_reply.started":"2022-06-25T10:27:45.109187Z","shell.execute_reply":"2022-06-25T10:27:46.290636Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_grid_image_with_mask(image, mask)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:27:46.292989Z","iopub.execute_input":"2022-06-25T10:27:46.29327Z","iopub.status.idle":"2022-06-25T10:27:47.354531Z","shell.execute_reply.started":"2022-06-25T10:27:46.293245Z","shell.execute_reply":"2022-06-25T10:27:47.353484Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ids_sampled = train_df[(train_df[\"organ\"] == \"spleen\") & (train_df[\"sex\"] == \"Female\")].sample(6, random_state=RANDOM_SEED).id.tolist()\n\nsampled_images, sampled_masks = get_image_masks_with_id(ids_sampled)\n\nplt.figure(figsize=(16, 16))\nfor ind, (tmp_id, tmp_image, tmp_mask) in enumerate(zip(ids_sampled, sampled_images, sampled_masks)):\n    plt.subplot(3, 3, ind + 1)\n    plt.imshow(tmp_image)\n    plt.imshow(tmp_mask, cmap=\"hot\", alpha=0.5)\n    plt.title(f\"Female Spleen: {tmp_id}\")\n    plt.axis(\"off\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:27:47.355898Z","iopub.execute_input":"2022-06-25T10:27:47.356207Z","iopub.status.idle":"2022-06-25T10:27:50.935903Z","shell.execute_reply.started":"2022-06-25T10:27:47.356179Z","shell.execute_reply":"2022-06-25T10:27:50.934762Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Lung Male: 24782","metadata":{}},{"cell_type":"code","source":"image_id = 24782\nimage, mask = read_image(image_id, 2)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:27:50.937256Z","iopub.execute_input":"2022-06-25T10:27:50.937595Z","iopub.status.idle":"2022-06-25T10:27:50.972493Z","shell.execute_reply.started":"2022-06-25T10:27:50.93755Z","shell.execute_reply":"2022-06-25T10:27:50.971428Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_image_and_mask(image, mask, image_id, \"bwr\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:27:50.97373Z","iopub.execute_input":"2022-06-25T10:27:50.974681Z","iopub.status.idle":"2022-06-25T10:27:52.375565Z","shell.execute_reply.started":"2022-06-25T10:27:50.974648Z","shell.execute_reply":"2022-06-25T10:27:52.3745Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_slice_image_and_mask(image, mask, 400, 620, 750, 900, \"plasma\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:27:52.377124Z","iopub.execute_input":"2022-06-25T10:27:52.377834Z","iopub.status.idle":"2022-06-25T10:27:52.60619Z","shell.execute_reply.started":"2022-06-25T10:27:52.377791Z","shell.execute_reply":"2022-06-25T10:27:52.605071Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_grid_image_with_mask(image, mask)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:27:52.607656Z","iopub.execute_input":"2022-06-25T10:27:52.608387Z","iopub.status.idle":"2022-06-25T10:27:53.496816Z","shell.execute_reply.started":"2022-06-25T10:27:52.608334Z","shell.execute_reply":"2022-06-25T10:27:53.495705Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ids_sampled = train_df[(train_df[\"organ\"] == \"lung\") & (train_df[\"sex\"] == \"Male\")].sample(6, random_state=RANDOM_SEED).id.tolist()\n\nsampled_images, sampled_masks = get_image_masks_with_id(ids_sampled)\n\nplt.figure(figsize=(16, 16))\nfor ind, (tmp_id, tmp_image, tmp_mask) in enumerate(zip(ids_sampled, sampled_images, sampled_masks)):\n    plt.subplot(3, 3, ind + 1)\n    plt.imshow(tmp_image)\n    plt.imshow(tmp_mask, cmap=\"hot\", alpha=0.5)\n    plt.title(f\"Male Lung: {tmp_id}\")\n    plt.axis(\"off\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:27:53.498466Z","iopub.execute_input":"2022-06-25T10:27:53.499491Z","iopub.status.idle":"2022-06-25T10:27:56.296842Z","shell.execute_reply.started":"2022-06-25T10:27:53.499453Z","shell.execute_reply":"2022-06-25T10:27:56.29573Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Lung Female: 27232","metadata":{}},{"cell_type":"code","source":"image_id = 27232\nimage, mask = read_image(image_id, 2)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:27:56.298135Z","iopub.execute_input":"2022-06-25T10:27:56.298554Z","iopub.status.idle":"2022-06-25T10:27:56.380078Z","shell.execute_reply.started":"2022-06-25T10:27:56.298519Z","shell.execute_reply":"2022-06-25T10:27:56.37926Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_image_and_mask(image, mask, image_id, \"bwr\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:27:56.381189Z","iopub.execute_input":"2022-06-25T10:27:56.382181Z","iopub.status.idle":"2022-06-25T10:27:57.768309Z","shell.execute_reply.started":"2022-06-25T10:27:56.382144Z","shell.execute_reply":"2022-06-25T10:27:57.76706Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_slice_image_and_mask(image, mask, 1050, 1150, 250, 450, \"plasma\")\nplot_slice_image_and_mask(image, mask, 1100, 1250, 450, 700, \"plasma\")\nplot_slice_image_and_mask(image, mask, 400, 800, 480, 850, \"plasma\")\nplot_slice_image_and_mask(image, mask, 1150, 1350, 750, 1050, \"plasma\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:27:57.769605Z","iopub.execute_input":"2022-06-25T10:27:57.769908Z","iopub.status.idle":"2022-06-25T10:27:58.542008Z","shell.execute_reply.started":"2022-06-25T10:27:57.769869Z","shell.execute_reply":"2022-06-25T10:27:58.540846Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_grid_image_with_mask(image, mask)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:27:58.543408Z","iopub.execute_input":"2022-06-25T10:27:58.544377Z","iopub.status.idle":"2022-06-25T10:27:59.510212Z","shell.execute_reply.started":"2022-06-25T10:27:58.544321Z","shell.execute_reply":"2022-06-25T10:27:59.509153Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ids_sampled = train_df[(train_df[\"organ\"] == \"lung\") & (train_df[\"sex\"] == \"Female\")].sample(6, random_state=RANDOM_SEED).id.tolist()\n\nsampled_images, sampled_masks = get_image_masks_with_id(ids_sampled)\n\nplt.figure(figsize=(16, 16))\nfor ind, (tmp_id, tmp_image, tmp_mask) in enumerate(zip(ids_sampled, sampled_images, sampled_masks)):\n    plt.subplot(3, 3, ind + 1)\n    plt.imshow(tmp_image)\n    plt.imshow(tmp_mask, cmap=\"hot\", alpha=0.5)\n    plt.title(f\"Female Lung: {tmp_id}\")\n    plt.axis(\"off\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:27:59.511753Z","iopub.execute_input":"2022-06-25T10:27:59.512722Z","iopub.status.idle":"2022-06-25T10:28:01.295825Z","shell.execute_reply.started":"2022-06-25T10:27:59.512683Z","shell.execute_reply":"2022-06-25T10:28:01.295017Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Kidney Male: 15192","metadata":{}},{"cell_type":"code","source":"image_id = 15192\nimage, mask = read_image(image_id, 2)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:28:01.296956Z","iopub.execute_input":"2022-06-25T10:28:01.297941Z","iopub.status.idle":"2022-06-25T10:28:01.348428Z","shell.execute_reply.started":"2022-06-25T10:28:01.297902Z","shell.execute_reply":"2022-06-25T10:28:01.3473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_image_and_mask(image, mask, image_id, \"bwr\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:28:01.349813Z","iopub.execute_input":"2022-06-25T10:28:01.350119Z","iopub.status.idle":"2022-06-25T10:28:02.734738Z","shell.execute_reply.started":"2022-06-25T10:28:01.350091Z","shell.execute_reply":"2022-06-25T10:28:02.73363Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_slice_image_and_mask(image, mask, 1100, 1400, 400, 650, \"plasma\")\nplot_slice_image_and_mask(image, mask, 1100, 1450, 720, 1100, \"plasma\")\nplot_slice_image_and_mask(image, mask, 220, 450, 820, 1300, \"plasma\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:28:02.736431Z","iopub.execute_input":"2022-06-25T10:28:02.736784Z","iopub.status.idle":"2022-06-25T10:28:03.451741Z","shell.execute_reply.started":"2022-06-25T10:28:02.736751Z","shell.execute_reply":"2022-06-25T10:28:03.450626Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_grid_image_with_mask(image, mask)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:28:03.452967Z","iopub.execute_input":"2022-06-25T10:28:03.45335Z","iopub.status.idle":"2022-06-25T10:28:04.60406Z","shell.execute_reply.started":"2022-06-25T10:28:03.45332Z","shell.execute_reply":"2022-06-25T10:28:04.602872Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ids_sampled = train_df[(train_df[\"organ\"] == \"kidney\") & (train_df[\"sex\"] == \"Male\")].sample(6, random_state=RANDOM_SEED).id.tolist()\n\nsampled_images, sampled_masks = get_image_masks_with_id(ids_sampled)\n\nplt.figure(figsize=(16, 16))\nfor ind, (tmp_id, tmp_image, tmp_mask) in enumerate(zip(ids_sampled, sampled_images, sampled_masks)):\n    plt.subplot(3, 3, ind + 1)\n    plt.imshow(tmp_image)\n    plt.imshow(tmp_mask, cmap=\"hot\", alpha=0.5)\n    plt.title(f\"Male Kidney: {tmp_id}\")\n    plt.axis(\"off\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:28:04.605516Z","iopub.execute_input":"2022-06-25T10:28:04.605893Z","iopub.status.idle":"2022-06-25T10:28:05.613542Z","shell.execute_reply.started":"2022-06-25T10:28:04.605862Z","shell.execute_reply":"2022-06-25T10:28:05.612674Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Kidney Female: 24522","metadata":{}},{"cell_type":"code","source":"image_id = 24522\nimage, mask = read_image(image_id, 2)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:28:05.619952Z","iopub.execute_input":"2022-06-25T10:28:05.620778Z","iopub.status.idle":"2022-06-25T10:28:05.696372Z","shell.execute_reply.started":"2022-06-25T10:28:05.620743Z","shell.execute_reply":"2022-06-25T10:28:05.695061Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_image_and_mask(image, mask, image_id, \"bwr\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:28:05.697993Z","iopub.execute_input":"2022-06-25T10:28:05.698297Z","iopub.status.idle":"2022-06-25T10:28:07.07839Z","shell.execute_reply.started":"2022-06-25T10:28:05.698269Z","shell.execute_reply":"2022-06-25T10:28:07.077323Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_slice_image_and_mask(image, mask, 280, 550, 720, 1000, \"plasma\")\nplot_slice_image_and_mask(image, mask, 400, 650, 1000, 1300, \"plasma\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:28:07.079992Z","iopub.execute_input":"2022-06-25T10:28:07.080721Z","iopub.status.idle":"2022-06-25T10:28:07.747365Z","shell.execute_reply.started":"2022-06-25T10:28:07.080669Z","shell.execute_reply":"2022-06-25T10:28:07.746269Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_grid_image_with_mask(image, mask)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:28:07.749132Z","iopub.execute_input":"2022-06-25T10:28:07.74956Z","iopub.status.idle":"2022-06-25T10:28:08.858682Z","shell.execute_reply.started":"2022-06-25T10:28:07.749519Z","shell.execute_reply":"2022-06-25T10:28:08.857651Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ids_sampled = train_df[(train_df[\"organ\"] == \"kidney\") & (train_df[\"sex\"] == \"Female\")].sample(6, random_state=RANDOM_SEED).id.tolist()\n\nsampled_images, sampled_masks = get_image_masks_with_id(ids_sampled)\n\nplt.figure(figsize=(16, 16))\nfor ind, (tmp_id, tmp_image, tmp_mask) in enumerate(zip(ids_sampled, sampled_images, sampled_masks)):\n    plt.subplot(3, 3, ind + 1)\n    plt.imshow(tmp_image)\n    plt.imshow(tmp_mask, cmap=\"hot\", alpha=0.5)\n    plt.title(f\"Female Kidney: {tmp_id}\")\n    plt.axis(\"off\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:28:08.860365Z","iopub.execute_input":"2022-06-25T10:28:08.860748Z","iopub.status.idle":"2022-06-25T10:28:09.60809Z","shell.execute_reply.started":"2022-06-25T10:28:08.860713Z","shell.execute_reply":"2022-06-25T10:28:09.607249Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Prostate: 30424\n(Male Only)","metadata":{}},{"cell_type":"code","source":"image_id = 30424\nimage, mask = read_image(image_id, 2)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:28:09.609098Z","iopub.execute_input":"2022-06-25T10:28:09.609797Z","iopub.status.idle":"2022-06-25T10:28:09.665048Z","shell.execute_reply.started":"2022-06-25T10:28:09.609762Z","shell.execute_reply":"2022-06-25T10:28:09.663482Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_image_and_mask(image, mask, image_id, \"bwr\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:28:09.666848Z","iopub.execute_input":"2022-06-25T10:28:09.668208Z","iopub.status.idle":"2022-06-25T10:28:11.132819Z","shell.execute_reply.started":"2022-06-25T10:28:09.668159Z","shell.execute_reply":"2022-06-25T10:28:11.13163Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_slice_image_and_mask(image, mask, 780, 1500, 230, 850, \"plasma\")\nplot_slice_image_and_mask(image, mask, 100, 800, 250, 1300, \"plasma\")\nplot_slice_image_and_mask(image, mask, 750, 1100, 1200, 1500, \"plasma\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:28:11.134357Z","iopub.execute_input":"2022-06-25T10:28:11.134776Z","iopub.status.idle":"2022-06-25T10:28:12.332605Z","shell.execute_reply.started":"2022-06-25T10:28:11.13474Z","shell.execute_reply":"2022-06-25T10:28:12.331319Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_grid_image_with_mask(image, mask)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:28:12.334282Z","iopub.execute_input":"2022-06-25T10:28:12.33473Z","iopub.status.idle":"2022-06-25T10:28:13.455189Z","shell.execute_reply.started":"2022-06-25T10:28:12.334688Z","shell.execute_reply":"2022-06-25T10:28:13.453958Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ids_sampled = train_df[train_df[\"organ\"] == \"prostate\"].sample(6, random_state=RANDOM_SEED).id.tolist()\n\nsampled_images, sampled_masks = get_image_masks_with_id(ids_sampled)\n\nplt.figure(figsize=(16, 16))\nfor ind, (tmp_id, tmp_image, tmp_mask) in enumerate(zip(ids_sampled, sampled_images, sampled_masks)):\n    plt.subplot(3, 3, ind + 1)\n    plt.imshow(tmp_image)\n    plt.imshow(tmp_mask, cmap=\"hot\", alpha=0.5)\n    plt.title(f\"Male Prostate: {tmp_id}\")\n    plt.axis(\"off\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:28:13.456569Z","iopub.execute_input":"2022-06-25T10:28:13.456983Z","iopub.status.idle":"2022-06-25T10:28:14.551549Z","shell.execute_reply.started":"2022-06-25T10:28:13.456949Z","shell.execute_reply":"2022-06-25T10:28:14.55039Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Large Intestine Male: 21812\n","metadata":{}},{"cell_type":"code","source":"image_id = 21812\nimage, mask = read_image(image_id, 2)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:28:14.553282Z","iopub.execute_input":"2022-06-25T10:28:14.5539Z","iopub.status.idle":"2022-06-25T10:28:14.656373Z","shell.execute_reply.started":"2022-06-25T10:28:14.553855Z","shell.execute_reply":"2022-06-25T10:28:14.655225Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_image_and_mask(image, mask, image_id, \"bwr\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:28:14.657846Z","iopub.execute_input":"2022-06-25T10:28:14.658185Z","iopub.status.idle":"2022-06-25T10:28:16.202273Z","shell.execute_reply.started":"2022-06-25T10:28:14.658153Z","shell.execute_reply":"2022-06-25T10:28:16.201258Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_slice_image_and_mask(image, mask, 10, 450, 100, 1000, \"plasma\")\nplot_slice_image_and_mask(image, mask, 350, 1000, 50, 1500, \"plasma\")\nplot_slice_image_and_mask(image, mask, 800, 1500, 400, 1500, \"plasma\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:28:16.203927Z","iopub.execute_input":"2022-06-25T10:28:16.204866Z","iopub.status.idle":"2022-06-25T10:28:17.440152Z","shell.execute_reply.started":"2022-06-25T10:28:16.204825Z","shell.execute_reply":"2022-06-25T10:28:17.43895Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_grid_image_with_mask(image, mask)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:28:17.4418Z","iopub.execute_input":"2022-06-25T10:28:17.442427Z","iopub.status.idle":"2022-06-25T10:28:18.533408Z","shell.execute_reply.started":"2022-06-25T10:28:17.442385Z","shell.execute_reply":"2022-06-25T10:28:18.53262Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ids_sampled = train_df[(train_df[\"organ\"] == \"largeintestine\") & (train_df[\"sex\"] == \"Male\")].sample(6, random_state=RANDOM_SEED).id.tolist()\n\nsampled_images, sampled_masks = get_image_masks_with_id(ids_sampled)\n\nplt.figure(figsize=(16, 16))\nfor ind, (tmp_id, tmp_image, tmp_mask) in enumerate(zip(ids_sampled, sampled_images, sampled_masks)):\n    plt.subplot(3, 3, ind + 1)\n    plt.imshow(tmp_image)\n    plt.imshow(tmp_mask, cmap=\"hot\", alpha=0.5)\n    plt.title(f\"Male Large-Intestine: {tmp_id}\")\n    plt.axis(\"off\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:28:18.534547Z","iopub.execute_input":"2022-06-25T10:28:18.535562Z","iopub.status.idle":"2022-06-25T10:28:19.268637Z","shell.execute_reply.started":"2022-06-25T10:28:18.535526Z","shell.execute_reply":"2022-06-25T10:28:19.267397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Large Intestine Female: 4062","metadata":{}},{"cell_type":"code","source":"image_id = 4062\nimage, mask = read_image(image_id, 2)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:28:19.269983Z","iopub.execute_input":"2022-06-25T10:28:19.270898Z","iopub.status.idle":"2022-06-25T10:28:19.320147Z","shell.execute_reply.started":"2022-06-25T10:28:19.270859Z","shell.execute_reply":"2022-06-25T10:28:19.318821Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_image_and_mask(image, mask, image_id, \"bwr\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:28:19.323458Z","iopub.execute_input":"2022-06-25T10:28:19.323824Z","iopub.status.idle":"2022-06-25T10:28:20.665141Z","shell.execute_reply.started":"2022-06-25T10:28:19.32379Z","shell.execute_reply":"2022-06-25T10:28:20.664045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_slice_image_and_mask(image, mask, 50, 600, 200, 1500, \"plasma\")\nplot_slice_image_and_mask(image, mask, 650, 1500, 600, 1500, \"plasma\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:28:20.666503Z","iopub.execute_input":"2022-06-25T10:28:20.666949Z","iopub.status.idle":"2022-06-25T10:28:21.536995Z","shell.execute_reply.started":"2022-06-25T10:28:20.666918Z","shell.execute_reply":"2022-06-25T10:28:21.536157Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_grid_image_with_mask(image, mask)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:28:21.538514Z","iopub.execute_input":"2022-06-25T10:28:21.538873Z","iopub.status.idle":"2022-06-25T10:28:22.521933Z","shell.execute_reply.started":"2022-06-25T10:28:21.538839Z","shell.execute_reply":"2022-06-25T10:28:22.520811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ids_sampled = train_df[(train_df[\"organ\"] == \"largeintestine\") & (train_df[\"sex\"] == \"Female\")].sample(6, random_state=RANDOM_SEED).id.tolist()\n\nsampled_images, sampled_masks = get_image_masks_with_id(ids_sampled)\n\nplt.figure(figsize=(16, 16))\nfor ind, (tmp_id, tmp_image, tmp_mask) in enumerate(zip(ids_sampled, sampled_images, sampled_masks)):\n    plt.subplot(3, 3, ind + 1)\n    plt.imshow(tmp_image)\n    plt.imshow(tmp_mask, cmap=\"hot\", alpha=0.5)\n    plt.title(f\"Female Large-Intestine: {tmp_id}\")\n    plt.axis(\"off\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:28:22.523675Z","iopub.execute_input":"2022-06-25T10:28:22.524388Z","iopub.status.idle":"2022-06-25T10:28:23.594647Z","shell.execute_reply.started":"2022-06-25T10:28:22.524345Z","shell.execute_reply":"2022-06-25T10:28:23.593655Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Analyzing the Meta Data","metadata":{}},{"cell_type":"code","source":"train_df[\"area\"] = train_df[\"img_height\"] * train_df[\"img_height\"]","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-25T10:28:23.59628Z","iopub.execute_input":"2022-06-25T10:28:23.597315Z","iopub.status.idle":"2022-06-25T10:28:23.604142Z","shell.execute_reply.started":"2022-06-25T10:28:23.597242Z","shell.execute_reply":"2022-06-25T10:28:23.602614Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.info()","metadata":{"execution":{"iopub.status.busy":"2022-06-25T10:28:23.605619Z","iopub.execute_input":"2022-06-25T10:28:23.606533Z","iopub.status.idle":"2022-06-25T10:28:23.624696Z","shell.execute_reply.started":"2022-06-25T10:28:23.606497Z","shell.execute_reply":"2022-06-25T10:28:23.623728Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(8, 8))\ntrain_df.organ.value_counts().plot(kind='bar')","metadata":{"execution":{"iopub.status.busy":"2022-06-25T10:28:23.625815Z","iopub.execute_input":"2022-06-25T10:28:23.626658Z","iopub.status.idle":"2022-06-25T10:28:23.936099Z","shell.execute_reply.started":"2022-06-25T10:28:23.626613Z","shell.execute_reply":"2022-06-25T10:28:23.934852Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(8, 8))\ntrain_df.sex.value_counts().plot(kind='bar')","metadata":{"execution":{"iopub.status.busy":"2022-06-25T10:28:23.937653Z","iopub.execute_input":"2022-06-25T10:28:23.938815Z","iopub.status.idle":"2022-06-25T10:28:24.091415Z","shell.execute_reply.started":"2022-06-25T10:28:23.938768Z","shell.execute_reply":"2022-06-25T10:28:24.090576Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(8, 8))\ntrain_df.data_source.value_counts().plot(kind='bar')","metadata":{"execution":{"iopub.status.busy":"2022-06-25T10:28:24.092973Z","iopub.execute_input":"2022-06-25T10:28:24.093404Z","iopub.status.idle":"2022-06-25T10:28:24.256956Z","shell.execute_reply.started":"2022-06-25T10:28:24.09336Z","shell.execute_reply":"2022-06-25T10:28:24.255884Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 12))\nsns.histplot(x=\"age\", kde=True, data=train_df)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-06-25T10:28:24.258619Z","iopub.execute_input":"2022-06-25T10:28:24.259383Z","iopub.status.idle":"2022-06-25T10:28:24.509008Z","shell.execute_reply.started":"2022-06-25T10:28:24.259334Z","shell.execute_reply":"2022-06-25T10:28:24.508171Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 12))\nsns.histplot(x=\"age\", hue=\"sex\", multiple=\"stack\", kde=True, data=train_df)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-06-25T10:28:24.510626Z","iopub.execute_input":"2022-06-25T10:28:24.510982Z","iopub.status.idle":"2022-06-25T10:28:24.833782Z","shell.execute_reply.started":"2022-06-25T10:28:24.510948Z","shell.execute_reply":"2022-06-25T10:28:24.832652Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 12))\nsns.histplot(x=\"age\", hue=\"organ\", multiple=\"stack\", data=train_df)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-06-25T10:28:24.835298Z","iopub.execute_input":"2022-06-25T10:28:24.836468Z","iopub.status.idle":"2022-06-25T10:28:25.237669Z","shell.execute_reply.started":"2022-06-25T10:28:24.83642Z","shell.execute_reply":"2022-06-25T10:28:25.236352Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 12))\nsns.displot(x=\"age\", hue=\"organ\", kind=\"kde\", multiple='stack', data=train_df, height=12)","metadata":{"execution":{"iopub.status.busy":"2022-06-25T10:28:25.238978Z","iopub.execute_input":"2022-06-25T10:28:25.240007Z","iopub.status.idle":"2022-06-25T10:28:25.735087Z","shell.execute_reply.started":"2022-06-25T10:28:25.239956Z","shell.execute_reply":"2022-06-25T10:28:25.734251Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.displot(x=\"age\", col=\"sex\", hue=\"organ\", kind=\"kde\", multiple='stack', data=train_df)","metadata":{"execution":{"iopub.status.busy":"2022-06-25T10:28:25.736283Z","iopub.execute_input":"2022-06-25T10:28:25.736851Z","iopub.status.idle":"2022-06-25T10:28:26.331999Z","shell.execute_reply.started":"2022-06-25T10:28:25.736815Z","shell.execute_reply":"2022-06-25T10:28:26.33077Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 12))\nsns.countplot(x=\"organ\", hue=\"sex\", data=train_df)","metadata":{"execution":{"iopub.status.busy":"2022-06-25T10:28:26.334364Z","iopub.execute_input":"2022-06-25T10:28:26.334701Z","iopub.status.idle":"2022-06-25T10:28:26.549193Z","shell.execute_reply.started":"2022-06-25T10:28:26.33467Z","shell.execute_reply":"2022-06-25T10:28:26.548086Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 12))\nsns.countplot(x=\"organ\", hue=\"data_source\", data=train_df)","metadata":{"execution":{"iopub.status.busy":"2022-06-25T10:28:26.552509Z","iopub.execute_input":"2022-06-25T10:28:26.554091Z","iopub.status.idle":"2022-06-25T10:28:26.755117Z","shell.execute_reply.started":"2022-06-25T10:28:26.554039Z","shell.execute_reply":"2022-06-25T10:28:26.754041Z"},"trusted":true},"execution_count":null,"outputs":[]}]}