{"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":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\n# for dirname, _, filenames in os.walk('/kaggle/input'):\n#     for filename in filenames:\n#         print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-09-22T14:38:45.619265Z","iopub.execute_input":"2022-09-22T14:38:45.619647Z","iopub.status.idle":"2022-09-22T14:38:45.625762Z","shell.execute_reply.started":"2022-09-22T14:38:45.619615Z","shell.execute_reply":"2022-09-22T14:38:45.624578Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import sys\n\n# cosine_annealing_warmup_pytorch, segmentation-models-pytorch\n# timm, pretrained-models-pytorch, efficientnet-pytorch\n\n\nsys.path.append(\"../input/cosine-annealing-warm-with-warmup-for-pytorch\")\nsys.path.append(\"../input/segmentation-models-pytorch\")\nsys.path.append(\"../input/timm-pytorch-image-models/pytorch-image-models-master\")\nsys.path.append(\"../input/pretrained-models-pytorch\")\nsys.path.append(\"../input/efficientnet-pytorch\")\n!tar -xvf ../input/swifter/swifter-1.1.2.tar\n\n# einops\nsys.path.append('./swifter-1.1.2')\n!pip install ../input/einops-030/einops-0.3.0-py2.py3-none-any.whl\n\n# staintools\nsys.path.append(\"./staintools-offline\")\n!pip install /kaggle/input/staintools-offline/spams-2.6.5.4-cp37-cp37m-linux_x86_64.whl\n!pip install /kaggle/input/staintools-offline/staintools-2.1.2-py3-none-any.whl","metadata":{"execution":{"iopub.status.busy":"2022-09-22T14:38:45.653521Z","iopub.execute_input":"2022-09-22T14:38:45.654071Z","iopub.status.idle":"2022-09-22T14:40:14.622068Z","shell.execute_reply.started":"2022-09-22T14:38:45.654033Z","shell.execute_reply":"2022-09-22T14:40:14.620671Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# online pip install\n# !pip install -qq torch==1.7.1+cu110 torchvision==0.8.2+cu110 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html\n# !pip install -qq git+https://github.com/qubvel/segmentation_models.pytorch\n# !pip install -qq timm==0.4.12\n# !pip install -qq einops\n# !pip install swifter\n# !pip install rasterio\n# !pip install torchsummary\n\n# !pip install wandb --upgrade\n# !pip install 'git+https://github.com/katsura-jp/pytorch-cosine-annealing-with-warmup'\n\n# !pip install spams\n# !pip install staintools","metadata":{"execution":{"iopub.status.busy":"2022-09-22T14:40:14.625442Z","iopub.execute_input":"2022-09-22T14:40:14.626155Z","iopub.status.idle":"2022-09-22T14:40:14.631876Z","shell.execute_reply.started":"2022-09-22T14:40:14.626088Z","shell.execute_reply":"2022-09-22T14:40:14.630640Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport sys\nimport gc\nimport pandas as pd\nimport numpy as np\nimport json\nimport random\nimport glob\nimport time\nimport warnings\nimport math\nfrom datetime import datetime\nfrom tqdm.notebook import tqdm\nfrom typing import List, Dict, Any\nimport tifffile as tiff\nimport rasterio\n\nimport importlib\n\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom PIL import Image\nimport cv2\nfrom types import SimpleNamespace\nimport swifter\nimport wandb\nimport staintools\nfrom timeit import default_timer as timer\n\n\nimport torch\nimport torch.nn as nn\nfrom torch.utils.data import Dataset, DataLoader, WeightedRandomSampler\nimport albumentations as A\nfrom albumentations.pytorch.transforms import ToTensorV2\nimport segmentation_models_pytorch as smp\nfrom torch.optim.lr_scheduler import CosineAnnealingLR, CosineAnnealingWarmRestarts\n# from cosine_annealing_with_warmup import *\n# import torchsummary\n\nfrom sklearn.preprocessing import MinMaxScaler, StandardScaler, MaxAbsScaler, RobustScaler, LabelEncoder\nfrom sklearn.metrics import confusion_matrix,accuracy_score\nfrom sklearn.model_selection import StratifiedKFold, KFold, StratifiedGroupKFold\nfrom sklearn import preprocessing\n\nfrom IPython.display import clear_output\n# from google.colab import output\n# output.enable_custom_widget_manager()\nclear_output()\n%matplotlib inline","metadata":{"execution":{"iopub.status.busy":"2022-09-22T14:40:14.634301Z","iopub.execute_input":"2022-09-22T14:40:14.635064Z","iopub.status.idle":"2022-09-22T14:40:14.654612Z","shell.execute_reply.started":"2022-09-22T14:40:14.635020Z","shell.execute_reply":"2022-09-22T14:40:14.653645Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cfg = SimpleNamespace()\ncfg.lr = 3e-4\ncfg.max_lr = 3e-4\ncfg.min_lr = 5e-5\ncfg.T_max = 16\ncfg.wd = 1e-7\ncfg.eps = 1e-7\ncfg.num_epochs = 100\ncfg.patience = 15\ncfg.batch_size = 4\ncfg.accumulate_iter = 16\ncfg.n_splits = 5\ncfg.drop_rate = 3e-1\ncfg.num_workers = 2\ncfg.img_size = 768\ncfg.window_size = (768,768)\ncfg.stride = (384,384)\ncfg.num_classes = 1\ncfg.importance_map = np.ones((*cfg.window_size, cfg.num_classes), dtype='float32')\ncfg.loss = 'Dice'\ncfg.tta = True\ncfg.seed = 42 \n\n# cfg.date = str(int(datetime.now().strftime(\"%Y%m%d\")) + 2)\ncfg.date = datetime.now().strftime(\"%Y%m%d\")\ncfg.model_name = f\"CoAT_model_resize768_{cfg.date}\"\ncfg.base_path = \"../input/\" \ncfg.train_img_path = cfg.base_path + \"hubmap-organ-segmentation/train_images/\"\ncfg.train_stain_img_path = cfg.base_path + \"hubmap-files/train_stain_images/\"\ncfg.test_img_path = cfg.base_path + \"hubmap-organ-segmentation/test_images/\"\ncfg.mask_path = cfg.base_path + \"hubmap-files/train_masks/\"\ncfg.anno_path = cfg.base_path + \"hubmap-organ-segmentation/train_annotations/\"\ncfg.train_path = cfg.base_path + \"hubmap-organ-segmentation/train.csv\"\ncfg.test_path = cfg.base_path + \"hubmap-organ-segmentation/test.csv\"\ncfg.submission_path = cfg.base_path + \"hubmap-organ-segmentation/sample_submission.csv\"\ncfg.organs = [\"kidney\", \"prostate\", \"largeintestine\", \"spleen\", \"lung\"]\ncfg.device = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n\nsys.path.append(cfg.base_path + \"hubmap-files/coat_utils/\")\nsys.path.append(cfg.base_path + \"stainet\")\nfrom coat import *\nfrom daformer import *\nfrom helper import *","metadata":{"execution":{"iopub.status.busy":"2022-09-22T14:40:14.657583Z","iopub.execute_input":"2022-09-22T14:40:14.658097Z","iopub.status.idle":"2022-09-22T14:40:14.671320Z","shell.execute_reply.started":"2022-09-22T14:40:14.658062Z","shell.execute_reply":"2022-09-22T14:40:14.670383Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_size = 768\nimaging_measurements = {\n    'hpa': {\n        'pixel_size': {\n            'kidney': 0.4,\n            'prostate': 0.4,\n            'largeintestine': 0.4,\n            'spleen': 0.4,\n            'lung': 0.4\n        },\n        'tissue_thickness': {\n            'kidney': 4,\n            'prostate': 4,\n            'largeintestine': 4,\n            'spleen': 4,\n            'lung': 4\n        }\n    },\n    'hubmap': {\n        'pixel_size': {\n            'kidney': 0.5,\n            'prostate': 6.263,\n            'largeintestine': 0.229,\n            'spleen': 0.4945,\n            'lung': 0.7562\n        },\n        'tissue_thickness': {\n        'kidney': 10,\n            'prostate': 5,\n            'largeintestine': 8,\n            'spleen': 4,\n            'lung': 5\n        }\n    }\n}\n\norgan_threshold = {\n    'Hubmap': {\n        'kidney'        : 0.7,\n        'prostate'      : 0.7,\n        'largeintestine': 0.7,\n        'spleen'        : 0.7,\n        'lung'          : 0.05\n    },\n    'HPA': {\n        'kidney'        : 0.5,\n        'prostate'      : 0.5,\n        'largeintestine': 0.5,\n        'spleen'        : 0.5,\n        'lung'          : 0.10\n    },\n}\n\ndata_source =['Hubmap', 'HPA']\norgan = ['kidney', 'prostate', 'largeintestine', 'spleen', 'lung']\n\nsubmit_type  = 'local-test'  ","metadata":{"execution":{"iopub.status.busy":"2022-09-22T15:53:12.680403Z","iopub.execute_input":"2022-09-22T15:53:12.680788Z","iopub.status.idle":"2022-09-22T15:53:12.689739Z","shell.execute_reply.started":"2022-09-22T15:53:12.680754Z","shell.execute_reply":"2022-09-22T15:53:12.688533Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = [\n    dotdict(\n        is_use = 1,\n        module = 'model_daformer_coat',\n        param={'encoder': coat_lite_medium, 'decoder':daformer_conv3x3},\n        checkpoint = [\n            '../input/hubmap-files/model/FOLD0_20220921.pt',\n            '../input/hubmap-files/model/FOLD1_20220921.pt'\n#             \"../input/hubmap-files/model/FOLD0_20220919.pt\",\n#             \"../input/hubmap-files/model/FOLD1_20220919.pt\",\n#             \"../input/hubmap-files/model/FOLD2_20220919.pt\",\n#             \"../input/hubmap-files/model/FOLD3_20220919.pt\",\n#             \"../input/hubmap-files/model/FOLD4_20220919.pt\",\n        ],\n    ),\n\n]","metadata":{"execution":{"iopub.status.busy":"2022-09-22T15:53:12.884880Z","iopub.execute_input":"2022-09-22T15:53:12.885527Z","iopub.status.idle":"2022-09-22T15:53:12.891498Z","shell.execute_reply.started":"2022-09-22T15:53:12.885490Z","shell.execute_reply":"2022-09-22T15:53:12.890616Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def seed_everthing(seed=42):\n    os.environ[\"PYTHONHASHSEED\"] = str(seed)\n    random.seed(seed)\n    np.random.seed(seed)\n    torch.manual_seed(seed)\n    torch.cuda.manual_seed(seed)\n    torch.cuda.manual_seed_all(seed)\n    torch.backends.cudnn.deterministic = True\n    torch.backends.cudnn.benchmark = False\n\nseed_everthing(2022)","metadata":{"execution":{"iopub.status.busy":"2022-09-22T15:53:13.040562Z","iopub.execute_input":"2022-09-22T15:53:13.041482Z","iopub.status.idle":"2022-09-22T15:53:13.047774Z","shell.execute_reply.started":"2022-09-22T15:53:13.041446Z","shell.execute_reply":"2022-09-22T15:53:13.046851Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"valid_file = '../input/hubmap-organ-segmentation/test.csv'\ntiff_dir   = '../input/hubmap-organ-segmentation/test_images'\n\nvalid_df = pd.read_csv(valid_file)\nvalid_df.loc[:,'img_area']=valid_df['img_height']*valid_df['img_width']#sort by biggest image first for memory debug\nvalid_df = valid_df.sort_values('img_area').reset_index(drop=True)\nprint('load valid_df ok')\n\n\ndef image_to_tensor(image, mode='rgb'):\n    if  mode=='bgr' :\n        image = image[:,:,::-1]\n    \n    x = image.transpose(2,0,1)\n    x = np.ascontiguousarray(x)\n    x = torch.tensor(x)\n    return x","metadata":{"execution":{"iopub.status.busy":"2022-09-22T15:53:13.194100Z","iopub.execute_input":"2022-09-22T15:53:13.194387Z","iopub.status.idle":"2022-09-22T15:53:13.207900Z","shell.execute_reply.started":"2022-09-22T15:53:13.194361Z","shell.execute_reply":"2022-09-22T15:53:13.206959Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ref: https://www.kaggle.com/paulorzp/run-length-encode-and-decode\ndef rle_decode(mask_rle, shape):\n    '''\n    mask_rle: run-length as string formated (start length)\n    shape: (height,width) of array to return \n    Returns numpy array, 1 - mask, 0 - background\n\n    '''\n    s = mask_rle.split()\n    starts, lengths = [np.asarray(x, dtype=int) for x in (s[0:][::2], s[1:][::2])]\n    starts -= 1\n    ends = starts + lengths\n    img = np.zeros(shape[0]*shape[1], dtype=np.uint8)\n    \n    for lo, hi in zip(starts, ends):\n        img[lo:hi] = 1\n       \n    return img.reshape(shape).T  # Needed to align to RLE direction\n\n\n# ref.: https://www.kaggle.com/stainsby/fast-tested-rle\ndef rle_encode(img):\n    '''\n    img: numpy array, 1 - mask, 0 - background\n    Returns run length as string formated\n    '''\n    pixels = img.flatten()\n    pixels = np.concatenate([[0], pixels, [0]])\n    runs = np.where(pixels[1:] != pixels[:-1])[0] + 1\n    runs[1::2] -= runs[::2]\n    return ' '.join(str(x) for x in runs)\n\n#ref: https://www.kaggle.com/code/bguberfain/memory-aware-rle-encoding/notebook\ndef rle_encode_less_memory(img):\n    '''\n    img: numpy array, 1 - mask, 0 - background\n    Returns run length as string formated\n    This simplified method requires first and last pixel to be zero\n    '''\n    pixels = img.T.flatten()\n    \n    # This simplified method requires first and last pixel to be zero\n    pixels[0] = 0\n    pixels[-1] = 0\n    runs = np.where(pixels[1:] != pixels[:-1])[0]  + 2\n    runs[1::2] -= runs[::2]\n    \n    return ' '.join(str(x) for x in runs)\n\ndef read_tiff(path, scale=None, verbose=0): #Modified from https://www.kaggle.com/code/abhinand05/hubmap-extensive-eda-what-are-we-hacking\n    image = tiff.imread(path)\n    if len(image.shape) == 5:\n        image = image.squeeze().transpose(1, 2, 0)\n    \n    if verbose:\n        print(f\"[{path}] 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\"[{path}] Resized Image shape: {image.shape}\")\n        \n    # mx = np.max(image)\n    # image = image.astype(np.float32)\n    # if mx:\n    #     image /= mx # scale image to [0, 1]\n    return image\n","metadata":{"execution":{"iopub.status.busy":"2022-09-22T15:53:13.389932Z","iopub.execute_input":"2022-09-22T15:53:13.390212Z","iopub.status.idle":"2022-09-22T15:53:13.402409Z","shell.execute_reply.started":"2022-09-22T15:53:13.390186Z","shell.execute_reply":"2022-09-22T15:53:13.401282Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class Net(nn.Module):\n    \n    def __init__(self,\n                 encoder=coat_lite_medium,\n                 decoder=daformer_conv3x3,\n                 encoder_cfg={},\n                 decoder_cfg={},\n                 ):\n        \n        super(Net, self).__init__()\n        decoder_dim = decoder_cfg.get('decoder_dim', 320)\n\n        self.encoder = encoder\n\n        self.rgb = RGB()\n\n        encoder_dim = self.encoder.embed_dims\n        # [64, 128, 320, 512]\n\n        self.decoder = decoder(\n            encoder_dim=encoder_dim,\n            decoder_dim=decoder_dim,\n        )\n        self.logit = nn.Sequential(\n            nn.Conv2d(decoder_dim, 1, kernel_size=1),\n            nn.Upsample(scale_factor = 4, mode='bicubic', align_corners=False),\n        )\n\n    def forward(self, batch):\n\n        x = self.rgb(batch['image'])\n\n        B, C, H, W = x.shape\n        encoder = self.encoder(x)\n\n        last, decoder = self.decoder(encoder)\n        logit = self.logit(last)\n\n        output = {}\n        probability_from_logit = torch.sigmoid(logit)\n        output['probability'] = probability_from_logit\n\n        return output\n        \ndef init_model():\n    encoder = coat_lite_medium()\n    checkpoint = '../input/hubmap-files/coat_utils/coat_lite_medium_384x384_f9129688.pth'\n    checkpoint = torch.load(checkpoint, map_location=lambda storage, loc: storage)\n    state_dict = checkpoint['model']\n    encoder.load_state_dict(state_dict,strict=False)\n    \n    net = Net(encoder=encoder).cuda()\n    \n    return net","metadata":{"execution":{"iopub.status.busy":"2022-09-22T15:53:13.689084Z","iopub.execute_input":"2022-09-22T15:53:13.689744Z","iopub.status.idle":"2022-09-22T15:53:13.700069Z","shell.execute_reply.started":"2022-09-22T15:53:13.689705Z","shell.execute_reply":"2022-09-22T15:53:13.698985Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def do_local_validation():\n    print('\\tlocal validation ...')\n    \n    submit_df = pd.read_csv('submission.csv').fillna('')\n    submit_df = submit_df.sort_values('id')\n    truth_df  = valid_df.sort_values('id')\n    \n    lb_score = []\n    num = len(submit_df)\n    for i in range(num):\n        t_df = truth_df.iloc[i]\n        p_df = submit_df.iloc[i]\n        t = rle_decode(t_df.rle, t_df.img_height, t_df.img_width, 1)\n        p = rle_decode(p_df.rle, t_df.img_height, t_df.img_width, 1)\n        \n        dice = 2*(t*p).sum()/(p.sum()+t.sum())\n        lb_score.append(dice)\n        \n        if 0:\n            overlay = result_to_overlay(p, t)\n            image_show_norm('overlay', overlay, min=0, max=1, resize=0.10)\n            cv2.waitKey(1)\n\n    truth_df.loc[:,'lb_score']=lb_score\n    for organ in ['all', 'kidney', 'prostate', 'largeintestine', 'spleen', 'lung']:\n        if organ != 'all':\n            d = truth_df[truth_df.organ == organ]\n        else:\n            d = truth_df\n        print('\\t%f\\t%s\\t%f' % (len(d) / len(truth_df), organ, d.lb_score.mean()))\n        \n    \ndef load_net():\n    print('\\tload model',flush=True)\n    num = len(model[0].checkpoint)\n    nets = []\n    for f in range(num):\n        print(model[0].checkpoint[f])\n        net = init_model()\n        net.load_state_dict(torch.load(model[0].checkpoint[f]))\n        net.cuda()\n        net.eval()\n        nets.append(net)\n        \n    print('ok!')\n    return nets\n\n\ndef do_tta_batch(image, organ):\n    \n    batch = { #<todo> multiscale????\n        'image': torch.stack([\n            image,\n            torch.flip(image,dims=[1]),\n            torch.flip(image,dims=[2]),\n        ]),\n        'organ': torch.Tensor(\n            [[organ_to_label[organ]]]*3\n        ).long()\n    }\n    return batch\n\ndef undo_tta_batch(probability):\n    probability[0] = probability[0]\n    probability[1] = torch.flip(probability[1],dims=[1])\n    probability[2] = torch.flip(probability[2],dims=[2])\n    probability = probability.mean(0, keepdims=True)\n    probability = probability[0,0].float()\n    return probability\n\ndef do_submit(): \n    print('** submit_type  = %s *******************'%submit_type)\n\n    all_net = load_net()\n    \n    result = []\n    start_timer = timer()\n    for i,d in valid_df.iterrows():\n        id = d['id']\n#         if (d['data_source'] in data_source) and (d['organ'] in organ):\n            \n        tiff_file = tiff_dir +'/%d.tiff'%id\n        tiff = read_tiff(tiff_file) \n        tiff = tiff.astype(np.float32)/255\n        H,W,_ = tiff.shape\n\n        if 1:\n            s = d.pixel_size/0.4 * (image_size/3000)\n            h = int(np.ceil(int(H*s)/32)*32)\n            w = int(np.ceil(int(W*s)/32)*32) \n            image = cv2.resize(tiff,dsize=(w,h),interpolation=cv2.INTER_LINEAR)\n#         else: \n#             #or just resize to h,w = 768\n#             image = cv2.resize(tiff,dsize=(image_size,image_size),interpolation=cv2.INTER_AREA)\n\n        image = image_to_tensor(image, 'rgb')\n        batch = { k:v.cuda() for k,v in do_tta_batch(image, d.organ).items() }\n\n        use = 0\n        probability = 0\n        with torch.no_grad():\n#             with torch.cuda.amp.autocast(enabled = True):\n\n            for net in all_net:\n\n                use += 1\n                output = net(batch)#data_parallel(net, batch) #\n                probability += \\\n                    F.interpolate(output['probability'], size=(d.img_height,d.img_width),\n                                  mode='bilinear',align_corners=False, antialias=True )\n\n            probability = undo_tta_batch(probability/use)\n        #---\n        print(d.data_source, d.organ, organ_threshold[d.data_source][d.organ] )\n        probability = probability.data.cpu().numpy() \n        \n        p = probability>0.5\n        rle = rle_encode(p)\n#         else:\n#             rle = ''\n        \n        #----\n        if 0: #debug\n            image = cv2.cvtColor(tiff, 4).astype(np.float32)/255 #cv2.COLOR_RGB2BGR=4\n            mask  = rle_decode(d.rle, d.img_height, d.img_width, 1) #None\n            overlay = result_to_overlay(image, mask, probability)\n            \n            #image_show('image',image, resize=0.25)\n            image_show('overlay',overlay, resize=0.25)\n            cv2.waitKey(0)\n            pass\n        \n        result.append({ 'id':id, 'rle':rle, })\n        print('\\r', '\\tsubmit ... ',end='',flush=True)\n    print('\\n')\n    \n    #---\n    submit_df = pd.DataFrame(result)\n    submit_df.to_csv('submission.csv',index=False)\n    print(submit_df)\n    print('\\tsubmit_df ok!')\n    print('')\n    \n    if submit_type  == 'local-cv':\n        do_local_validation()\n        \n    if submit_type == 'local-test':\n        m = tiff\n#         p = probability\n        \n        plt.figure(figsize=(12, 7))\n        plt.subplot(1, 3, 1); plt.imshow(m); plt.axis('OFF'); plt.title('image')\n        plt.subplot(1, 3, 2); plt.imshow(p*255); plt.axis('OFF'); plt.title('mask')\n        plt.subplot(1, 3, 3); plt.imshow(m); plt.imshow(p*255, alpha=0.4); plt.axis('OFF'); plt.title('overlay')\n        plt.tight_layout()\n        plt.show()\n        \n    return submit_df\nsubmission = do_submit()","metadata":{"execution":{"iopub.status.busy":"2022-09-22T16:13:26.274192Z","iopub.execute_input":"2022-09-22T16:13:26.274568Z","iopub.status.idle":"2022-09-22T16:13:32.445840Z","shell.execute_reply.started":"2022-09-22T16:13:26.274535Z","shell.execute_reply":"2022-09-22T16:13:32.445008Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}