{"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":"# **used mmsegmentation from open-mmlab**","metadata":{}},{"cell_type":"markdown","source":"# **Install MMSegmentation**","metadata":{"papermill":{"duration":0.034808,"end_time":"2021-10-28T17:34:14.981619","exception":false,"start_time":"2021-10-28T17:34:14.946811","status":"completed"},"tags":[]}},{"cell_type":"code","source":"!pip install '/kaggle/input/pytorch110torchvision011torchaudio010cu113/torch-1.10.1cu113-cp37-cp37m-linux_x86_64.whl' --no-deps\n!pip install '/kaggle/input/pytorch110torchvision011torchaudio010cu113/torchvision-0.11.2cu113-cp37-cp37m-linux_x86_64.whl' --no-deps\n!pip install '/kaggle/input/pytorch110torchvision011torchaudio010cu113/torchaudio-0.10.1cu113-cp37-cp37m-linux_x86_64.whl' --no-deps","metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","papermill":{"duration":127.55412,"end_time":"2021-10-28T17:36:22.571091","exception":false,"start_time":"2021-10-28T17:34:15.016971","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-10-26T12:46:42.049386Z","iopub.execute_input":"2022-10-26T12:46:42.049901Z","iopub.status.idle":"2022-10-26T12:48:54.306544Z","shell.execute_reply.started":"2022-10-26T12:46:42.049801Z","shell.execute_reply":"2022-10-26T12:48:54.305672Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install '/kaggle/input/mmdetectionv2140/addict-2.4.0-py3-none-any.whl' --no-deps\n!pip install '/kaggle/input/mmdetectionv2140/yapf-0.31.0-py2.py3-none-any.whl' --no-deps\n!pip install '/kaggle/input/mmdetectionv2140/terminal-0.4.0-py3-none-any.whl' --no-deps\n!pip install '/kaggle/input/mmdetectionv2140/terminaltables-3.1.0-py3-none-any.whl' --no-deps","metadata":{"papermill":{"duration":222.21755,"end_time":"2021-10-28T17:40:04.826612","exception":false,"start_time":"2021-10-28T17:36:22.609062","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-10-26T12:48:54.308553Z","iopub.execute_input":"2022-10-26T12:48:54.308850Z","iopub.status.idle":"2022-10-26T12:50:22.568440Z","shell.execute_reply.started":"2022-10-26T12:48:54.308810Z","shell.execute_reply":"2022-10-26T12:50:22.567563Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# install mmcv & mmseg\n\n!pip install '/kaggle/input/mmcv1371/mmcv_full-1.5.0-cp37-cp37m-manylinux1_x86_64.whl' --no-deps\n!pip install '/kaggle/input/mmcv1371/mmcls-0.21.0-py2.py3-none-any.whl' --no-deps\n!pip install '/kaggle/input/mmdetectionv2140/pycocotools-2.0.2/pycocotools-2.0.2' --no-deps\n!pip install '/kaggle/input/mmdetectionv2140/mmpycocotools-12.0.3/mmpycocotools-12.0.3' --no-deps\n\n!rm -rf mmsegmentation\n!cp -r /kaggle/input/mmsegunknown  /kaggle/working/mmsegmentation\n%cd /kaggle/working/mmsegmentation\n!pip install -e .","metadata":{"execution":{"iopub.status.busy":"2022-10-26T12:50:22.573544Z","iopub.execute_input":"2022-10-26T12:50:22.573850Z","iopub.status.idle":"2022-10-26T12:52:45.364734Z","shell.execute_reply.started":"2022-10-26T12:50:22.573813Z","shell.execute_reply":"2022-10-26T12:52:45.363752Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Import Libraries**","metadata":{"papermill":{"duration":0.098388,"end_time":"2021-10-28T17:40:04.980758","exception":false,"start_time":"2021-10-28T17:40:04.88237","status":"completed"},"tags":[]}},{"cell_type":"code","source":"import math\nimport torch\nimport torch.nn as nn\nimport torchvision.transforms as transforms\nimport torch.nn.functional as F\nfrom torch.utils.data import Dataset, DataLoader\nimport glob\nimport sklearn\nimport torchvision\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import LabelEncoder\nfrom tqdm.auto import tqdm\nfrom scipy.ndimage import binary_closing, binary_opening, measurements\nimport numpy as np\nimport pandas as pd\nimport os\nimport tifffile as tiff\nimport matplotlib.pyplot as plt\nimport PIL\nimport json\nfrom PIL import Image, ImageEnhance\nimport rasterio\nfrom rasterio.windows import Window\nimport albumentations as A\nimport mmseg\nimport mmcv\nimport gc\nfrom albumentations.pytorch import ToTensorV2\nimport seaborn as sns\nimport glob\nfrom pathlib import Path\nimport pycocotools\nfrom pycocotools import mask\nimport numpy.random\nimport random\nimport cv2\nimport re\nimport shutil\ntry:\n    from itertools import  ifilterfalse\nexcept ImportError: # py3k\n    from itertools import  filterfalse\nfrom mmseg.datasets import build_dataset\nfrom mmseg.models import build_segmentor\nfrom mmseg.apis import train_segmentor\nfrom mmseg.apis import inference_segmentor, init_segmentor, show_result_pyplot, set_random_seed","metadata":{"papermill":{"duration":28.752894,"end_time":"2021-10-28T17:40:33.786328","exception":false,"start_time":"2021-10-28T17:40:05.033434","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-10-26T12:52:45.367936Z","iopub.execute_input":"2022-10-26T12:52:45.368441Z","iopub.status.idle":"2022-10-26T12:52:50.528231Z","shell.execute_reply.started":"2022-10-26T12:52:45.368395Z","shell.execute_reply":"2022-10-26T12:52:50.525902Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%cd ..","metadata":{"papermill":{"duration":0.077806,"end_time":"2021-10-28T17:40:33.91703","exception":false,"start_time":"2021-10-28T17:40:33.839224","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-10-26T12:52:50.530055Z","iopub.execute_input":"2022-10-26T12:52:50.530358Z","iopub.status.idle":"2022-10-26T12:52:50.544346Z","shell.execute_reply.started":"2022-10-26T12:52:50.530316Z","shell.execute_reply":"2022-10-26T12:52:50.543281Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### deal input images\n[122](11111)","metadata":{}},{"cell_type":"code","source":"def rle_encode(img):\n    pixels = img.flatten()\n    pixels = np.concatenate([[0], pixels, [0]])\n    runs = np.where(pixels[1:] != pixels[:-1])[0] + 1\n    print(runs[1::2].shape, runs[::2].shape)\n    runs[1::2] -= runs[::2]\n    \n    return ' '.join(str(x) for x in runs)\n\n\ndef rle_encode_less_memory(img):\n    pixels = img.T.flatten()\n    pixels[0] = 0\n    pixels[-1] = 0\n    runs = np.where(pixels[1:] != pixels[:-1])[0] + 2\n    #  print(runs.shape) should be odd, but i got an even sometimes\n    runs[1::2] -= runs[::2]\n    \n    return ' '.join(str(x) for x in runs)\n\n\n","metadata":{"papermill":{"duration":0.066347,"end_time":"2021-10-28T17:40:34.262446","exception":false,"start_time":"2021-10-28T17:40:34.196099","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-10-26T12:52:50.546741Z","iopub.execute_input":"2022-10-26T12:52:50.547056Z","iopub.status.idle":"2022-10-26T12:52:50.559338Z","shell.execute_reply.started":"2022-10-26T12:52:50.547015Z","shell.execute_reply":"2022-10-26T12:52:50.558352Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bs = 64\nsz = 256\nreduce = 4\nTH = 0.225\nDATA = '../input/hubmap-organ-segmentation/test_images/'\n","metadata":{"execution":{"iopub.status.busy":"2022-10-26T12:52:50.561208Z","iopub.execute_input":"2022-10-26T12:52:50.561645Z","iopub.status.idle":"2022-10-26T12:52:50.567991Z","shell.execute_reply.started":"2022-10-26T12:52:50.561527Z","shell.execute_reply":"2022-10-26T12:52:50.567103Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Helper Functions**","metadata":{"papermill":{"duration":0.052766,"end_time":"2021-10-28T17:40:34.030284","exception":false,"start_time":"2021-10-28T17:40:33.977518","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"# **Helper Dataset**","metadata":{}},{"cell_type":"code","source":"mean = np.array([0.7720342, 0.74582646, 0.76392896])\nstd = np.array([0.24745085, 0.26182273, 0.25782376])\n\ns_th = 40  #saturation blancking threshold\np_th = 1000*(sz//256)**2 #threshold for the minimum number of pixels\nidentity = rasterio.Affine(1, 0, 0, 0, 1, 0)\n\ndef img2tensor(img,dtype:np.dtype=np.float32):\n    if img.ndim==2 : img = np.expand_dims(img,2)\n    img = np.transpose(img,(2,0,1))\n    return torch.from_numpy(img.astype(dtype, copy=False))\n\n\nclass HuBMAPDataset(Dataset):\n    def __init__(self, idx, sz=sz, reduce=reduce):\n        self.data = rasterio.open(os.path.join(DATA,idx+'.tiff'), transform = identity, \n                                 num_threads='all_cpus')\n        # some images have issues with their format \n        # and must be saved correctly before reading with rasterio\n        if self.data.count != 3:\n            subdatasets = self.data.subdatasets\n            self.layers = []\n            if len(subdatasets) > 0:\n                for i, subdataset in enumerate(subdatasets, 0):\n                    self.layers.append(rasterio.open(subdataset))\n        self.shape = self.data.shape\n        self.reduce = reduce\n        self.sz = reduce*sz\n        self.pad0 = (self.sz - self.shape[0]%self.sz)%self.sz\n        self.pad1 = (self.sz - self.shape[1]%self.sz)%self.sz\n        self.n0max = (self.shape[0] + self.pad0)//self.sz\n        self.n1max = (self.shape[1] + self.pad1)//self.sz\n        \n    def __len__(self):\n        return self.n0max*self.n1max\n    \n    def __getitem__(self, idx):\n        # the code below may be a little bit difficult to understand,\n        # but the thing it does is mapping the original image to\n        # tiles created with adding padding, as done in\n        # https://www.kaggle.com/iafoss/256x256-images ,\n        # and then the tiles are loaded with rasterio\n        # n0,n1 - are the x and y index of the tile (idx = n0*self.n1max + n1)\n        n0,n1 = idx//self.n1max, idx%self.n1max\n        # x0,y0 - are the coordinates of the lower left corner of the tile in the image\n        # negative numbers correspond to padding (which must not be loaded)\n        x0,y0 = -self.pad0//2 + n0*self.sz, -self.pad1//2 + n1*self.sz\n        # make sure that the region to read is within the image\n        p00,p01 = max(0,x0), min(x0+self.sz,self.shape[0])\n        p10,p11 = max(0,y0), min(y0+self.sz,self.shape[1])\n        img = np.zeros((self.sz,self.sz,3),np.uint8)\n        # mapping the loade region to the tile\n        if self.data.count == 3:\n            img[(p00-x0):(p01-x0),(p10-y0):(p11-y0)] = np.moveaxis(self.data.read([1,2,3],\n                window=Window.from_slices((p00,p01),(p10,p11))), 0, -1)\n        else:\n            for i,layer in enumerate(self.layers):\n                img[(p00-x0):(p01-x0),(p10-y0):(p11-y0),i] =\\\n                  layer.read(1,window=Window.from_slices((p00,p01),(p10,p11)))\n        \n        if self.reduce != 1:\n            img = cv2.resize(img,(self.sz//reduce,self.sz//reduce),\n                             interpolation = cv2.INTER_AREA)\n            img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n        #check for empty imges\n#         img = img.cvtColor(img, )\n#         cv2.imwrite('demo.jpg', img)\n#         print(img)\n#         img here is what we need\n        hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)\n        h,s,v = cv2.split(hsv)\n        if (s>s_th).sum() <= p_th or img.sum() <= p_th:\n            #images with -1 will be skipped\n            return img, -1\n        else: return img, idx","metadata":{"execution":{"iopub.status.busy":"2022-10-26T13:02:24.934285Z","iopub.execute_input":"2022-10-26T13:02:24.934548Z","iopub.status.idle":"2022-10-26T13:02:24.952162Z","shell.execute_reply.started":"2022-10-26T13:02:24.934518Z","shell.execute_reply":"2022-10-26T13:02:24.951477Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_mask_from_result(result):\n    d = {True : 1, False : 0}\n    u,inv = np.unique(result,return_inverse = True)\n    mk = cp.array([d[x] for x in u])[inv].reshape(result.shape)\n#     print(mk.shape)\n    return mk","metadata":{"papermill":{"duration":0.062139,"end_time":"2021-10-28T17:40:34.493003","exception":false,"start_time":"2021-10-28T17:40:34.430864","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-10-26T12:52:50.607553Z","iopub.execute_input":"2022-10-26T12:52:50.608593Z","iopub.status.idle":"2022-10-26T12:52:50.615897Z","shell.execute_reply.started":"2022-10-26T12:52:50.608504Z","shell.execute_reply":"2022-10-26T12:52:50.614896Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def does_overlap(mask, other_masks):\n    for other_mask in other_masks:\n        if np.sum(np.logical_and(mask, other_mask)) > 0:\n            return True\n    return False\n\n\ndef remove_overlapping_pixels(mask, other_masks):\n    for other_mask in other_masks:\n        if np.sum(np.logical_and(mask, other_mask)) > 0:\n            print(\"Overlap detected\")\n            mask[np.logical_and(mask, other_mask)] = 0\n    return mask","metadata":{"papermill":{"duration":0.063539,"end_time":"2021-10-28T17:40:34.610553","exception":false,"start_time":"2021-10-28T17:40:34.547014","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-10-26T12:52:50.618632Z","iopub.execute_input":"2022-10-26T12:52:50.621096Z","iopub.status.idle":"2022-10-26T12:52:50.630776Z","shell.execute_reply.started":"2022-10-26T12:52:50.621059Z","shell.execute_reply":"2022-10-26T12:52:50.629958Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_img_and_mask(img_path, annotation, width, height):\n    \"\"\" Capture the relevant image array as well as the image mask \"\"\"\n    img_mask = np.zeros((height, width), dtype=np.uint8)\n    for i, annot in enumerate(annotation): \n        img_mask = np.where(rle_decode(annot, (height, width))!=0, i, img_mask)\n    img = cv2.imread(img_path)[..., ::-1]\n    return img[..., 0], img_mask\n","metadata":{"execution":{"iopub.status.busy":"2022-10-26T12:52:50.634890Z","iopub.execute_input":"2022-10-26T12:52:50.635390Z","iopub.status.idle":"2022-10-26T12:52:50.645039Z","shell.execute_reply.started":"2022-10-26T12:52:50.635353Z","shell.execute_reply":"2022-10-26T12:52:50.644359Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Model**","metadata":{"papermill":{"duration":0.053488,"end_time":"2021-10-28T17:40:34.718633","exception":false,"start_time":"2021-10-28T17:40:34.665145","status":"completed"},"tags":[]}},{"cell_type":"code","source":"from mmcv import Config\n# cfg = Config.fromfile('../input/hubpretrainedmodel/swin_upernet_0814.py')","metadata":{"papermill":{"duration":0.083816,"end_time":"2021-10-28T17:40:34.857025","exception":false,"start_time":"2021-10-28T17:40:34.773209","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-10-26T12:52:50.649383Z","iopub.execute_input":"2022-10-26T12:52:50.651126Z","iopub.status.idle":"2022-10-26T12:52:50.657898Z","shell.execute_reply.started":"2022-10-26T12:52:50.651089Z","shell.execute_reply":"2022-10-26T12:52:50.656858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# modify model\n# cfg.model.decode_head.num_classes = 6\n# cfg.model.auxiliary_head.num_classes = 6","metadata":{"papermill":{"duration":0.784288,"end_time":"2021-10-28T17:40:35.695074","exception":false,"start_time":"2021-10-28T17:40:34.910786","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-10-26T12:52:50.663235Z","iopub.execute_input":"2022-10-26T12:52:50.664397Z","iopub.status.idle":"2022-10-26T12:52:50.670350Z","shell.execute_reply.started":"2022-10-26T12:52:50.664333Z","shell.execute_reply":"2022-10-26T12:52:50.668637Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Inference**","metadata":{"papermill":{"duration":0.0544,"end_time":"2021-10-28T17:40:35.805148","exception":false,"start_time":"2021-10-28T17:40:35.750748","status":"completed"},"tags":[]}},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"configs = [\n#     '../input/mmseg-trainning-convx/config.py',\n#     '../input/mmseg-trainning-convx/config.py',\n#     '../input/training-mae/config.py',\n    '../input/train-patches/config.py',\n#     '../input/hubpretrainedmodel/swin_upernet_0824.py',\n#     '../input/training-mae/seg_model_output/config.py',\n     \n]\nckpts = [\n#     '../input/mmseg-trainning-convx/seg_model_output/iter_8000.pth',\n    '../input/train-patches/seg_model_output/iter_5000.pth',\n#     '../input/training-mae/seg_model_output/iter_5000.pth',\n#     '../input/mmseg-trainning-convx/seg_model_output/iter_9000.pth',\n#     '../input/hubpretrainedmodel/20220824_upernet.pth',\n#     '../input/training-mae/seg_model_output/iter_5000.pth',\n     \n]\nweights = [0.3, 0.6, 0.1]\nmodels = []\nnorm_cfg = dict(type='BN', requires_grad=True)\nfor idx,(cfg, ckpt) in enumerate(zip(configs, ckpts)):\n    cfg = Config.fromfile(cfg)\n#     cfg.model.neck['norm_cfg'] = norm_cfg\n#     cfg.model.decode_head.norm_cfg=norm_cfg\n#     cfg.model.test_cfg.crop_size=(256, 256)\n    cfg.model.test_cfg.mode=\"whole\"\n    model = init_segmentor(cfg, ckpt, device='cuda:0')\n    models.append(model)","metadata":{"papermill":{"duration":0.063514,"end_time":"2021-10-28T17:40:36.292327","exception":false,"start_time":"2021-10-28T17:40:36.228813","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-10-26T13:03:14.080399Z","iopub.execute_input":"2022-10-26T13:03:14.080664Z","iopub.status.idle":"2022-10-26T13:03:15.572220Z","shell.execute_reply.started":"2022-10-26T13:03:14.080634Z","shell.execute_reply":"2022-10-26T13:03:15.571423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# model = init_segmentor(cfg, '../input/hubpretrainedmodel/20220814_upernet.pth')\n# change to train_images for test\n\n\nnames,preds = [],[]\n# print(DATA)\ndebug = len(os.listdir(DATA))<2\nfor file in sorted(os.listdir(DATA)):\n    \n    idx = file[:-5]\n    img = cv2.imread(os.path.join(DATA,idx+'.tiff'))\n    ds = HuBMAPDataset(idx)\n    dl = DataLoader(ds,bs,num_workers=0,shuffle=False,pin_memory=True)\n    mp = []\n\n    for x, y in iter(dl):\n        x = np.uint8(x)\n        for i in range(len(ds)):\n            masks_tile = []\n            pred_tile = np.zeros(x[i].shape[:-1], dtype=float)\n            for model in models:\n                res_i = inference_segmentor(model, x[i])\n                if debug:\n                    show_result_pyplot(model, x[i], res_i)\n                mp_i = res_i[0]\n                masks_tile.append(mp_i)\n            pred_tile = masks_tile[0]\n#             pred_tile = (pred_tile > 0).astype(np.uint8)\n            mp.append(pred_tile)\n    #generate masks\n    \n    mask = np.zeros((len(ds),ds.sz,ds.sz))\n    \n    for i in range(len(mp)):\n#         mp[i] = np.uint8(mp[i])\n        p_t = cv2.resize(mp[i], (ds.sz,ds.sz), interpolation=cv2.INTER_NEAREST)\n        mask[i] = p_t\n    mask = torch.from_numpy(mask)\n    #reshape tiled masks into a single mask and crop padding\n    #TODO↓\n    mask = mask.view(ds.n0max,ds.n1max,ds.sz,ds.sz).\\\n        permute(0,2,1,3).reshape(ds.n0max*ds.sz,ds.n1max*ds.sz)\n    mask = mask[ds.pad0//2:-(ds.pad0-ds.pad0//2) if ds.pad0 > 0 else ds.n0max*ds.sz,\n        ds.pad1//2:-(ds.pad1-ds.pad1//2) if ds.pad1 > 0 else ds.n1max*ds.sz]\n    mask = mask.numpy()\n    mask = (mask>0).astype(np.uint8)\n    \n    #convert to rle\n    if debug:\n        columns, rows = 4,4\n        idx0 = 20\n        fig=plt.figure(figsize=(columns*4, rows*4))\n        fig.add_subplot(rows, columns, 1)\n        plt.axis('off')\n        plt.imshow(img)\n        plt.imshow(mask, alpha=0.5)\n        plt.title(idx)\n        plt.show()\n    #https://www.kaggle.com/bguberfain/memory-aware-rle-encoding\n    \n    rle = rle_encode_less_memory(mask)\n    names.append(idx)\n    preds.append(rle)\n\n    del mask, ds, dl, mp\n    gc.collect()\n\n            \n","metadata":{"papermill":{"duration":54.072416,"end_time":"2021-10-28T17:41:30.419105","exception":false,"start_time":"2021-10-28T17:40:36.346689","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-10-26T13:03:20.635355Z","iopub.execute_input":"2022-10-26T13:03:20.635610Z","iopub.status.idle":"2022-10-26T13:03:36.637279Z","shell.execute_reply.started":"2022-10-26T13:03:20.635581Z","shell.execute_reply":"2022-10-26T13:03:36.636515Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.DataFrame({'id':names,'rle':preds})\ndf.to_csv('submission.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2022-10-26T12:53:16.021889Z","iopub.execute_input":"2022-10-26T12:53:16.022620Z","iopub.status.idle":"2022-10-26T12:53:16.039051Z","shell.execute_reply.started":"2022-10-26T12:53:16.022581Z","shell.execute_reply":"2022-10-26T12:53:16.038213Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df","metadata":{"execution":{"iopub.status.busy":"2022-10-26T12:53:16.040595Z","iopub.execute_input":"2022-10-26T12:53:16.040859Z","iopub.status.idle":"2022-10-26T12:53:16.057973Z","shell.execute_reply.started":"2022-10-26T12:53:16.040826Z","shell.execute_reply":"2022-10-26T12:53:16.057176Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"shutil.rmtree('/kaggle/working/mmsegmentation')","metadata":{"papermill":{"duration":0.169468,"end_time":"2021-10-28T17:41:35.314035","exception":false,"start_time":"2021-10-28T17:41:35.144567","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-10-26T12:53:16.059235Z","iopub.execute_input":"2022-10-26T12:53:16.059580Z","iopub.status.idle":"2022-10-26T12:53:16.142519Z","shell.execute_reply.started":"2022-10-26T12:53:16.059545Z","shell.execute_reply":"2022-10-26T12:53:16.141932Z"},"trusted":true},"execution_count":null,"outputs":[]}]}