{"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":"!pip install /kaggle/input/segmodelpytorchwheel/wheel/timm-0.6.12-py3-none-any.whl\n!pip install /kaggle/input/segmodelpytorchwheel/wheel/efficientnet_pytorch-0.7.1-py3-none-any.whl\n!pip install /kaggle/input/segmodelpytorchwheel/wheel/pretrainedmodels-0.7.4-py3-none-any.whl\n!pip install /kaggle/input/segmodelpytorchwheel/wheel/segmentation_models_pytorch-0.3.2-py3-none-any.whl","metadata":{"execution":{"iopub.status.busy":"2023-05-24T04:51:36.245771Z","iopub.execute_input":"2023-05-24T04:51:36.246565Z","iopub.status.idle":"2023-05-24T04:53:43.430652Z","shell.execute_reply.started":"2023-05-24T04:51:36.246525Z","shell.execute_reply":"2023-05-24T04:53:43.429494Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Imports","metadata":{"id":"BKl81qZA8yvl"}},{"cell_type":"markdown","source":"### standard imports","metadata":{"id":"t1EQePfV83O2"}},{"cell_type":"code","source":"import os\nimport shutil\nimport pathlib\n\nfrom PIL import Image\nimport pandas as pd\nimport numpy as np\nimport cv2 as cv\nimport random\nimport matplotlib.pyplot as plt\nfrom tqdm.auto import tqdm\n\nimport torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nfrom torch import optim\n\nfrom torch.utils.data import DataLoader, random_split\nfrom torch.utils.data import Dataset\n\nimport torchvision\nfrom torchvision import datasets\nimport cv2\nfrom torch.cuda import amp\n","metadata":{"id":"6AevVvdl85Um","execution":{"iopub.status.busy":"2023-05-24T04:57:37.226762Z","iopub.execute_input":"2023-05-24T04:57:37.22719Z","iopub.status.idle":"2023-05-24T04:57:37.237265Z","shell.execute_reply.started":"2023-05-24T04:57:37.227151Z","shell.execute_reply":"2023-05-24T04:57:37.236197Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torchvision.transforms as T\nfrom torchvision.transforms import Compose, ToTensor, Resize\nfrom torchvision.utils import make_grid","metadata":{"id":"Dzq3qiLS9-u8","execution":{"iopub.status.busy":"2023-05-24T04:57:38.479557Z","iopub.execute_input":"2023-05-24T04:57:38.482477Z","iopub.status.idle":"2023-05-24T04:57:38.488821Z","shell.execute_reply.started":"2023-05-24T04:57:38.482445Z","shell.execute_reply":"2023-05-24T04:57:38.48788Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Albumentations","metadata":{"id":"Y7NgVvbE-AHU"}},{"cell_type":"code","source":"try:\n    import albumentations as A\n    from albumentations.pytorch import ToTensorV2\n    import segmentation_models_pytorch as smp\nexcept:\n    !pip install -q -U segmentation-models-pytorch albumentations > /dev/null\n    import albumentations as A\n    import segmentation_models_pytorch as smp\n    from albumentations.pytorch import ToTensorV2","metadata":{"id":"NOCIrRda-BYM","execution":{"iopub.status.busy":"2023-05-24T04:57:39.531377Z","iopub.execute_input":"2023-05-24T04:57:39.53173Z","iopub.status.idle":"2023-05-24T04:57:39.541109Z","shell.execute_reply.started":"2023-05-24T04:57:39.531702Z","shell.execute_reply":"2023-05-24T04:57:39.540099Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Config File, Seeds & Devices","metadata":{"id":"qigozplb-TDs"}},{"cell_type":"code","source":"# device = torch.device('cpu')\nif torch.cuda.is_available():\n    device = torch.device('cuda')\nelse:\n    device = torch.device('cpu')\n\ndevice","metadata":{"id":"sfi7e5KrSrsk","outputId":"4fffb542-588e-4cfd-bab3-1d92c84d913d","execution":{"iopub.status.busy":"2023-05-24T04:57:40.082984Z","iopub.execute_input":"2023-05-24T04:57:40.083428Z","iopub.status.idle":"2023-05-24T04:57:40.101838Z","shell.execute_reply.started":"2023-05-24T04:57:40.083394Z","shell.execute_reply":"2023-05-24T04:57:40.101024Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Transforms","metadata":{"id":"Z0bspYGB851c"}},{"cell_type":"code","source":"## Code from https://www.kaggle.com/code/lupin11/40min-data-preprocess\n\nimport os\n\ndef get_ids(tar_path):\n    ids = []\n    for img_id in os.listdir(tar_path):\n        ids.append(img_id)\n    print(f\"{len(ids)} samples in {tar_path}\")\n    return ids\n\ndef mkdir(tar_path, name, prt=False):\n    dir_path = os.path.join(tar_path, name)\n    if os.path.exists(dir_path):\n        if prt:\n            print(f\"{dir_path} exists!\")\n        return dir_path\n    os.mkdir(dir_path)\n    if prt:\n        print(f\"{dir_path} created\")\n    return dir_path\n\n# create a directory to save the result\ndata_path = mkdir(\"/kaggle/working/\", \"data\", True)\n\n# only training data is processed here\ntar_path = \"/kaggle/input/google-research-identify-contrails-reduce-global-warming/test\"\n\n# get ids of each sample\nids = get_ids(tar_path)\n\nimport numpy as np\n\n\ndef false_color(band11, band14, band15):\n    \"\"\"\n    convert bands to rgb that labelers saw\n    \"\"\"\n    def normalize(band, bounds):\n        return (band - bounds[0]) / (bounds[1] - bounds[0])\n    \n    \n    _T11_BOUNDS = (243, 303)\n    _CLOUD_TOP_TDIFF_BOUNDS = (-4, 5)\n    _TDIFF_BOUNDS = (-4, 2)\n\n    r = normalize(band15 - band14, _TDIFF_BOUNDS)\n    g = normalize(band14 - band11, _CLOUD_TOP_TDIFF_BOUNDS)\n    b = normalize(band14, _T11_BOUNDS)\n\n    return np.clip(np.stack([r, g, b], axis=2), 0, 1)\n\nimport gc\nfrom tqdm.notebook import tqdm\n\nN_TIMES_BEFORE = 4\n\nLENGTH = None # 100 for testing, None means processing all the ids\n\nfor i in tqdm(range(len(ids[:LENGTH]))):\n    img_id = ids[i]\n# for img_id in tqdm(ids[:LENGTH]):\n    sample_path = f\"{tar_path}/{img_id}\"\n    band11 = np.load(f\"{sample_path}/band_11.npy\")[..., N_TIMES_BEFORE]\n    band14 = np.load(f\"{sample_path}/band_14.npy\")[..., N_TIMES_BEFORE]\n    band15 = np.load(f\"{sample_path}/band_15.npy\")[..., N_TIMES_BEFORE]\n    #human_pixel_mask = np.load(f\"{sample_path}/human_pixel_masks.npy\")\n    mkdir(data_path, img_id)\n    save_path = f\"{data_path}/{img_id}\"\n    image = false_color(band11, band14, band15)\n    np.save(f\"{save_path}/image.npy\", image.astype('float16'))  # use float16 to save disk space\n   # np.save(f\"{save_path}/label.npy\", human_pixel_mask.astype('float16'))\n    del band11, band14, band15, image\n    if i % 100 == 0:\n        gc.collect()  # very necessary\n        \nimport pandas as pd\nimage_paths = [f\"/kaggle/working/data/{img_id}/image.npy\" for img_id in ids]\n#label_paths = [f\"/kaggle/working/data/{img_id}/label.npy\" for img_id in ids]\ndf = pd.DataFrame({'image': image_paths, 'label': ''})\ndf.to_csv(\"data.csv\", index=False)","metadata":{"execution":{"iopub.status.busy":"2023-05-24T04:57:40.659027Z","iopub.execute_input":"2023-05-24T04:57:40.659608Z","iopub.status.idle":"2023-05-24T04:57:41.053183Z","shell.execute_reply.started":"2023-05-24T04:57:40.659572Z","shell.execute_reply":"2023-05-24T04:57:41.052227Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Count of train records\n! ls -l /kaggle/input/google-research-identify-contrails-reduce-global-warming/train | wc -l\n# Count of val records\n! ls -l /kaggle/input/google-research-identify-contrails-reduce-global-warming/validation | wc -l\n# Count of test records: 2 (verification)\n! ls -l /kaggle/input/google-research-identify-contrails-reduce-global-warming/test | wc -l","metadata":{"execution":{"iopub.status.busy":"2023-05-24T04:57:41.055265Z","iopub.execute_input":"2023-05-24T04:57:41.055949Z","iopub.status.idle":"2023-05-24T04:57:46.688313Z","shell.execute_reply.started":"2023-05-24T04:57:41.055915Z","shell.execute_reply":"2023-05-24T04:57:46.687038Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class CFG:\n    seed          = 101\n    debug         = False # set debug=False for Full Training\n    exp_name      = 'Baselinev2'\n    comment       = 'unet-effnet-b0-256x256-aug2-split2'\n    model_name    = 'Unet'\n    backbone      = 'efficientnet-b0'\n    img_size      = [256, 256]\n    epochs        = 3\n    lr            = 2e-3\n    n_fold        = 5\n    num_classes   = 1\n    device        = torch.device(\"cuda:0\" if torch.cuda.is_available() else \"cpu\")","metadata":{"execution":{"iopub.status.busy":"2023-05-24T04:57:46.692406Z","iopub.execute_input":"2023-05-24T04:57:46.692826Z","iopub.status.idle":"2023-05-24T04:57:46.699681Z","shell.execute_reply.started":"2023-05-24T04:57:46.69279Z","shell.execute_reply":"2023-05-24T04:57:46.698548Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_transforms = {\n    \"train\": A.Compose([\n        A.Resize(*CFG.img_size, interpolation=cv2.INTER_NEAREST),\n        ], p=1.0),\n    \n    \"valid\": A.Compose([\n        A.Resize(*CFG.img_size, interpolation=cv2.INTER_NEAREST),\n        ], p=1.0)\n}","metadata":{"execution":{"iopub.status.busy":"2023-05-24T04:57:46.701106Z","iopub.execute_input":"2023-05-24T04:57:46.70137Z","iopub.status.idle":"2023-05-24T04:57:46.715714Z","shell.execute_reply.started":"2023-05-24T04:57:46.701348Z","shell.execute_reply":"2023-05-24T04:57:46.714823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"IMAGE_SIZE=256\n\ndef train_csv(x,path):\n    y= x.replace(\"/kaggle/working/data/\",f\"{path}\")\n    return y\n\nclass Dataset:\n    def __init__(self,mode,transform =None,is_inference=True):\n        \n        self.is_infer = is_inference\n\n        \n        if mode == 'train':\n            ROOT_PATH = '/kaggle/input/40min-data-preprocess'\n            DATA_PATH = '/kaggle/input/40min-data-preprocess/data/'\n        elif mode =='valid':\n            ROOT_PATH = '/kaggle/input/40min-data-preprocess-2c96b6'\n            DATA_PATH = '/kaggle/input/40min-data-preprocess-2c96b6/data_valid/'\n        else :\n            ROOT_PATH = '/kaggle/working'\n            DATA_PATH = '/kaggle/input/preprocess-test/data/'\n\n\n        df = pd.read_csv(f\"{ROOT_PATH}/data.csv\")\n        \n        if mode != 'test':\n        \n            df[\"image\"]=df[\"image\"].apply(lambda x: train_csv(x,DATA_PATH))\n        \n            if not (self.is_infer):\n                df[\"label\"]=df[\"label\"].apply(lambda x:train_csv(x,DATA_PATH))\n            \n\n        self.images = df['image']\n        self.labels = df['label']\n        self.transform =transform\n    def __getitem__(self, idx):\n        image = np.load(self.images[idx]).astype(float)\n        if not self.is_infer : \n            \n            label = np.load(self.labels[idx]).astype(float)\n            \n            if  self.transform :\n                data = self.transform(image=image, mask=label)\n                image  = data['image']\n                label  = data['mask']\n                image = np.transpose(image, (2, 0, 1))\n                label = np.transpose(label, (2, 0, 1))                \n            return torch.tensor(image), torch.tensor(label)\n        else :\n\n            if  self.transform :\n                data = self.transform(image=image)\n                image  = data['image']\n                image = np.transpose(image, (2, 0, 1))\n            return torch.tensor(image)\n    \n    def __len__(self):\n        return len(self.images)\n\ntest_dataset = Dataset('test',transform =data_transforms['valid'],is_inference=True)    \n\n","metadata":{"execution":{"iopub.status.busy":"2023-05-24T04:57:46.71875Z","iopub.execute_input":"2023-05-24T04:57:46.719474Z","iopub.status.idle":"2023-05-24T04:57:46.738098Z","shell.execute_reply.started":"2023-05-24T04:57:46.719439Z","shell.execute_reply":"2023-05-24T04:57:46.737133Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(test_dataset)","metadata":{"execution":{"iopub.status.busy":"2023-05-24T04:57:46.739702Z","iopub.execute_input":"2023-05-24T04:57:46.740093Z","iopub.status.idle":"2023-05-24T04:57:46.754597Z","shell.execute_reply.started":"2023-05-24T04:57:46.740045Z","shell.execute_reply":"2023-05-24T04:57:46.75367Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## DataLoader","metadata":{}},{"cell_type":"code","source":"test_loader = DataLoader(test_dataset, batch_size=16, \n                              num_workers=4, shuffle=False, pin_memory=True)\n","metadata":{"id":"w4taEkO_EoEg","execution":{"iopub.status.busy":"2023-05-24T04:57:46.756226Z","iopub.execute_input":"2023-05-24T04:57:46.756958Z","iopub.status.idle":"2023-05-24T04:57:46.76622Z","shell.execute_reply.started":"2023-05-24T04:57:46.756925Z","shell.execute_reply":"2023-05-24T04:57:46.765143Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def show_img(img, mask=None):\n    clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))\n    plt.imshow(img)\n    \n    if mask is not None:\n        plt.imshow(mask, alpha=0.9)\n\n    plt.axis('off')","metadata":{"execution":{"iopub.status.busy":"2023-05-24T04:57:46.768032Z","iopub.execute_input":"2023-05-24T04:57:46.768922Z","iopub.status.idle":"2023-05-24T04:57:46.777012Z","shell.execute_reply.started":"2023-05-24T04:57:46.76889Z","shell.execute_reply":"2023-05-24T04:57:46.776124Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_batch(imgs, msks, size=5):\n    plt.figure(figsize=(5*5, 5))\n    for idx in range(size):\n        plt.subplot(1, 5, idx+1)\n        img = imgs[idx,].permute((1, 2, 0)).numpy()\n        #img = img.astype('uint8')\n        msk = msks[idx,].permute((1, 2, 0)).numpy()\n        show_img(img, msk)\n    plt.tight_layout()\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2023-05-24T04:57:46.778765Z","iopub.execute_input":"2023-05-24T04:57:46.779625Z","iopub.status.idle":"2023-05-24T04:57:46.787153Z","shell.execute_reply.started":"2023-05-24T04:57:46.779593Z","shell.execute_reply":"2023-05-24T04:57:46.786483Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Utilities for Segmentation","metadata":{"id":"8xEbBzpU9Hil"}},{"cell_type":"code","source":"import segmentation_models_pytorch as smp\n\ndef build_model():\n    model = smp.Unet(\n        encoder_name=CFG.backbone,      # choose encoder, e.g. mobilenet_v2 or efficientnet-b7\n        encoder_weights=None,     # use `imagenet` pre-trained weights for encoder initialization\n        in_channels=3,                  # model input channels (1 for gray-scale images, 3 for RGB, etc.)\n        classes=CFG.num_classes,        # model output channels (number of classes in your dataset)\n        activation=None,\n    )\n    model.to(CFG.device)\n    return model\n\ndef load_model(path):\n    model = build_model()\n    model.load_state_dict(torch.load(path))\n    model.eval()\n    return model","metadata":{"execution":{"iopub.status.busy":"2023-05-24T04:57:46.78882Z","iopub.execute_input":"2023-05-24T04:57:46.789548Z","iopub.status.idle":"2023-05-24T04:57:46.797683Z","shell.execute_reply.started":"2023-05-24T04:57:46.789516Z","shell.execute_reply":"2023-05-24T04:57:46.796787Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# For colored terminal text\nfrom colorama import Fore, Back, Style\nc_  = Fore.GREEN\nsr_ = Style.RESET_ALL","metadata":{"execution":{"iopub.status.busy":"2023-05-24T04:57:46.803836Z","iopub.execute_input":"2023-05-24T04:57:46.804118Z","iopub.status.idle":"2023-05-24T04:57:46.808935Z","shell.execute_reply.started":"2023-05-24T04:57:46.80409Z","shell.execute_reply":"2023-05-24T04:57:46.807862Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = build_model()","metadata":{"execution":{"iopub.status.busy":"2023-05-24T04:57:46.810664Z","iopub.execute_input":"2023-05-24T04:57:46.811168Z","iopub.status.idle":"2023-05-24T04:57:46.953953Z","shell.execute_reply.started":"2023-05-24T04:57:46.81113Z","shell.execute_reply":"2023-05-24T04:57:46.953023Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fold =0\nfrom tqdm import tqdm\nimport time\nimport copy\nimport joblib\nfrom collections import defaultdict\nimport gc\nfrom IPython import display as ipd\n\npath='/kaggle/input/unetweights/best_epoch-00.bin'\n\nmodel = build_model()\nmodel = load_model(path)","metadata":{"execution":{"iopub.status.busy":"2023-05-24T04:57:46.955686Z","iopub.execute_input":"2023-05-24T04:57:46.956026Z","iopub.status.idle":"2023-05-24T04:57:47.289488Z","shell.execute_reply.started":"2023-05-24T04:57:46.955995Z","shell.execute_reply":"2023-05-24T04:57:47.288491Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def rle_encode(x, fg_val=1):\n    \"\"\"\n    Args:\n        x:  numpy array of shape (height, width), 1 - mask, 0 - background\n    Returns: run length encoding as list\n    \"\"\"\n\n    dots = np.where(\n        x.T.flatten() == fg_val)[0]  # .T sets Fortran order down-then-right\n    run_lengths = []\n    prev = -2\n    for b in dots:\n        if b > prev + 1:\n            run_lengths.extend((b + 1, 0))\n        run_lengths[-1] += 1\n        prev = b\n    return run_lengths\n\n\ndef list_to_string(x):\n    \"\"\"\n    Converts list to a string representation\n    Empty list returns '-'\n    \"\"\"\n    if x: # non-empty list\n        s = str(x).replace(\"[\", \"\").replace(\"]\", \"\").replace(\",\", \"\")\n    else:\n        s = '-'\n    return s\n\n\ndef rle_decode(mask_rle, shape=(256, 256)):\n    '''\n    mask_rle: run-length as string formatted (start length)\n              empty predictions need to be encoded with '-'\n    shape: (height, width) of array to return \n    Returns numpy array, 1 - mask, 0 - background\n    '''\n\n    img = np.zeros(shape[0]*shape[1], dtype=np.uint8)\n    if mask_rle != '-': \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        for lo, hi in zip(starts, ends):\n            img[lo:hi] = 1\n    return img.reshape(shape, order='F') ","metadata":{"execution":{"iopub.status.busy":"2023-05-24T04:57:47.292788Z","iopub.execute_input":"2023-05-24T04:57:47.293863Z","iopub.status.idle":"2023-05-24T04:57:47.304435Z","shell.execute_reply.started":"2023-05-24T04:57:47.293827Z","shell.execute_reply":"2023-05-24T04:57:47.303535Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def submit_to_csv(test_ids, y_pred):\n    \n    y_encoded = [list_to_string(rle_encode(y)) for y in y_pred]\n    \n    all_test_paths = list(Path('/kaggle/input/google-research-identify-contrails-reduce-global-warming/test').glob(\"*\"))\n    \n    sub_df = pd.DataFrame({'record_id': [path.stem for path in all_test_paths], 'encoded_pixels': y_encoded})\n    \n    print(\"Submitted\")\n    return sub_df","metadata":{"execution":{"iopub.status.busy":"2023-05-24T04:57:47.30713Z","iopub.execute_input":"2023-05-24T04:57:47.30752Z","iopub.status.idle":"2023-05-24T04:57:47.317801Z","shell.execute_reply.started":"2023-05-24T04:57:47.307489Z","shell.execute_reply":"2023-05-24T04:57:47.316902Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"imgs = next(iter(test_loader))\nimgs = imgs.to(CFG.device, dtype=torch.float)\n","metadata":{"execution":{"iopub.status.busy":"2023-05-24T04:57:47.319064Z","iopub.execute_input":"2023-05-24T04:57:47.319502Z","iopub.status.idle":"2023-05-24T04:57:47.567188Z","shell.execute_reply.started":"2023-05-24T04:57:47.31945Z","shell.execute_reply":"2023-05-24T04:57:47.565877Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"imgs.shape","metadata":{"execution":{"iopub.status.busy":"2023-05-24T04:57:47.570458Z","iopub.execute_input":"2023-05-24T04:57:47.571271Z","iopub.status.idle":"2023-05-24T04:57:47.578527Z","shell.execute_reply.started":"2023-05-24T04:57:47.571229Z","shell.execute_reply":"2023-05-24T04:57:47.577528Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from pathlib import Path\n\nout_rle = []\ntest_ids = []\npreds=[]\nmodel.eval()\nwith torch.inference_mode():\n    for idx, image in enumerate(tqdm(test_loader)):  \n        print(\"Test idx:\", idx)\n        image = image.to(CFG.device, dtype=torch.float)\n        \n        pred = model(image)\n        pred = (nn.Sigmoid()(pred)>0.5).double()\n    \n\n        out_reversed = np.array([o.cpu().permute(1,2,0).numpy() for o in pred])\n        for e in out_reversed:\n            out_rle.append(e)","metadata":{"execution":{"iopub.status.busy":"2023-05-24T04:57:47.580301Z","iopub.execute_input":"2023-05-24T04:57:47.581047Z","iopub.status.idle":"2023-05-24T04:57:47.875959Z","shell.execute_reply.started":"2023-05-24T04:57:47.581014Z","shell.execute_reply":"2023-05-24T04:57:47.874784Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Test:","metadata":{}},{"cell_type":"code","source":"import os\ntest_ids = list(os.listdir(\"/kaggle/input/google-research-identify-contrails-reduce-global-warming/test\"))","metadata":{"execution":{"iopub.status.busy":"2023-05-24T04:57:47.880165Z","iopub.execute_input":"2023-05-24T04:57:47.880863Z","iopub.status.idle":"2023-05-24T04:57:47.886665Z","shell.execute_reply.started":"2023-05-24T04:57:47.880823Z","shell.execute_reply":"2023-05-24T04:57:47.885706Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_df= submit_to_csv(test_ids, out_rle)","metadata":{"execution":{"iopub.status.busy":"2023-05-24T04:57:47.888283Z","iopub.execute_input":"2023-05-24T04:57:47.889017Z","iopub.status.idle":"2023-05-24T04:57:47.900604Z","shell.execute_reply.started":"2023-05-24T04:57:47.888981Z","shell.execute_reply":"2023-05-24T04:57:47.899555Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_df","metadata":{"execution":{"iopub.status.busy":"2023-05-24T04:57:48.074491Z","iopub.execute_input":"2023-05-24T04:57:48.074788Z","iopub.status.idle":"2023-05-24T04:57:48.085248Z","shell.execute_reply.started":"2023-05-24T04:57:48.074763Z","shell.execute_reply":"2023-05-24T04:57:48.084229Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"! rm -Rf /kaggle/working/*","metadata":{"execution":{"iopub.status.busy":"2023-05-24T04:57:48.298029Z","iopub.execute_input":"2023-05-24T04:57:48.299022Z","iopub.status.idle":"2023-05-24T04:57:49.281215Z","shell.execute_reply.started":"2023-05-24T04:57:48.298984Z","shell.execute_reply":"2023-05-24T04:57:49.279857Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_df.to_csv(\"submission.csv\",index=False)","metadata":{"execution":{"iopub.status.busy":"2023-05-24T04:57:49.283895Z","iopub.execute_input":"2023-05-24T04:57:49.284309Z","iopub.status.idle":"2023-05-24T04:57:49.29314Z","shell.execute_reply.started":"2023-05-24T04:57:49.28427Z","shell.execute_reply":"2023-05-24T04:57:49.292197Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls /kaggle/working","metadata":{"execution":{"iopub.status.busy":"2023-05-24T04:57:49.294815Z","iopub.execute_input":"2023-05-24T04:57:49.29557Z","iopub.status.idle":"2023-05-24T04:57:50.282751Z","shell.execute_reply.started":"2023-05-24T04:57:49.295537Z","shell.execute_reply":"2023-05-24T04:57:50.28154Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}