{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":6927,"databundleVersionId":45059,"sourceType":"competition"}],"dockerImageVersionId":30733,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import copy\nimport os\nimport random\nimport shutil\nimport zipfile\nfrom math import atan2, cos, sin, sqrt, pi, log\n\nimport cv2\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nimport torchvision.transforms as transforms\nfrom PIL import Image\nfrom numpy import linalg as LA\nfrom torch import optim, nn\nfrom torch.utils.data import DataLoader, random_split\nfrom torch.utils.data.dataset import Dataset\nfrom torchvision import transforms\nfrom tqdm import tqdm\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-06-15T14:49:30.435537Z","iopub.execute_input":"2024-06-15T14:49:30.435904Z","iopub.status.idle":"2024-06-15T14:49:35.736823Z","shell.execute_reply.started":"2024-06-15T14:49:30.435874Z","shell.execute_reply":"2024-06-15T14:49:35.736022Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class DoubleConv(nn.Module):\n    def __init__(self, in_channels, out_channels):\n        super().__init__()\n        self.conv_op = nn.Sequential(\n            nn.Conv2d(in_channels, out_channels, kernel_size=3, padding=1),\n            nn.ReLU(inplace=True),\n            nn.Conv2d(out_channels, out_channels, kernel_size=3, padding=1),\n            nn.ReLU(inplace=True)\n        )\n\n    def forward(self, x):\n        return self.conv_op(x)","metadata":{"execution":{"iopub.status.busy":"2024-06-15T14:49:35.738742Z","iopub.execute_input":"2024-06-15T14:49:35.740302Z","iopub.status.idle":"2024-06-15T14:49:35.746396Z","shell.execute_reply.started":"2024-06-15T14:49:35.740269Z","shell.execute_reply":"2024-06-15T14:49:35.745444Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class DownSample(nn.Module):\n    def __init__(self, in_channels, out_channels):\n        super().__init__()\n        self.conv = DoubleConv(in_channels, out_channels)\n        self.pool = nn.MaxPool2d(kernel_size=2, stride=2)\n\n    def forward(self, x):\n        down = self.conv(x)\n        p = self.pool(down)\n\n        return down, p\n","metadata":{"execution":{"iopub.status.busy":"2024-06-15T14:49:35.747445Z","iopub.execute_input":"2024-06-15T14:49:35.747731Z","iopub.status.idle":"2024-06-15T14:49:35.762283Z","shell.execute_reply.started":"2024-06-15T14:49:35.747685Z","shell.execute_reply":"2024-06-15T14:49:35.761414Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class UpSample(nn.Module):\n    def __init__(self, in_channels, out_channels):\n        super().__init__()\n        self.up = nn.ConvTranspose2d(in_channels, in_channels//2, kernel_size=2, stride=2)\n        self.conv = DoubleConv(in_channels, out_channels)\n\n    def forward(self, x1, x2):\n        x1 = self.up(x1)\n        x = torch.cat([x1, x2], 1)\n        return self.conv(x)\n","metadata":{"execution":{"iopub.status.busy":"2024-06-15T14:49:35.763225Z","iopub.execute_input":"2024-06-15T14:49:35.763458Z","iopub.status.idle":"2024-06-15T14:49:35.772316Z","shell.execute_reply.started":"2024-06-15T14:49:35.763437Z","shell.execute_reply":"2024-06-15T14:49:35.771562Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class UNet(nn.Module):\n    def __init__(self, in_channels, num_classes):\n        super().__init__()\n        self.down_convolution_1 = DownSample(in_channels, 64)\n        self.down_convolution_2 = DownSample(64, 128)\n        self.down_convolution_3 = DownSample(128, 256)\n        self.down_convolution_4 = DownSample(256, 512)\n\n        self.bottle_neck = DoubleConv(512, 1024)\n\n        self.up_convolution_1 = UpSample(1024, 512)\n        self.up_convolution_2 = UpSample(512, 256)\n        self.up_convolution_3 = UpSample(256, 128)\n        self.up_convolution_4 = UpSample(128, 64)\n\n        self.out = nn.Conv2d(in_channels=64, out_channels=num_classes, kernel_size=1)\n\n    def forward(self, x):\n        down_1, p1 = self.down_convolution_1(x)\n        down_2, p2 = self.down_convolution_2(p1)\n        down_3, p3 = self.down_convolution_3(p2)\n        down_4, p4 = self.down_convolution_4(p3)\n\n        b = self.bottle_neck(p4)\n\n        up_1 = self.up_convolution_1(b, down_4)\n        up_2 = self.up_convolution_2(up_1, down_3)\n        up_3 = self.up_convolution_3(up_2, down_2)\n        up_4 = self.up_convolution_4(up_3, down_1)\n\n        out = self.out(up_4)\n        return out\n","metadata":{"execution":{"iopub.status.busy":"2024-06-15T14:49:35.775326Z","iopub.execute_input":"2024-06-15T14:49:35.775831Z","iopub.status.idle":"2024-06-15T14:49:35.785680Z","shell.execute_reply.started":"2024-06-15T14:49:35.775798Z","shell.execute_reply":"2024-06-15T14:49:35.784755Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"input_image = torch.rand((1,3,512,512))\nmodel = UNet(3,10)\noutput = model(input_image)\nprint(output.size())","metadata":{"execution":{"iopub.status.busy":"2024-06-15T14:49:35.786738Z","iopub.execute_input":"2024-06-15T14:49:35.787084Z","iopub.status.idle":"2024-06-15T14:49:38.857512Z","shell.execute_reply.started":"2024-06-15T14:49:35.787061Z","shell.execute_reply":"2024-06-15T14:49:38.856487Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class CarvanaDataset(Dataset):\n    def __init__(self, root_path, limit=None):\n        self.root_path = root_path\n        self.limit = limit\n        self.images = sorted([root_path + \"/train/\" + i for i in os.listdir(root_path + \"/train/\")])[:self.limit]\n        self.masks = sorted([root_path + \"/train_masks/\" + i for i in os.listdir(root_path + \"/train_masks/\")])[:self.limit]\n\n        self.transform = transforms.Compose([\n            transforms.Resize((512, 512)),\n            transforms.ToTensor()])\n        \n        if self.limit is None:\n            self.limit = len(self.images)\n\n    def __getitem__(self, index):\n        img = Image.open(self.images[index]).convert(\"RGB\")\n        mask = Image.open(self.masks[index]).convert(\"L\")\n\n        return self.transform(img), self.transform(mask)\n\n    def __len__(self):\n        return min(len(self.images), self.limit)","metadata":{"execution":{"iopub.status.busy":"2024-06-15T14:49:38.858755Z","iopub.execute_input":"2024-06-15T14:49:38.859051Z","iopub.status.idle":"2024-06-15T14:49:38.868235Z","shell.execute_reply.started":"2024-06-15T14:49:38.859025Z","shell.execute_reply":"2024-06-15T14:49:38.866946Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(os.listdir(\"../input/carvana-image-masking-challenge/\"))\n\nDATASET_DIR = '../input/carvana-image-masking-challenge/'\nWORKING_DIR = '/kaggle/working/'\n","metadata":{"execution":{"iopub.status.busy":"2024-06-15T14:49:38.869340Z","iopub.execute_input":"2024-06-15T14:49:38.869604Z","iopub.status.idle":"2024-06-15T14:49:38.884426Z","shell.execute_reply.started":"2024-06-15T14:49:38.869581Z","shell.execute_reply":"2024-06-15T14:49:38.883575Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"if len(os.listdir(WORKING_DIR)) <= 1:\n\n    with zipfile.ZipFile(DATASET_DIR + 'train.zip', 'r') as zip_file:\n        zip_file.extractall(WORKING_DIR)\n\n    with zipfile.ZipFile(DATASET_DIR + 'train_masks.zip', 'r') as zip_file:\n        zip_file.extractall(WORKING_DIR)\n    \n    print(\n        len(os.listdir(WORKING_DIR + 'train')),\n        len(os.listdir(WORKING_DIR + 'train_masks'))\n    )","metadata":{"execution":{"iopub.status.busy":"2024-06-15T14:49:38.885519Z","iopub.execute_input":"2024-06-15T14:49:38.885843Z","iopub.status.idle":"2024-06-15T14:49:47.673860Z","shell.execute_reply.started":"2024-06-15T14:49:38.885818Z","shell.execute_reply":"2024-06-15T14:49:47.672773Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_dataset = CarvanaDataset(WORKING_DIR)\n\ngenerator = torch.Generator().manual_seed(25)\n","metadata":{"execution":{"iopub.status.busy":"2024-06-15T14:49:47.675240Z","iopub.execute_input":"2024-06-15T14:49:47.675934Z","iopub.status.idle":"2024-06-15T14:49:47.691609Z","shell.execute_reply.started":"2024-06-15T14:49:47.675897Z","shell.execute_reply":"2024-06-15T14:49:47.690740Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_dataset, test_dataset = random_split(train_dataset, [0.8, 0.2], generator=generator)","metadata":{"execution":{"iopub.status.busy":"2024-06-15T14:49:47.692788Z","iopub.execute_input":"2024-06-15T14:49:47.693025Z","iopub.status.idle":"2024-06-15T14:49:47.698687Z","shell.execute_reply.started":"2024-06-15T14:49:47.693004Z","shell.execute_reply":"2024-06-15T14:49:47.697977Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_dataset, val_dataset = random_split(test_dataset, [0.5, 0.5], generator=generator)","metadata":{"execution":{"iopub.status.busy":"2024-06-15T14:49:47.699633Z","iopub.execute_input":"2024-06-15T14:49:47.699894Z","iopub.status.idle":"2024-06-15T14:49:47.706633Z","shell.execute_reply.started":"2024-06-15T14:49:47.699872Z","shell.execute_reply":"2024-06-15T14:49:47.705719Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"device = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n\nif device == \"cuda\":\n    num_workers = torch.cuda.device_count() * 4\n    ","metadata":{"execution":{"iopub.status.busy":"2024-06-15T14:49:47.707776Z","iopub.execute_input":"2024-06-15T14:49:47.708136Z","iopub.status.idle":"2024-06-15T14:49:47.760988Z","shell.execute_reply.started":"2024-06-15T14:49:47.708103Z","shell.execute_reply":"2024-06-15T14:49:47.760125Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"LEARNING_RATE = 3e-4\nBATCH_SIZE = 8\n\ntrain_dataloader = DataLoader(dataset=train_dataset,\n                              num_workers=num_workers, pin_memory=False,\n                              batch_size=BATCH_SIZE,\n                              shuffle=True)\nval_dataloader = DataLoader(dataset=val_dataset,\n                            num_workers=num_workers, pin_memory=False,\n                            batch_size=BATCH_SIZE,\n                            shuffle=True)\n\ntest_dataloader = DataLoader(dataset=test_dataset,\n                            num_workers=num_workers, pin_memory=False,\n                            batch_size=BATCH_SIZE,\n                            shuffle=True)\n\nmodel = UNet(in_channels=3, num_classes=1).to(device)\noptimizer = optim.AdamW(model.parameters(), lr=LEARNING_RATE)\ncriterion = nn.BCEWithLogitsLoss()\n","metadata":{"execution":{"iopub.status.busy":"2024-06-15T14:49:47.763639Z","iopub.execute_input":"2024-06-15T14:49:47.763935Z","iopub.status.idle":"2024-06-15T14:49:48.217731Z","shell.execute_reply.started":"2024-06-15T14:49:47.763909Z","shell.execute_reply":"2024-06-15T14:49:48.216756Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def dice_coefficient(prediction, target, epsilon=1e-07):\n    prediction_copy = prediction.clone()\n\n    prediction_copy[prediction_copy < 0] = 0\n    prediction_copy[prediction_copy > 0] = 1\n\n    intersection = abs(torch.sum(prediction_copy * target))\n    union = abs(torch.sum(prediction_copy) + torch.sum(target))\n    dice = (2. * intersection + epsilon) / (union + epsilon)\n    \n    return dice","metadata":{"execution":{"iopub.status.busy":"2024-06-15T14:51:28.356061Z","iopub.execute_input":"2024-06-15T14:51:28.356449Z","iopub.status.idle":"2024-06-15T14:51:28.363170Z","shell.execute_reply.started":"2024-06-15T14:51:28.356418Z","shell.execute_reply":"2024-06-15T14:51:28.361967Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"torch.cuda.empty_cache()","metadata":{"execution":{"iopub.status.busy":"2024-06-15T14:51:47.523991Z","iopub.execute_input":"2024-06-15T14:51:47.524675Z","iopub.status.idle":"2024-06-15T14:51:47.528574Z","shell.execute_reply.started":"2024-06-15T14:51:47.524643Z","shell.execute_reply":"2024-06-15T14:51:47.527684Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"EPOCHS = 10\n\ntrain_losses = []\ntrain_dcs = []\nval_losses = []\nval_dcs = []\n\nfor epoch in tqdm(range(EPOCHS)):\n    model.train()\n    train_running_loss = 0\n    train_running_dc = 0\n    \n    for idx, img_mask in enumerate(tqdm(train_dataloader, position=0, leave=True)):\n        img = img_mask[0].float().to(device)\n        mask = img_mask[1].float().to(device)\n        \n        y_pred = model(img)\n        optimizer.zero_grad()\n        \n        dc = dice_coefficient(y_pred, mask)\n        loss = criterion(y_pred, mask)\n        \n        train_running_loss += loss.item()\n        train_running_dc += dc.item()\n\n        loss.backward()\n        optimizer.step()\n\n    train_loss = train_running_loss / (idx + 1)\n    train_dc = train_running_dc / (idx + 1)\n    \n    train_losses.append(train_loss)\n    train_dcs.append(train_dc)\n\n    model.eval()\n    val_running_loss = 0\n    val_running_dc = 0\n    \n    with torch.no_grad():\n        for idx, img_mask in enumerate(tqdm(val_dataloader, position=0, leave=True)):\n            img = img_mask[0].float().to(device)\n            mask = img_mask[1].float().to(device)\n\n            y_pred = model(img)\n            loss = criterion(y_pred, mask)\n            dc = dice_coefficient(y_pred, mask)\n            \n            val_running_loss += loss.item()\n            val_running_dc += dc.item()\n\n        val_loss = val_running_loss / (idx + 1)\n        val_dc = val_running_dc / (idx + 1)\n    \n    val_losses.append(val_loss)\n    val_dcs.append(val_dc)\n\n    print(\"-\" * 30)\n    print(f\"Training Loss EPOCH {epoch + 1}: {train_loss:.4f}\")\n    print(f\"Training DICE EPOCH {epoch + 1}: {train_dc:.4f}\")\n    print(\"\\n\")\n    print(f\"Validation Loss EPOCH {epoch + 1}: {val_loss:.4f}\")\n    print(f\"Validation DICE EPOCH {epoch + 1}: {val_dc:.4f}\")\n    print(\"-\" * 30)\n\n# Saving the model\ntorch.save(model.state_dict(), 'my_checkpoint.pth')\n","metadata":{"execution":{"iopub.status.busy":"2024-06-15T14:52:09.022581Z","iopub.execute_input":"2024-06-15T14:52:09.023484Z","iopub.status.idle":"2024-06-15T16:00:56.322394Z","shell.execute_reply.started":"2024-06-15T14:52:09.023449Z","shell.execute_reply":"2024-06-15T16:00:56.321280Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"epochs_list = list(range(1, EPOCHS + 1))\n\nplt.figure(figsize=(12, 5))\nplt.subplot(1, 2, 1)\nplt.plot(epochs_list, train_losses, label='Training Loss')\nplt.plot(epochs_list, val_losses, label='Validation Loss')\nplt.xticks(ticks=list(range(1, EPOCHS + 1, 1))) \nplt.title('Loss over epochs')\nplt.xlabel('Epochs')\nplt.ylabel('Loss')\nplt.grid()\nplt.tight_layout()\n\nplt.legend()\n\n\nplt.subplot(1, 2, 2)\nplt.plot(epochs_list, train_dcs, label='Training DICE')\nplt.plot(epochs_list, val_dcs, label='Validation DICE')\nplt.xticks(ticks=list(range(1, EPOCHS + 1, 1)))  \nplt.title('DICE Coefficient over epochs')\nplt.xlabel('Epochs')\nplt.ylabel('DICE')\nplt.grid()\nplt.legend()\n\nplt.tight_layout()\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2024-06-15T16:05:29.538142Z","iopub.execute_input":"2024-06-15T16:05:29.538511Z","iopub.status.idle":"2024-06-15T16:05:30.234118Z","shell.execute_reply.started":"2024-06-15T16:05:29.538469Z","shell.execute_reply":"2024-06-15T16:05:30.233224Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"epochs_list = list(range(1, EPOCHS + 1))\n\nplt.figure(figsize=(12, 5))\nplt.plot(epochs_list, train_losses, label='Training Loss')\nplt.plot(epochs_list, val_losses, label='Validation Loss')\nplt.xticks(ticks=list(range(1, EPOCHS + 1, 1))) \nplt.ylim(0, 0.05)\nplt.title('Loss over epochs (zoomed)')\nplt.xlabel('Epochs')\nplt.ylabel('Loss')\nplt.grid()\nplt.tight_layout()\n\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-06-15T16:05:35.790008Z","iopub.execute_input":"2024-06-15T16:05:35.790361Z","iopub.status.idle":"2024-06-15T16:05:36.157311Z","shell.execute_reply.started":"2024-06-15T16:05:35.790332Z","shell.execute_reply":"2024-06-15T16:05:36.156406Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_pth = '/kaggle/working/my_checkpoint.pth'\ntrained_model = UNet(in_channels=3, num_classes=1).to(device)\ntrained_model.load_state_dict(torch.load(model_pth, map_location=torch.device(device)))\n","metadata":{"execution":{"iopub.status.busy":"2024-06-15T16:05:40.344315Z","iopub.execute_input":"2024-06-15T16:05:40.344917Z","iopub.status.idle":"2024-06-15T16:05:40.794733Z","shell.execute_reply.started":"2024-06-15T16:05:40.344881Z","shell.execute_reply":"2024-06-15T16:05:40.793856Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_running_loss = 0\ntest_running_dc = 0\n\nwith torch.no_grad():\n    for idx, img_mask in enumerate(tqdm(test_dataloader, position=0, leave=True)):\n        img = img_mask[0].float().to(device)\n        mask = img_mask[1].float().to(device)\n\n        y_pred = trained_model(img)\n        loss = criterion(y_pred, mask)\n        dc = dice_coefficient(y_pred, mask)\n\n        test_running_loss += loss.item()\n        test_running_dc += dc.item()\n\n    test_loss = test_running_loss / (idx + 1)\n    test_dc = test_running_dc / (idx + 1)\n","metadata":{"execution":{"iopub.status.busy":"2024-06-15T16:06:04.674362Z","iopub.execute_input":"2024-06-15T16:06:04.675003Z","iopub.status.idle":"2024-06-15T16:06:24.239895Z","shell.execute_reply.started":"2024-06-15T16:06:04.674960Z","shell.execute_reply":"2024-06-15T16:06:24.238635Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def random_images_inference(image_tensors, mask_tensors, image_paths, model_pth, device):\n    model = UNet(in_channels=3, num_classes=1).to(device)\n    model.load_state_dict(torch.load(model_pth, map_location=torch.device(device)))\n\n    transform = transforms.Compose([\n        transforms.Resize((512, 512))\n    ])\n\n    # Iterate for the images, masks and paths\n    for image_pth, mask_pth, image_paths in zip(image_tensors, mask_tensors, image_paths):\n        # Load the image\n        img = transform(image_pth)\n        \n        # Predict the imagen with the model\n        pred_mask = model(img.unsqueeze(0))\n        pred_mask = pred_mask.squeeze(0).permute(1,2,0)\n        \n        # Load the mask to compare\n        mask = transform(mask_pth).permute(1, 2, 0).to(device)\n        \n        print(f\"Image: {os.path.basename(image_paths)}, DICE coefficient: {round(float(dice_coefficient(pred_mask, mask)),5)}\")\n        \n        # Show the images\n        img = img.cpu().detach().permute(1, 2, 0)\n        pred_mask = pred_mask.cpu().detach()\n        pred_mask[pred_mask < 0] = 0\n        pred_mask[pred_mask > 0] = 1\n        \n        plt.figure(figsize=(15, 16))\n        plt.subplot(131), plt.imshow(img), plt.title(\"original\")\n        plt.subplot(132), plt.imshow(pred_mask, cmap=\"gray\"), plt.title(\"predicted\")\n        plt.subplot(133), plt.imshow(mask, cmap=\"gray\"), plt.title(\"mask\")\n        plt.show()\n","metadata":{"execution":{"iopub.status.busy":"2024-06-15T16:08:25.901885Z","iopub.execute_input":"2024-06-15T16:08:25.902262Z","iopub.status.idle":"2024-06-15T16:08:25.912509Z","shell.execute_reply.started":"2024-06-15T16:08:25.902231Z","shell.execute_reply":"2024-06-15T16:08:25.911589Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# n = 10\n\n# image_tensors = []\n# mask_tensors = []\n# image_paths = []\n\n# for _ in range(n):\n#     random_index = random.randint(0, len(test_dataloader.dataset) - 1)\n#     random_sample = test_dataloader.dataset[random_index]\n\n#     image_tensors.append(random_sample[0])  \n#     mask_tensors.append(random_sample[1]) \n#     image_paths.append(random_sample[2]) \n","metadata":{"execution":{"iopub.status.busy":"2024-06-15T16:09:21.044345Z","iopub.execute_input":"2024-06-15T16:09:21.044736Z","iopub.status.idle":"2024-06-15T16:09:21.048985Z","shell.execute_reply.started":"2024-06-15T16:09:21.044686Z","shell.execute_reply":"2024-06-15T16:09:21.048147Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# model_path = '/kaggle/working/my_checkpoint.pth'\n\n# random_images_inference(image_tensors, mask_tensors, image_paths, model_pàth, device=\"cpu\")\n","metadata":{"execution":{"iopub.status.busy":"2024-06-15T16:09:40.669563Z","iopub.execute_input":"2024-06-15T16:09:40.670529Z","iopub.status.idle":"2024-06-15T16:09:40.674561Z","shell.execute_reply.started":"2024-06-15T16:09:40.670491Z","shell.execute_reply":"2024-06-15T16:09:40.673542Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}