{"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-24T05:10:02.935753Z","iopub.execute_input":"2022-09-24T05:10:02.936095Z","iopub.status.idle":"2022-09-24T05:10:02.964068Z","shell.execute_reply.started":"2022-09-24T05:10:02.936017Z","shell.execute_reply":"2022-09-24T05:10:02.963189Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import sys\nsys.path.append('../input/einops/einops-master')\nsys.path.append('../input/timmmaster')\nsys.path.append('../input/coats1024-hpamodel')\n\n!pip install ../input/staintools-offline/spams-2.6.5.4-cp37-cp37m-linux_x86_64.whl &> /dev/null\n!pip install ../input/staintools-offline/staintools-2.1.2-py3-none-any.whl &> /dev/null","metadata":{"execution":{"iopub.status.busy":"2022-09-24T05:10:02.966924Z","iopub.execute_input":"2022-09-24T05:10:02.967261Z","iopub.status.idle":"2022-09-24T05:11:05.261143Z","shell.execute_reply.started":"2022-09-24T05:10:02.967234Z","shell.execute_reply":"2022-09-24T05:11:05.259838Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import staintools\nimport tifffile\nimport cv2\nimport numpy as np\nfrom utils import *\nimport gc","metadata":{"execution":{"iopub.status.busy":"2022-09-24T05:11:05.264260Z","iopub.execute_input":"2022-09-24T05:11:05.264585Z","iopub.status.idle":"2022-09-24T05:11:07.567264Z","shell.execute_reply.started":"2022-09-24T05:11:05.264556Z","shell.execute_reply":"2022-09-24T05:11:07.566120Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Import CoaT and conv3x3, and create the new network that consists of the two nets","metadata":{}},{"cell_type":"code","source":"from net_hub import *\n\nclass NetHUB(nn.Module):\n    def __init__(self,\n                 encoder=coat_small_plus,\n                 decoder=daformer_conv3x3,\n                 encoder_cfg={},\n                 decoder_cfg={}):\n        super(NetHUB, self).__init__()\n        decoder_dim = decoder_cfg.get('decoder_dim', 320)\n        self.output_type = ['inference']\n        self.rgb = RGB()\n        self.encoder = encoder\n        encoder_dim = self.encoder.embed_dims\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\n        self.aux = nn.ModuleList([\n            nn.Conv2d(decoder_dim, 1, kernel_size=1, padding=0) for i in range(5)])\n\n    def forward(self, batch):\n        x = batch['image']\n        x = self.rgb(x)\n        B, C, H, W = x.shape\n\n        encoder = self.encoder(x)\n        last, decoder = self.decoder(encoder)\n\n        logit = self.logit(last)\n        logit = F.interpolate(logit, size=None, scale_factor=4, mode='bilinear', align_corners=False)\n        output = {}\n        if 'inference' in self.output_type:\n            output['probability'] = torch.sigmoid(logit)\n        return output","metadata":{"execution":{"iopub.status.busy":"2022-09-24T05:11:15.553512Z","iopub.execute_input":"2022-09-24T05:11:15.553897Z","iopub.status.idle":"2022-09-24T05:11:15.580696Z","shell.execute_reply.started":"2022-09-24T05:11:15.553858Z","shell.execute_reply":"2022-09-24T05:11:15.579749Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### define stochastic weight averaing","metadata":{}},{"cell_type":"code","source":"# SWA function\ndef do_swa(checkpoints):\n    swa_state_dict = torch.load(checkpoints[0], map_location=lambda storage, loc: storage)\n    for k,v in swa_state_dict.items():\n        swa_state_dict[k] = torch.zeros_like(v)\n    for m in range(len(checkpoints)):\n        if m == 0:\n            state_dict = torch.load(checkpoints[m], map_location=lambda storage, loc:storage)\n            for k, v in state_dict.items():\n                swa_state_dict[k] += v\n        else:\n            state_dict = torch.load(checkpoints[m], map_location=lambda storage, loc:storage)\n            for k, v in state_dict.items():\n                swa_state_dict[k] += v\n    for k,v in swa_state_dict.items():\n        swa_state_dict[k] /= np.array(len(checkpoints)).astype(float)\n    print(f'SWAed{checkpoints}')\n    print()\n    return swa_state_dict","metadata":{"execution":{"iopub.status.busy":"2022-09-24T05:11:15.584194Z","iopub.execute_input":"2022-09-24T05:11:15.584928Z","iopub.status.idle":"2022-09-24T05:11:15.595530Z","shell.execute_reply.started":"2022-09-24T05:11:15.584890Z","shell.execute_reply":"2022-09-24T05:11:15.594508Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### kidney","metadata":{}},{"cell_type":"code","source":"## Fold0\nswa_0 = do_swa(['../input/swa-comparison-fold0/Fold0_IoU0.685_Dice0.768_BCE0.118_TB0.071_104.pth',\n              '../input/swa-comparison-fold0/Fold0_IoU0.675_Dice0.759_BCE0.127_TB0.063_122.pth',\n              '../input/swa-comparison-fold0/Fold0_IoU0.682_Dice0.765_BCE0.127_TB0.062_134.pth'\n              ])\nnet_0 = NetHUB(encoder=coat_small_plus()).cuda()\nnet_0.load_state_dict(swa_0)\nnet_0.eval()\nnet_0.output_type = ['inference']","metadata":{"execution":{"iopub.status.busy":"2022-09-24T05:11:15.597009Z","iopub.execute_input":"2022-09-24T05:11:15.597342Z","iopub.status.idle":"2022-09-24T05:11:20.840451Z","shell.execute_reply.started":"2022-09-24T05:11:15.597315Z","shell.execute_reply":"2022-09-24T05:11:20.839464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## Fold1\nswa_1 = do_swa(['../input/coatsp1024-bilinear-fold1/Fold1_IoU0.68_Dice0.757_BCE0.074_TB0.085_99.pth',\n              '../input/coatsp1024-bilinear-fold1/Fold1_IoU0.68_Dice0.758_BCE0.083_TB0.083_127.pth',\n              '../input/coatsp1024-bilinear-fold1/Fold1_IoU0.698_Dice0.77_BCE0.067_TB0.08_113.pth'\n              ])\nnet_1 = NetHUB(encoder=coat_small_plus()).cuda()\nnet_1.load_state_dict(swa_1)\nnet_1.eval()\nnet_1.output_type = ['inference']","metadata":{"execution":{"iopub.status.busy":"2022-09-24T05:11:20.841786Z","iopub.execute_input":"2022-09-24T05:11:20.842133Z","iopub.status.idle":"2022-09-24T05:11:26.260376Z","shell.execute_reply.started":"2022-09-24T05:11:20.842100Z","shell.execute_reply":"2022-09-24T05:11:26.259386Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## Fold2\nswa_2 = do_swa(['../input/coatsp1024-bilinear-fold2/Fold2_IoU0.711_Dice0.79_BCE0.07_TB0.064_102.pth',\n              '../input/coatsp1024-bilinear-fold2/Fold2_IoU0.711_Dice0.792_BCE0.073_TB0.073_90.pth',\n              '../input/coatsp1024-bilinear-fold2/Fold2_IoU0.715_Dice0.794_BCE0.072_TB0.073_91.pth'\n              ])\nnet_2 = NetHUB(encoder=coat_small_plus()).cuda()\nnet_2.load_state_dict(swa_2)\nnet_2.eval()\nnet_2.output_type = ['inference']","metadata":{"execution":{"iopub.status.busy":"2022-09-24T05:11:26.264753Z","iopub.execute_input":"2022-09-24T05:11:26.265045Z","iopub.status.idle":"2022-09-24T05:11:31.979869Z","shell.execute_reply.started":"2022-09-24T05:11:26.265019Z","shell.execute_reply":"2022-09-24T05:11:31.978889Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## Fold3\nswa_3 = do_swa(['../input/coastp1024-bilinear-fold3-new/Fold3_IoU0.694_Dice0.767_BCE0.075_TB0.071_110.pth',\n              '../input/coastp1024-bilinear-fold3-new/Fold3_IoU0.695_Dice0.768_BCE0.073_TB0.068_99.pth',\n              '../input/coastp1024-bilinear-fold3-new/Fold3_IoU0.699_Dice0.773_BCE0.074_TB0.068_92.pth'\n              ])\nnet_3 = NetHUB(encoder=coat_small_plus()).cuda()\nnet_3.load_state_dict(swa_3)\nnet_3.eval()\nnet_3.output_type = ['inference']","metadata":{"execution":{"iopub.status.busy":"2022-09-24T05:11:31.981477Z","iopub.execute_input":"2022-09-24T05:11:31.982133Z","iopub.status.idle":"2022-09-24T05:11:38.065125Z","shell.execute_reply.started":"2022-09-24T05:11:31.982090Z","shell.execute_reply":"2022-09-24T05:11:38.064058Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## Fold4\nswa_4 = do_swa(['../input/coatsp1024-bilinearfold4-originaldata/Fold4_Dice0.75_BCE0.075_TB0.074_127.pth',\n              '../input/coatsp1024-bilinearfold4-originaldata/Fold4_IoU0.678_Dice0.754_BCE0.068_TB0.08_103.pth',\n              '../input/coatsp1024-bilinearfold4-originaldata/Fold4_Dice0.75_BCE0.072_TB0.067_131.pth'\n              ])\nnet_4 = NetHUB(encoder=coat_small_plus()).cuda()\nnet_4.load_state_dict(swa_4)\nnet_4.eval()\nnet_4.output_type = ['inference']","metadata":{"execution":{"iopub.status.busy":"2022-09-24T05:11:38.069006Z","iopub.execute_input":"2022-09-24T05:11:38.071425Z","iopub.status.idle":"2022-09-24T05:11:43.469188Z","shell.execute_reply.started":"2022-09-24T05:11:38.071384Z","shell.execute_reply":"2022-09-24T05:11:43.468184Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## Combined net\nnets = []\nnets.append(net_0)\nnets.append(net_1)\nnets.append(net_2)\nnets.append(net_3)\nnets.append(net_4)","metadata":{"execution":{"iopub.status.busy":"2022-09-24T05:11:43.470595Z","iopub.execute_input":"2022-09-24T05:11:43.470970Z","iopub.status.idle":"2022-09-24T05:11:43.477979Z","shell.execute_reply.started":"2022-09-24T05:11:43.470926Z","shell.execute_reply":"2022-09-24T05:11:43.476684Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### lung","metadata":{}},{"cell_type":"code","source":"import glob\nlung_paths = [[fn for fn in glob.glob('../input/lung-fold0/*.pth')]] +\\\n            [[fn for fn in glob.glob('../input/lung-fold1/*.pth')]] +\\\n            [[fn for fn in glob.glob('../input/lung-fold2/*.pth')]] +\\\n            [[fn for fn in glob.glob('../input/lung-fold3/*.pth')]] +\\\n            [[fn for fn in glob.glob('../input/lung-fold4/*.pth')]] +\\\n            [[fn for fn in glob.glob('../input/lung-fold5/*.pth')]]\n\nnets_lung = []\nfor path in lung_paths:\n    if type(path) == list:\n        swa = do_swa(path)\n    else: \n        swa = do_swa([path])\n    model = NetHUB(encoder=coat_small_plus()).cuda()\n    model.load_state_dict(swa)\n    model.eval()\n    model.output_type = ['inference']\n    nets_lung.append(model)","metadata":{"execution":{"iopub.status.busy":"2022-09-24T05:11:43.480008Z","iopub.execute_input":"2022-09-24T05:11:43.480788Z","iopub.status.idle":"2022-09-24T05:12:14.948648Z","shell.execute_reply.started":"2022-09-24T05:11:43.480744Z","shell.execute_reply":"2022-09-24T05:12:14.947676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### spleen","metadata":{}},{"cell_type":"code","source":"spleen_paths = [[fn for fn in glob.glob('../input/spleen768-fold0/*.pth')]]+\\\n                [[fn for fn in glob.glob('../input/spleen768-fold1/*.pth')]]+\\\n                [[fn for fn in glob.glob('../input/spleen768-fold2/*.pth')]]+\\\n                [[fn for fn in glob.glob('../input/spleen768-fold3/*.pth')]]+\\\n                [[fn for fn in glob.glob('../input/spleen768-fold4/*.pth')]]\n                        \nnets_spleen = []\nfor path in spleen_paths:\n    if type(path) == list:\n        swa = do_swa(path)\n    else: \n        swa = do_swa([path])\n    net_spleen = NetHUB(encoder=coat_small_plus()).cuda()        \n    net_spleen.load_state_dict(swa)\n    net_spleen.eval()\n    net_spleen.output_type = ['inference']\n    nets_spleen.append(net_spleen)","metadata":{"execution":{"iopub.status.busy":"2022-09-24T05:12:14.950017Z","iopub.execute_input":"2022-09-24T05:12:14.951041Z","iopub.status.idle":"2022-09-24T05:12:39.994614Z","shell.execute_reply.started":"2022-09-24T05:12:14.950998Z","shell.execute_reply":"2022-09-24T05:12:39.993607Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### prostate","metadata":{}},{"cell_type":"code","source":"prostate_paths = [[fn for fn in glob.glob('../input/prostate-fold0/*.pth')]] +\\\n                [[fn for fn in glob.glob('../input/prostate-fold1/*.pth')]] +\\\n                [[fn for fn in glob.glob('../input/prostate-fold2/*.pth')]] +\\\n                [[fn for fn in glob.glob('../input/prostate-fold3/*.pth')]] +\\\n                [[fn for fn in glob.glob('../input/prostate-fold4/*.pth')]]\n\nnets_prostate = []\nfor path in prostate_paths:\n    if type(path) == list:\n        swa = do_swa(path)\n    else: \n        swa = do_swa([path])\n    net_prostate = NetHUB(encoder=coat_small_plus()).cuda()        \n    net_prostate.load_state_dict(swa)\n    net_prostate.eval()\n    net_prostate.output_type = ['inference']\n    nets_prostate.append(net_prostate)","metadata":{"execution":{"iopub.status.busy":"2022-09-24T05:12:39.996366Z","iopub.execute_input":"2022-09-24T05:12:39.996762Z","iopub.status.idle":"2022-09-24T05:13:05.875479Z","shell.execute_reply.started":"2022-09-24T05:12:39.996725Z","shell.execute_reply":"2022-09-24T05:13:05.874505Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### large intestine","metadata":{}},{"cell_type":"code","source":"intestine_paths = [[fn for fn in glob.glob('../input/intestine-fold0/*.pth')]] +\\\n                [[fn for fn in glob.glob('../input/intestine-fold1/*.pth')]] +\\\n                [[fn for fn in glob.glob('../input/intestine-fold2/*.pth')]] +\\\n                [[fn for fn in glob.glob('../input/intestine-fold3/*.pth')]] +\\\n                [[fn for fn in glob.glob('../input/intestine-fold4/*.pth')]]\n\nnets_intestine = []\nfor path in intestine_paths:\n    if type(path) == list:\n        swa = do_swa(path)\n    else: \n        swa = do_swa([path])\n    net_intestine = NetHUB(encoder=coat_small_plus()).cuda()        \n    net_intestine.load_state_dict(swa)\n    net_intestine.eval()\n    net_intestine.output_type = ['inference']\n    nets_intestine.append(net_intestine)","metadata":{"execution":{"iopub.status.busy":"2022-09-24T05:13:05.877281Z","iopub.execute_input":"2022-09-24T05:13:05.877874Z","iopub.status.idle":"2022-09-24T05:13:31.054785Z","shell.execute_reply.started":"2022-09-24T05:13:05.877821Z","shell.execute_reply":"2022-09-24T05:13:31.053780Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Inference ","metadata":{}},{"cell_type":"code","source":"IMAGE_SIZE = 1024\nSEED = 2021\n\norgan_threshold = { # Each threshold is optimized by manual testing on CV and public HPA and Hubmap data\n    'Hubmap': {                   \n        'kidney'        : 0.45,            \n        'prostate'      : 0.25,   \n        'largeintestine': 0.3,               \n        'spleen'        : 0.35,   \n        'lung'          : 0.1,   \n    },    \n    'HPA': {\n        'kidney'        : 0.5,\n        'prostate'      : 0.5,\n        'largeintestine': 0.5,\n        'spleen'        : 0.5,\n        'lung'          : 0.05,\n    },\n}\ndata_source =['Hubmap', 'HPA']\norgan = ['kidney', 'prostate', 'largeintestine', 'spleen', 'lung']\n\ntest_file = '../input/hubmap-organ-segmentation/test.csv'\ntiff_dir   = '../input/hubmap-organ-segmentation/test_images'\n\ntest_df = pd.read_csv(test_file)\ntest_df.loc[:,'img_area'] = test_df['img_height'] * test_df['img_width']\ntest_df = test_df.sort_values('img_area').reset_index(drop=True)\n\n\nresult = []\n\nfor i, d in test_df.iterrows():\n    id = d['id']\n        \n    if(d['data_source'] in data_source) and (d['organ'] in organ):\n        tiff_file = tiff_dir+'/%d.tiff'%id\n        tiff = read_tiff(tiff_file, 'rgb')\n        \n        if (id != 10078):\n            target = staintools.read_image('../input/hubmap-organ-segmentation/test_images/10078.tiff')\n            target = staintools.LuminosityStandardizer.standardize(target)\n            tiff = staintools.LuminosityStandardizer.standardize(tiff)            \n            if d['data_source'] == 'Hubmap':\n                normalizer = staintools.StainNormalizer(method='vahadane')\n                normalizer.fit(target)\n                tiff = normalizer.transform(tiff)\n                \n        tiff = tiff.astype(np.float32)/255\n        \n\n        if (d['organ'] == 'largeintestine'):\n            image = cv2.resize(tiff, dsize=(1536, 1536), interpolation=cv2.INTER_LINEAR)\n                        \n        elif (d['organ'] == 'spleen'):\n            image = cv2.resize(tiff, dsize=(768, 768), interpolation=cv2.INTER_LINEAR)\n              \n        else:\n            image = cv2.resize(tiff, dsize=(IMAGE_SIZE, IMAGE_SIZE), interpolation=cv2.INTER_LINEAR)\n                    \n        image = image_to_tensor(image, 'rgb')        \n        batch = {k:v.cuda() for k,v in do_tta_batch_hub(image, d.organ).items()}                         \n        probability = 0\n        with torch.no_grad():\n            with torch.cuda.amp.autocast(enabled=True):\n                res = []\n                if d['organ'] == 'lung': # lung\n                    for net_lung in nets_lung:\n                        probability = 0\n                        output = net_lung(batch)\n                        probability += F.interpolate(output['probability'], \n                                                     size=(d.img_height, d.img_width),\n                                                     mode='bilinear',\n                                                     align_corners=False,\n                                                     antialias=True)\n                        probability = undo_tta_batch_hub(probability)\n                        res.append(probability)\n                elif d['organ'] == 'spleen': # spleen\n                    for net_spleen in nets_spleen:\n                        probability = 0\n                        output = net_spleen(batch)          \n                        probability += F.interpolate(output['probability'], \n                                                     size=(d.img_height, d.img_width),\n                                                     mode='bilinear',\n                                                     align_corners=False,\n                                                     antialias=True)\n                        probability = undo_tta_batch_hub(probability)\n                        res.append(probability)\n                elif d['organ'] == 'largeintestine': # largeintestine\n                    for net_intestine in nets_intestine:\n                        probability = 0\n                        output = net_intestine(batch)          \n                        probability += F.interpolate(output['probability'], \n                                                     size=(d.img_height, d.img_width),\n                                                     mode='bilinear',\n                                                     align_corners=False,\n                                                     antialias=True)\n                        probability = undo_tta_batch_hub(probability)\n                        res.append(probability)\n                elif d['organ'] == 'prostate': # prostate\n                    for net_prostate in nets_prostate:\n                        probability = 0\n                        output = net_prostate(batch)          \n                        probability += F.interpolate(output['probability'], \n                                                     size=(d.img_height, d.img_width),\n                                                     mode='bilinear',\n                                                     align_corners=False,\n                                                     antialias=True)\n                        probability = undo_tta_batch_hub(probability)\n                        res.append(probability)\n                else: # kidney\n                    for net in nets:\n                        probability = 0\n                        output = net(batch)\n                        probability += F.interpolate(output['probability'], \n                                                     size=(d.img_height, d.img_width),\n                                                     mode='bilinear',\n                                                     align_corners=False,\n                                                     antialias=True)\n                        probability = undo_tta_batch_hub(probability)\n                        res.append(probability)                    \n                res = torch.stack(res)\n                probability = torch.mean(res, dim=0)                                        \n        probability = probability.data.cpu().numpy()\n        p = probability > organ_threshold[d.data_source][d.organ]\n        rle = rle_encode_less_memory(p)        \n\n    else:\n        rle = ''\n        \n    if id == 10078:\n        import matplotlib.pyplot as plt \n        m = tiff\n        p = probability\n        sbmt = probability > organ_threshold[d.data_source][d.organ]\n\n        plt.figure(figsize=(12, 7))\n        plt.subplot(1, 4, 1); plt.imshow(m); plt.axis('OFF'); plt.title('image')\n        plt.subplot(1, 4, 2); plt.imshow(p*255); plt.axis('OFF'); plt.title('mask')\n        plt.subplot(1, 4, 3); plt.imshow(m); plt.imshow(p*255, alpha=0.4); plt.axis('OFF'); plt.title('overlay')\n        plt.subplot(1, 4, 4); plt.imshow(m); plt.imshow(sbmt*255, alpha=0.4); plt.axis('OFF'); plt.title('submit')\n        plt.tight_layout()\n        plt.show()\n            \n    result.append({ 'id':id, 'rle':rle, })                ","metadata":{"execution":{"iopub.status.busy":"2022-09-24T05:13:31.066369Z","iopub.execute_input":"2022-09-24T05:13:31.067025Z","iopub.status.idle":"2022-09-24T05:13:40.185543Z","shell.execute_reply.started":"2022-09-24T05:13:31.066989Z","shell.execute_reply":"2022-09-24T05:13:40.184551Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub = pd.DataFrame(result)\nsub.to_csv('submission.csv',index=False)\nsub.head()","metadata":{"execution":{"iopub.status.busy":"2022-09-24T05:13:40.186951Z","iopub.execute_input":"2022-09-24T05:13:40.187613Z","iopub.status.idle":"2022-09-24T05:13:40.208061Z","shell.execute_reply.started":"2022-09-24T05:13:40.187576Z","shell.execute_reply":"2022-09-24T05:13:40.207001Z"},"trusted":true},"execution_count":null,"outputs":[]}]}