{"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\nfor 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":"2023-03-30T12:35:41.196171Z","iopub.execute_input":"2023-03-30T12:35:41.197160Z","iopub.status.idle":"2023-03-30T12:35:41.227795Z","shell.execute_reply.started":"2023-03-30T12:35:41.197128Z","shell.execute_reply":"2023-03-30T12:35:41.226656Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import glob\nimport zipfile\nfrom PIL import Image\n\nimport matplotlib.pyplot as plt\nfrom sklearn.model_selection import train_test_split\n\nimport torch\ntorch.manual_seed(42)\nimport torch.nn as nn\nimport torch.nn.functional as F\nfrom torchvision.io import read_image\nfrom torch.utils.data import Dataset, DataLoader\nfrom torchvision.transforms import ToTensor, CenterCrop","metadata":{"execution":{"iopub.status.busy":"2023-03-30T12:35:43.932276Z","iopub.execute_input":"2023-03-30T12:35:43.932978Z","iopub.status.idle":"2023-03-30T12:35:47.844724Z","shell.execute_reply.started":"2023-03-30T12:35:43.932927Z","shell.execute_reply":"2023-03-30T12:35:47.843670Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"input_dir = \"/kaggle/input/carvana-image-masking-challenge/\"","metadata":{"execution":{"iopub.status.busy":"2023-03-30T12:35:47.848622Z","iopub.execute_input":"2023-03-30T12:35:47.849616Z","iopub.status.idle":"2023-03-30T12:35:47.855240Z","shell.execute_reply.started":"2023-03-30T12:35:47.849585Z","shell.execute_reply":"2023-03-30T12:35:47.854264Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"with zipfile.ZipFile(input_dir+\"train.zip\", 'r') as zip_ref:\n    zip_ref.extractall(\".\")\n    \nwith zipfile.ZipFile(input_dir+\"train_masks.zip\", 'r') as zip_ref:\n    zip_ref.extractall(\".\")\n    \nwith zipfile.ZipFile(input_dir+\"sample_submission.csv.zip\", 'r') as zip_ref:\n    zip_ref.extractall(\".\")\n    \n# with zipfile.ZipFile(input_dir+\"test.zip\", 'r') as zip_ref:\n#     zip_ref.extractall(\".\")","metadata":{"execution":{"iopub.status.busy":"2023-03-30T12:35:47.856777Z","iopub.execute_input":"2023-03-30T12:35:47.857256Z","iopub.status.idle":"2023-03-30T12:35:57.233730Z","shell.execute_reply.started":"2023-03-30T12:35:47.857218Z","shell.execute_reply":"2023-03-30T12:35:57.232733Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_val_images = glob.glob(\"train/*\")\n\ntrain_val_images = sorted(train_val_images)\n\ntrain_val_images = [s.split(\"/\")[-1].split(\".\")[0] for s in train_val_images]\n\nlen(train_val_images)","metadata":{"execution":{"iopub.status.busy":"2023-03-30T12:36:03.281362Z","iopub.execute_input":"2023-03-30T12:36:03.281746Z","iopub.status.idle":"2023-03-30T12:36:03.308385Z","shell.execute_reply.started":"2023-03-30T12:36:03.281703Z","shell.execute_reply":"2023-03-30T12:36:03.307273Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_sub = pd.read_csv(\"sample_submission.csv\")\n\nsample_sub.head(2)","metadata":{"execution":{"iopub.status.busy":"2023-03-30T12:36:05.342282Z","iopub.execute_input":"2023-03-30T12:36:05.342635Z","iopub.status.idle":"2023-03-30T12:36:05.416530Z","shell.execute_reply.started":"2023-03-30T12:36:05.342603Z","shell.execute_reply":"2023-03-30T12:36:05.414604Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_images, val_images = train_test_split(train_val_images, test_size=0.1, random_state=42)\n\n# test_images = sample_sub.img.to_numpy()","metadata":{"execution":{"iopub.status.busy":"2023-03-30T12:36:08.697531Z","iopub.execute_input":"2023-03-30T12:36:08.698341Z","iopub.status.idle":"2023-03-30T12:36:08.711805Z","shell.execute_reply.started":"2023-03-30T12:36:08.698297Z","shell.execute_reply":"2023-03-30T12:36:08.710419Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_images[0], val_images[0]#, test_images[0]","metadata":{"execution":{"iopub.status.busy":"2023-03-30T12:36:08.898622Z","iopub.execute_input":"2023-03-30T12:36:08.899356Z","iopub.status.idle":"2023-03-30T12:36:08.906059Z","shell.execute_reply.started":"2023-03-30T12:36:08.899322Z","shell.execute_reply":"2023-03-30T12:36:08.904999Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(train_images), len(val_images)#, len(test_images)","metadata":{"execution":{"iopub.status.busy":"2023-03-30T12:36:09.262420Z","iopub.execute_input":"2023-03-30T12:36:09.263977Z","iopub.status.idle":"2023-03-30T12:36:09.272487Z","shell.execute_reply.started":"2023-03-30T12:36:09.263928Z","shell.execute_reply":"2023-03-30T12:36:09.271535Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_size = 576\n\nclass CustomImageDataset(Dataset):\n    def __init__(self, img_ids, transform=None):\n        self.img_ids = img_ids\n        self.transform = transform\n\n    def __len__(self):\n        return len(self.img_ids)\n\n    def __getitem__(self, idx):\n        img_id = self.img_ids[idx]\n        img_path = \"train/\" + img_id + \".jpg\"\n        mask_path = \"train_masks/\" + img_id + \"_mask.gif\"\n        image = Image.open(img_path)\n        image = image.resize((img_size, img_size))\n        mask = Image.open(mask_path).convert(\"L\")\n        mask = mask.resize((img_size, img_size))\n        if self.transform:\n            image = self.transform(image)\n            mask = self.transform(mask)\n        \n        return image, mask","metadata":{"execution":{"iopub.status.busy":"2023-03-30T12:36:09.773274Z","iopub.execute_input":"2023-03-30T12:36:09.775931Z","iopub.status.idle":"2023-03-30T12:36:10.069408Z","shell.execute_reply.started":"2023-03-30T12:36:09.775882Z","shell.execute_reply":"2023-03-30T12:36:10.068131Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_data = CustomImageDataset(train_images, ToTensor())\nval_data = CustomImageDataset(val_images, ToTensor())","metadata":{"execution":{"iopub.status.busy":"2023-03-30T12:36:10.600945Z","iopub.execute_input":"2023-03-30T12:36:10.601895Z","iopub.status.idle":"2023-03-30T12:36:10.607335Z","shell.execute_reply.started":"2023-03-30T12:36:10.601844Z","shell.execute_reply":"2023-03-30T12:36:10.605961Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for x, y in training_data:\n    print(x.shape)\n    print(y.shape)\n    break","metadata":{"execution":{"iopub.status.busy":"2023-03-30T12:36:11.009826Z","iopub.execute_input":"2023-03-30T12:36:11.010453Z","iopub.status.idle":"2023-03-30T12:36:11.163916Z","shell.execute_reply.started":"2023-03-30T12:36:11.010416Z","shell.execute_reply":"2023-03-30T12:36:11.162747Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_dataloader = DataLoader(training_data, batch_size=4, shuffle=True)\nval_dataloader = DataLoader(val_data, batch_size=4, shuffle=True)","metadata":{"execution":{"iopub.status.busy":"2023-03-30T12:36:12.850624Z","iopub.execute_input":"2023-03-30T12:36:12.851425Z","iopub.status.idle":"2023-03-30T12:36:12.858214Z","shell.execute_reply.started":"2023-03-30T12:36:12.851388Z","shell.execute_reply":"2023-03-30T12:36:12.857018Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"device = \"cuda\" if torch.cuda.is_available() else \"mps\" if torch.backends.mps.is_available() else \"cpu\"\nprint(f\"Using {device} device\")","metadata":{"execution":{"iopub.status.busy":"2023-03-30T12:36:13.259150Z","iopub.execute_input":"2023-03-30T12:36:13.259562Z","iopub.status.idle":"2023-03-30T12:36:13.340671Z","shell.execute_reply.started":"2023-03-30T12:36:13.259529Z","shell.execute_reply":"2023-03-30T12:36:13.339504Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class ConvBlock(nn.Module):\n    def __init__(self, in_channels: int, out_channels: int):\n        super(ConvBlock, self).__init__()\n        self.block = nn.Sequential(\n            nn.Conv2d(in_channels, out_channels, kernel_size=3, stride=1, padding=1),\n            nn.BatchNorm2d(out_channels),\n            nn.ReLU(inplace=True),\n            \n            nn.Conv2d(out_channels, out_channels, kernel_size=3, stride=1, padding=1),\n            nn.BatchNorm2d(out_channels),\n            nn.ReLU(inplace=True)\n        )\n        \n    def forward(self, x: torch.Tensor):\n        return self.block(x)\n    \nclass CopyAndCrop(nn.Module):\n    def forward(self, x: torch.Tensor, encoded: torch.Tensor):\n        _, _, h, w = encoded.shape\n        crop = CenterCrop((h, w))(x)\n        output = torch.cat((x, crop), 1)\n        \n        return output\n\n    \nclass UNet(nn.Module):\n    def __init__(self, in_channels: int, out_channels: int):\n        super(UNet, self).__init__()\n\n        self.encoders = nn.ModuleList([\n            ConvBlock(in_channels, 64),\n            ConvBlock(64, 128),\n            ConvBlock(128, 256),\n            ConvBlock(256, 512),\n        ])\n        self.down_sample = nn.MaxPool2d(2)\n        self.copyAndCrop = CopyAndCrop()\n        self.decoders = nn.ModuleList([\n            ConvBlock(1024, 512),\n            ConvBlock(512, 256),\n            ConvBlock(256, 128),\n            ConvBlock(128, 64),\n        ])\n\n\n        self.up_samples = nn.ModuleList([\n            nn.ConvTranspose2d(1024, 512, kernel_size=2, stride=2),\n            nn.ConvTranspose2d(512, 256, kernel_size=2, stride=2),\n            nn.ConvTranspose2d(256, 128, kernel_size=2, stride=2),\n            nn.ConvTranspose2d(128, 64, kernel_size=2, stride=2)\n        ])\n\n\n        self.bottleneck = ConvBlock(512, 1024)\n        self.final_conv = nn.Conv2d(64, out_channels, kernel_size=1, stride=1)\n        \n    def forward(self, x: torch.Tensor):\n        # encode\n        encoded_features = []\n        for enc in self.encoders:\n            x = enc(x)\n            encoded_features.append(x)\n            x = self.down_sample(x)\n            \n        \n        x = self.bottleneck(x)\n        \n        # decode\n        for idx, denc in enumerate(self.decoders):\n            x = self.up_samples[idx](x)\n            encoded = encoded_features.pop()\n            x = self.copyAndCrop(x, encoded)\n            x = denc(x)\n            \n        output = self.final_conv(x)\n        return output\n    \nmodel = UNet(in_channels=3, out_channels=1).to(device)\nprint(model)","metadata":{"execution":{"iopub.status.busy":"2023-03-30T12:36:15.957845Z","iopub.execute_input":"2023-03-30T12:36:15.958583Z","iopub.status.idle":"2023-03-30T12:36:19.083849Z","shell.execute_reply.started":"2023-03-30T12:36:15.958544Z","shell.execute_reply":"2023-03-30T12:36:19.082705Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# class UNet(nn.Module):\n#     def __init__(self):\n#         super().__init__()\n#         self.conv1 = nn.Conv2d(in_channels=3, out_channels=64, kernel_size=3, padding=1)\n#         self.conv2 = nn.Conv2d(in_channels=64, out_channels=64, kernel_size=3, padding=1)\n        \n#         self.conv3 = nn.Conv2d(in_channels=64, out_channels=128, kernel_size=3, padding=1)\n#         self.conv4 = nn.Conv2d(in_channels=128, out_channels=128, kernel_size=3, padding=1)\n        \n#         self.conv5 = nn.Conv2d(in_channels=128, out_channels=256, kernel_size=3, padding=1)\n#         self.conv6 = nn.Conv2d(in_channels=256, out_channels=256, kernel_size=3, padding=1)\n        \n#         self.conv7 = nn.Conv2d(in_channels=256, out_channels=512, kernel_size=3, padding=1)\n#         self.conv8 = nn.Conv2d(in_channels=512, out_channels=512, kernel_size=3, padding=1)\n        \n#         self.conv9 = nn.Conv2d(in_channels=512, out_channels=1024, kernel_size=3, padding=1)\n#         self.conv10 = nn.Conv2d(in_channels=1024, out_channels=1024, kernel_size=3, padding=1)\n        \n#         self.upconv1 = nn.ConvTranspose2d(in_channels=1024, out_channels=512, kernel_size=2, stride=2)\n        \n#         self.conv11 = nn.Conv2d(in_channels=1024, out_channels=512, kernel_size=3, padding=1)\n#         self.conv12 = nn.Conv2d(in_channels=512, out_channels=512, kernel_size=3, padding=1)\n        \n#         self.upconv2 = nn.ConvTranspose2d(in_channels=512, out_channels=256, kernel_size=2, stride=2)\n        \n#         self.conv13 = nn.Conv2d(in_channels=512, out_channels=256, kernel_size=3, padding=1)\n#         self.conv14 = nn.Conv2d(in_channels=256, out_channels=256, kernel_size=3, padding=1)\n        \n#         self.upconv3 = nn.ConvTranspose2d(in_channels=256, out_channels=128, kernel_size=2, stride=2)\n        \n#         self.conv15 = nn.Conv2d(in_channels=256, out_channels=128, kernel_size=3, padding=1)\n#         self.conv16 = nn.Conv2d(in_channels=128, out_channels=128, kernel_size=3, padding=1)\n        \n#         self.upconv4 = nn.ConvTranspose2d(in_channels=128, out_channels=64, kernel_size=2, stride=2)\n        \n#         self.conv17 = nn.Conv2d(in_channels=128, out_channels=64, kernel_size=3, padding=1)\n#         self.conv18 = nn.Conv2d(in_channels=64, out_channels=64, kernel_size=3, padding=1)\n        \n#         self.finalconv = nn.Conv2d(in_channels=64, out_channels=1, kernel_size=1)\n\n#         self.pool = nn.MaxPool2d(kernel_size=2, stride=2)\n\n\n#     def forward(self, x):\n#         x = F.relu(self.conv1(x))\n#         x = F.relu(self.conv2(x))\n        \n#         crop1 = CenterCrop((img_size, img_size))(x)\n        \n#         x = F.relu(self.pool(x))\n        \n#         x = F.relu(self.conv3(x))\n#         x = F.relu(self.conv4(x))\n\n#         crop2 = CenterCrop((img_size//2, img_size//2))(x)\n        \n#         x = F.relu(self.pool(x))\n        \n#         x = F.relu(self.conv5(x))\n#         x = F.relu(self.conv6(x))\n        \n#         crop3 = CenterCrop((img_size//4, img_size//4))(x)\n                \n#         x = F.relu(self.pool(x))\n        \n#         x = F.relu(self.conv7(x))\n#         x = F.relu(self.conv8(x))\n#         crop4 = CenterCrop((img_size//8, img_size//8))(x)\n        \n#         x = F.relu(self.pool(x))\n        \n#         x = F.relu(self.conv9(x))\n#         x = F.relu(self.conv10(x))\n        \n#         x = F.relu(torch.cat((self.upconv1(x), crop4), 1))\n        \n        \n#         x = F.relu(self.conv11(x))\n#         x = F.relu(self.conv12(x))\n        \n#         x = F.relu(torch.cat((self.upconv2(x), crop3), 1))\n\n#         x = F.relu(self.conv13(x))\n#         x = F.relu(self.conv14(x))\n        \n#         x = F.relu(torch.cat((self.upconv3(x), crop2), 1))\n\n#         x = F.relu(self.conv15(x))\n#         x = F.relu(self.conv16(x))\n\n#         x = F.relu(torch.cat((self.upconv4(x), crop1), 1))\n\n#         x = F.relu(self.conv17(x))\n#         x = F.relu(self.conv18(x))\n\n#         x = self.finalconv(x)\n\n#         return x\n\n        \n# model = UNet().to(device)\n# print(model)","metadata":{"execution":{"iopub.status.busy":"2023-03-30T12:36:22.511857Z","iopub.execute_input":"2023-03-30T12:36:22.512216Z","iopub.status.idle":"2023-03-30T12:36:22.519282Z","shell.execute_reply.started":"2023-03-30T12:36:22.512185Z","shell.execute_reply":"2023-03-30T12:36:22.518260Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"loss_fn = nn.BCEWithLogitsLoss()\noptimizer = torch.optim.Adam(model.parameters(), lr=0.0002)","metadata":{"execution":{"iopub.status.busy":"2023-03-30T12:36:23.528359Z","iopub.execute_input":"2023-03-30T12:36:23.528732Z","iopub.status.idle":"2023-03-30T12:36:23.534501Z","shell.execute_reply.started":"2023-03-30T12:36:23.528689Z","shell.execute_reply":"2023-03-30T12:36:23.533248Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def train(dataloader, model, loss_fn, optimizer):\n    size = len(dataloader.dataset)\n    model.train()\n    for batch, (X, y) in enumerate(dataloader):\n        X, y = X.to(device), y.to(device)\n\n        pred = model(X)\n        loss = loss_fn(pred, y)\n\n        # Backpropagation\n        optimizer.zero_grad()\n        loss.backward()\n        optimizer.step()\n\n        if batch % 100 == 0:\n            loss, current = loss.item(), (batch + 1) * len(X)\n            print(f\"loss: {loss:>7f}  [{current:>5d}/{size:>5d}]\")","metadata":{"execution":{"iopub.status.busy":"2023-03-30T13:00:11.353809Z","iopub.execute_input":"2023-03-30T13:00:11.354173Z","iopub.status.idle":"2023-03-30T13:00:11.361196Z","shell.execute_reply.started":"2023-03-30T13:00:11.354141Z","shell.execute_reply":"2023-03-30T13:00:11.360151Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"epochs = 2\nfor t in range(epochs):\n    print(f\"Epoch {t+1}\\n-------------------------------\")\n    train(train_dataloader, model, loss_fn, optimizer)\nprint(\"Done!\")","metadata":{"execution":{"iopub.status.busy":"2023-03-30T13:17:18.508549Z","iopub.execute_input":"2023-03-30T13:17:18.509653Z","iopub.status.idle":"2023-03-30T13:31:44.747702Z","shell.execute_reply.started":"2023-03-30T13:17:18.509615Z","shell.execute_reply":"2023-03-30T13:31:44.746478Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_images(images, mask = False):\n    fig = plt.figure(figsize=(10, 8))\n    columns = len(images)\n    rows = 1\n    for i in range(columns*rows):\n        img = images[i]\n        fig.add_subplot(rows, columns, i+1)\n        if mask:\n            img = img > 0.5\n        plt.imshow(img, cmap=\"gray\")\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2023-03-30T13:33:09.626863Z","iopub.execute_input":"2023-03-30T13:33:09.627234Z","iopub.status.idle":"2023-03-30T13:33:09.633963Z","shell.execute_reply.started":"2023-03-30T13:33:09.627201Z","shell.execute_reply":"2023-03-30T13:33:09.632961Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def visualize_result(dataloader):\n    tr_imgs = []\n    msk_imgs = []\n    \n    for x, y in dataloader:\n        x = x.to(device)\n        \n        pred = model(x)\n        \n        for i in range(x.shape[0]):\n            tr_img = x[i].cpu().detach().numpy()\n            tr_img = np.einsum('kij->ijk',tr_img)\n            tr_imgs.append(tr_img)\n            \n            msk_img = pred[i].cpu().detach().numpy()\n            msk_img = msk_img.reshape((img_size, img_size))\n            msk_imgs.append(msk_img)\n\n        break\n        \n    plot_images(tr_imgs, mask=False)\n    plot_images(msk_imgs, mask=True)\n    \nvisualize_result(val_dataloader)","metadata":{"execution":{"iopub.status.busy":"2023-03-30T12:59:38.445279Z","iopub.execute_input":"2023-03-30T12:59:38.445635Z","iopub.status.idle":"2023-03-30T12:59:40.061849Z","shell.execute_reply.started":"2023-03-30T12:59:38.445603Z","shell.execute_reply":"2023-03-30T12:59:40.060900Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"torch.save(model.state_dict(), \"model.pth\")","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# def rle(img):\n#     flat_img = img.flatten()\n#     flat_img = np.where(flat_img > 0.5, 1, 0).astype(np.uint8)\n#     flat_img = np.insert(flat_img, [0, len(flat_img)], [0, 0])\n\n#     starts = np.array((flat_img[:-1] == 0) & (flat_img[1:] == 1))\n#     ends = np.array((flat_img[:-1] == 1) & (flat_img[1:] == 0))\n#     starts_ix = np.where(starts)[0] + 1\n#     ends_ix = np.where(ends)[0] + 1\n#     lengths = ends_ix - starts_ix\n\n#     encoding = ''\n#     for idx in range(len(starts_ix)):\n#         encoding += '%d %d ' % (starts_ix[idx], lengths[idx])\n#     return encoding.strip()","metadata":{"execution":{"iopub.status.busy":"2023-03-30T06:11:14.095463Z","iopub.execute_input":"2023-03-30T06:11:14.095910Z","iopub.status.idle":"2023-03-30T06:11:14.101879Z","shell.execute_reply.started":"2023-03-30T06:11:14.095867Z","shell.execute_reply":"2023-03-30T06:11:14.100837Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# test_rle = np.zeros((test_images.shape[0]), dtype=object)\n\n# for i in range(test_images.shape[0]):\n#     img = np.array(Image.open(\"/kaggle/working/test/\" + test_images[i]))\n#     test_rle[i] = rle(img)\n    \n#     if i % 1000 == 0:\n#         print(i)","metadata":{"execution":{"iopub.status.busy":"2023-03-30T06:11:15.945630Z","iopub.execute_input":"2023-03-30T06:11:15.945991Z","iopub.status.idle":"2023-03-30T06:11:15.950943Z","shell.execute_reply.started":"2023-03-30T06:11:15.945959Z","shell.execute_reply":"2023-03-30T06:11:15.949854Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# df_ans = pd.DataFrame({\"img\": test_images, \"rle_mask\": test_rle})\n\n# df_ans","metadata":{"execution":{"iopub.status.busy":"2023-03-30T06:11:53.296765Z","iopub.execute_input":"2023-03-30T06:11:53.298736Z","iopub.status.idle":"2023-03-30T06:11:53.305972Z","shell.execute_reply.started":"2023-03-30T06:11:53.298689Z","shell.execute_reply":"2023-03-30T06:11:53.304845Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# df_ans.to_csv(\"ans1.csv\", index=False)","metadata":{"execution":{"iopub.status.busy":"2023-03-30T06:12:00.666841Z","iopub.execute_input":"2023-03-30T06:12:00.667528Z","iopub.status.idle":"2023-03-30T06:12:00.672174Z","shell.execute_reply.started":"2023-03-30T06:12:00.667489Z","shell.execute_reply":"2023-03-30T06:12:00.670980Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}