{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","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":30823,"isInternetEnabled":true,"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","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2024-12-30T17:00:04.650525Z","iopub.execute_input":"2024-12-30T17:00:04.650836Z","iopub.status.idle":"2024-12-30T17:00:09.084115Z","shell.execute_reply.started":"2024-12-30T17:00:04.650809Z","shell.execute_reply":"2024-12-30T17:00:09.083232Z"}},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-30T17:00:17.889410Z","iopub.execute_input":"2024-12-30T17:00:17.889812Z","iopub.status.idle":"2024-12-30T17:00:17.894444Z","shell.execute_reply.started":"2024-12-30T17:00:17.889785Z","shell.execute_reply":"2024-12-30T17:00:17.893618Z"}},"outputs":[],"execution_count":null},{"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","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-30T17:00:20.647088Z","iopub.execute_input":"2024-12-30T17:00:20.647430Z","iopub.status.idle":"2024-12-30T17:00:20.652597Z","shell.execute_reply.started":"2024-12-30T17:00:20.647400Z","shell.execute_reply":"2024-12-30T17:00:20.651687Z"}},"outputs":[],"execution_count":null},{"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)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-30T17:00:22.798349Z","iopub.execute_input":"2024-12-30T17:00:22.798651Z","iopub.status.idle":"2024-12-30T17:00:22.803782Z","shell.execute_reply.started":"2024-12-30T17:00:22.798628Z","shell.execute_reply":"2024-12-30T17:00:22.802846Z"}},"outputs":[],"execution_count":null},{"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","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-30T17:00:25.509824Z","iopub.execute_input":"2024-12-30T17:00:25.510115Z","iopub.status.idle":"2024-12-30T17:00:25.516851Z","shell.execute_reply.started":"2024-12-30T17:00:25.510093Z","shell.execute_reply":"2024-12-30T17:00:25.515788Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"input_image = torch.rand((5,3,512,512))\nmodel = UNet(3,10)\noutput = model(input_image)\nprint(output.size())\n# You should get torch.Size([1, 10, 512, 512]) as a result","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-30T17:02:01.596799Z","iopub.execute_input":"2024-12-30T17:02:01.597225Z","iopub.status.idle":"2024-12-30T17:02:16.955822Z","shell.execute_reply.started":"2024-12-30T17:02:01.597191Z","shell.execute_reply":"2024-12-30T17:02:16.954914Z"}},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-30T14:48:19.426128Z","iopub.execute_input":"2024-12-30T14:48:19.426870Z","iopub.status.idle":"2024-12-30T14:48:19.433148Z","shell.execute_reply.started":"2024-12-30T14:48:19.426836Z","shell.execute_reply":"2024-12-30T14:48:19.432368Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(os.listdir(\"../input/carvana-image-masking-challenge/\"))\n\nDATASET_DIR = '../input/carvana-image-masking-challenge/'\nWORKING_DIR = '/kaggle/working/'","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-30T14:48:33.838807Z","iopub.execute_input":"2024-12-30T14:48:33.839087Z","iopub.status.idle":"2024-12-30T14:48:33.848604Z","shell.execute_reply.started":"2024-12-30T14:48:33.839068Z","shell.execute_reply":"2024-12-30T14:48:33.847732Z"}},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-30T14:48:45.196783Z","iopub.execute_input":"2024-12-30T14:48:45.197082Z","iopub.status.idle":"2024-12-30T14:48:53.729990Z","shell.execute_reply.started":"2024-12-30T14:48:45.197062Z","shell.execute_reply":"2024-12-30T14:48:53.729310Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_dataset = CarvanaDataset(WORKING_DIR)\n\ngenerator = torch.Generator().manual_seed(25)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-30T14:48:58.371369Z","iopub.execute_input":"2024-12-30T14:48:58.371667Z","iopub.status.idle":"2024-12-30T14:48:58.384443Z","shell.execute_reply.started":"2024-12-30T14:48:58.371645Z","shell.execute_reply":"2024-12-30T14:48:58.383682Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_dataset, test_dataset = random_split(train_dataset, [0.8, 0.2], generator=generator)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-30T14:49:08.167327Z","iopub.execute_input":"2024-12-30T14:49:08.167632Z","iopub.status.idle":"2024-12-30T14:49:08.173815Z","shell.execute_reply.started":"2024-12-30T14:49:08.167610Z","shell.execute_reply":"2024-12-30T14:49:08.173024Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_dataset, val_dataset = random_split(test_dataset, [0.5, 0.5], generator=generator)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-30T14:49:23.118741Z","iopub.execute_input":"2024-12-30T14:49:23.119023Z","iopub.status.idle":"2024-12-30T14:49:23.122893Z","shell.execute_reply.started":"2024-12-30T14:49:23.119003Z","shell.execute_reply":"2024-12-30T14:49:23.121989Z"}},"outputs":[],"execution_count":null},{"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","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-30T15:41:39.436309Z","iopub.execute_input":"2024-12-30T15:41:39.436596Z","iopub.status.idle":"2024-12-30T15:41:39.440691Z","shell.execute_reply.started":"2024-12-30T15:41:39.436576Z","shell.execute_reply":"2024-12-30T15:41:39.439750Z"}},"outputs":[],"execution_count":null},{"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()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-30T14:51:28.057674Z","iopub.execute_input":"2024-12-30T14:51:28.057961Z","iopub.status.idle":"2024-12-30T14:51:28.505772Z","shell.execute_reply.started":"2024-12-30T14:51:28.057939Z","shell.execute_reply":"2024-12-30T14:51:28.504841Z"}},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-30T14:51:40.353459Z","iopub.execute_input":"2024-12-30T14:51:40.353780Z","iopub.status.idle":"2024-12-30T14:51:40.358185Z","shell.execute_reply.started":"2024-12-30T14:51:40.353751Z","shell.execute_reply":"2024-12-30T14:51:40.357349Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"torch.cuda.empty_cache()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-30T14:51:47.737888Z","iopub.execute_input":"2024-12-30T14:51:47.738304Z","iopub.status.idle":"2024-12-30T14:51:47.741864Z","shell.execute_reply.started":"2024-12-30T14:51:47.738251Z","shell.execute_reply":"2024-12-30T14:51:47.741005Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"EPOCHS = 2\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')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-30T15:16:33.343793Z","iopub.execute_input":"2024-12-30T15:16:33.344112Z","iopub.status.idle":"2024-12-30T15:30:24.717636Z","shell.execute_reply.started":"2024-12-30T15:16:33.344078Z","shell.execute_reply":"2024-12-30T15:30:24.716856Z"}},"outputs":[],"execution_count":null},{"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()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-30T15:31:55.271753Z","iopub.execute_input":"2024-12-30T15:31:55.272046Z","iopub.status.idle":"2024-12-30T15:31:55.931577Z","shell.execute_reply.started":"2024-12-30T15:31:55.272023Z","shell.execute_reply":"2024-12-30T15:31:55.930681Z"}},"outputs":[],"execution_count":null},{"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()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-30T15:32:10.695352Z","iopub.execute_input":"2024-12-30T15:32:10.695659Z","iopub.status.idle":"2024-12-30T15:32:11.175938Z","shell.execute_reply.started":"2024-12-30T15:32:10.695632Z","shell.execute_reply":"2024-12-30T15:32:11.175047Z"}},"outputs":[],"execution_count":null},{"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)))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-30T15:32:15.742274Z","iopub.execute_input":"2024-12-30T15:32:15.742621Z","iopub.status.idle":"2024-12-30T15:32:16.173471Z","shell.execute_reply.started":"2024-12-30T15:32:15.742594Z","shell.execute_reply":"2024-12-30T15:32:16.172749Z"}},"outputs":[],"execution_count":null},{"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)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-30T15:32:19.630320Z","iopub.execute_input":"2024-12-30T15:32:19.630624Z","iopub.status.idle":"2024-12-30T15:32:39.636058Z","shell.execute_reply.started":"2024-12-30T15:32:19.630602Z","shell.execute_reply":"2024-12-30T15:32:39.635165Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def random_images_inference(image_tensors, mask_tensors, model_path, device):\n    model = UNet(in_channels=3, num_classes=1).to(device)\n    model.load_state_dict(torch.load(model_path, 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, mask_pth in zip(image_tensors, mask_tensors):\n        # Load the image\n        img = transform(image)\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        # 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()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-30T15:55:23.191588Z","iopub.execute_input":"2024-12-30T15:55:23.191908Z","iopub.status.idle":"2024-12-30T15:55:23.198737Z","shell.execute_reply.started":"2024-12-30T15:55:23.191886Z","shell.execute_reply":"2024-12-30T15:55:23.197732Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"n = 2\n\nimage_tensors = []\nmask_tensors = []\n\nfor _ 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]) ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-30T15:55:30.236191Z","iopub.execute_input":"2024-12-30T15:55:30.236555Z","iopub.status.idle":"2024-12-30T15:55:30.328158Z","shell.execute_reply.started":"2024-12-30T15:55:30.236530Z","shell.execute_reply":"2024-12-30T15:55:30.327453Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model_path = '/kaggle/working/my_checkpoint.pth'\n\nrandom_images_inference(image_tensors=image_tensors, \n                        mask_tensors=mask_tensors, \n                        model_path=model_path,\n                        device=\"cpu\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-30T15:55:36.020843Z","iopub.execute_input":"2024-12-30T15:55:36.021137Z","iopub.status.idle":"2024-12-30T15:55:42.593310Z","shell.execute_reply.started":"2024-12-30T15:55:36.021115Z","shell.execute_reply":"2024-12-30T15:55:42.592422Z"}},"outputs":[],"execution_count":null}]}