{"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)\nimport matplotlib.pyplot as plt\n!pip install torchvision\n!pip install torchmetrics\n!pip install torchmetrics[detection]\n!pip install torchvision\nplt.rcParams[\"figure.figsize\"] = (20,10)\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\n# import 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":"2023-11-05T21:06:32.262621Z","iopub.execute_input":"2023-11-05T21:06:32.263511Z","iopub.status.idle":"2023-11-05T21:07:19.996913Z","shell.execute_reply.started":"2023-11-05T21:06:32.263468Z","shell.execute_reply":"2023-11-05T21:07:19.995912Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import wandb\nfrom kaggle_secrets import UserSecretsClient\nuser_secrets = UserSecretsClient()\napi_key = user_secrets.get_secret(\"wandb_api\")\nwandb.login(key=api_key)","metadata":{"execution":{"iopub.status.busy":"2023-11-05T21:07:19.998845Z","iopub.execute_input":"2023-11-05T21:07:19.999448Z","iopub.status.idle":"2023-11-05T21:07:23.631678Z","shell.execute_reply.started":"2023-11-05T21:07:19.999421Z","shell.execute_reply":"2023-11-05T21:07:23.630715Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch\ndevice = torch.device(\"cuda\" if torch.cuda.is_available() else 'cpu')\ndevice","metadata":{"execution":{"iopub.status.busy":"2023-11-05T21:07:23.632952Z","iopub.execute_input":"2023-11-05T21:07:23.633535Z","iopub.status.idle":"2023-11-05T21:07:25.157702Z","shell.execute_reply.started":"2023-11-05T21:07:23.633501Z","shell.execute_reply":"2023-11-05T21:07:25.156805Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_labels=pd.read_csv(\"/kaggle/input/sartorius-cell-instance-segmentation/train.csv\")\nassert max(train_labels.groupby(\"id\")[\"cell_type\"].unique().apply(lambda d: len(d)).sort_values()) == 1\ntrain_labels = train_labels.set_index(\"id\")\nprint(\"GUD\")","metadata":{"execution":{"iopub.status.busy":"2023-11-05T21:07:25.160188Z","iopub.execute_input":"2023-11-05T21:07:25.160668Z","iopub.status.idle":"2023-11-05T21:07:25.830517Z","shell.execute_reply.started":"2023-11-05T21:07:25.160641Z","shell.execute_reply":"2023-11-05T21:07:25.829643Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# train_labels=train_labels.head(20000)\n# train_labels=train_labels.head(50)","metadata":{"execution":{"iopub.status.busy":"2023-11-05T21:07:25.831911Z","iopub.execute_input":"2023-11-05T21:07:25.832258Z","iopub.status.idle":"2023-11-05T21:07:25.836184Z","shell.execute_reply.started":"2023-11-05T21:07:25.832225Z","shell.execute_reply":"2023-11-05T21:07:25.835347Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cells = train_labels[\"cell_type\"].unique()\ncells","metadata":{"execution":{"iopub.status.busy":"2023-11-05T21:07:25.837429Z","iopub.execute_input":"2023-11-05T21:07:25.838107Z","iopub.status.idle":"2023-11-05T21:07:25.855747Z","shell.execute_reply.started":"2023-11-05T21:07:25.838080Z","shell.execute_reply":"2023-11-05T21:07:25.854862Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def decode_rle(inputs, height, width):\n    \"\"\"RLE to image\n    modified from: https://www.kaggle.com/paulorzp/run-length-encode-and-decode\n\n    Args:\n        rle (str): mask with run length encoding.\n        height (int): return image height.\n        width (int): return image width.\n        brightness (int): brightness of the pixel. Default to 1.\n\n    Returns:\n        np.ndarray: 1(b) - mask, 0 - background.\n    \"\"\"    \n    l = []\n    for rle in  inputs:\n        img = np.zeros(height * width, dtype=np.uint8)\n        s = 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 # brightness\n        l.append(torch.Tensor(img.reshape((height, width))))\n    return torch.stack(l)","metadata":{"execution":{"iopub.status.busy":"2023-11-05T21:07:25.856974Z","iopub.execute_input":"2023-11-05T21:07:25.857536Z","iopub.status.idle":"2023-11-05T21:07:25.865655Z","shell.execute_reply.started":"2023-11-05T21:07:25.857505Z","shell.execute_reply":"2023-11-05T21:07:25.864830Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_boxes(inputs):\n    result = []\n    for i in range(inputs.shape[0]):\n        # Assuming you have a binary mask tensor\n        binary_mask = inputs[i]\n        # Find the row and column indices of the non-zero elements\n        rows, cols = (binary_mask != 0).nonzero().t()\n        if len(rows) > 0:\n            # Calculate the bounding box coordinates in [x1, y1, x2, y2] format\n            x1 = cols.min().item()\n            y1 = rows.min().item()\n            x2 = cols.max().item()\n            y2 = rows.max().item()\n\n            # Create a tensor with the bounding box coordinates\n            bounding_box = torch.tensor([x1, y1, x2, y2])\n            result.append(bounding_box)\n    return torch.stack(result)","metadata":{"execution":{"iopub.status.busy":"2023-11-05T21:07:25.866709Z","iopub.execute_input":"2023-11-05T21:07:25.866971Z","iopub.status.idle":"2023-11-05T21:07:25.880105Z","shell.execute_reply.started":"2023-11-05T21:07:25.866949Z","shell.execute_reply":"2023-11-05T21:07:25.879333Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import  os\nimport pandas as pd\nfrom torchvision.io import read_image\nfrom matplotlib import pyplot as plt\nfrom torchvision.utils import save_image\n\n\nclass LocalImageDataset(torch.utils.data.Dataset):\n    def __init__(self,annotations, img_dir,x_transform=None ,transform=None, target_transform=None):\n        self.img_dir = img_dir\n        self.ids = annotations.index.unique()\n        self.annotations = annotations\n        self.transform = transform\n        self.target_transform = target_transform\n        self.x_transform  = x_transform \n    def __len__(self):\n        return len(self.ids)\n\n    def __getitem__(self, idx):\n        mid = self.ids[idx]\n        \n        img_path = os.path.join(self.img_dir,mid +\".png\")\n        image_x =  read_image(img_path) / 255\n\n        y_compressed = self.annotations.loc[mid]\n        h = y_compressed.iloc[0][\"height\"]\n        w = y_compressed.iloc[0][\"width\"]\n        image_y =  decode_rle(y_compressed[\"annotation\"].values,h,w)\n        image_x = image_x.view(image_x.shape[1],image_x.shape[2])\n        \n        image_x,image_y = image_x,image_y.permute(1,2,0)\n        if(self.x_transform != None):\n            transformed = self.x_transform(image=image_x.numpy())\n            image_x = torch.from_numpy(transformed['image'])\n        if(self.transform != None):\n            transformed = self.transform(image=image_x.numpy(), mask=image_y.numpy())\n            image_x = torch.from_numpy(transformed['image'])\n            image_y = torch.from_numpy(transformed['mask'])\n            \n   \n        image_x,image_y = image_x,image_y.permute(2,0,1)\n        \n        \n        boxes_y = get_boxes(image_y.to(\"cpu\"))\n        label = np.where(cells == y_compressed.iloc[0][\"cell_type\"])[0][0]\n#         norm = transforms.Normalize((0.5), (0.5))\n#         image_x = norm(image_x)\n        return image_x.to(\"cpu\"), {\"masks\": image_y.double().to(\"cpu\"),\"labels\": torch.Tensor([label for i in range(image_y.shape[0])]).int(),\"boxes\": boxes_y} ","metadata":{"execution":{"iopub.status.busy":"2023-11-05T21:07:25.881113Z","iopub.execute_input":"2023-11-05T21:07:25.881381Z","iopub.status.idle":"2023-11-05T21:07:26.125790Z","shell.execute_reply.started":"2023-11-05T21:07:25.881358Z","shell.execute_reply":"2023-11-05T21:07:26.125039Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torchvision.transforms as transforms\n\nimport albumentations as A\nx_transform = A.Compose([\n#     A.RandomCrop(width=650, height=800),\n#     A.RandomBrightnessContrast(p=0.25),\n#     A.GridDistortion(p=0.5),\n    A.Downscale(p=0.15),\n    A.Sharpen((0,1),p=1)\n\n])\ntransform = A.Compose([\n#     A.Rotate(360,p=0.6)\n],is_check_shapes=False)\n\ntrain_dataset = LocalImageDataset(train_labels,\"/kaggle/input/sartorius-cell-instance-segmentation/train\",x_transform=x_transform,transform=transform)\n# train_dataset = LocalImageDataset(train_labels,\"/kaggle/input/sartorius-cell-instance-segmentation/train\")","metadata":{"execution":{"iopub.status.busy":"2023-11-05T21:07:26.129937Z","iopub.execute_input":"2023-11-05T21:07:26.130224Z","iopub.status.idle":"2023-11-05T21:07:27.753185Z","shell.execute_reply.started":"2023-11-05T21:07:26.130200Z","shell.execute_reply":"2023-11-05T21:07:27.752245Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def collate(batch):\n    data_x = []\n    data_y = []\n    for i in range(len(batch)):\n        data_x.append(batch[i][0])\n        data_y.append(batch[i][1])\n    return data_x,data_y","metadata":{"execution":{"iopub.status.busy":"2023-11-05T21:07:27.754479Z","iopub.execute_input":"2023-11-05T21:07:27.754833Z","iopub.status.idle":"2023-11-05T21:07:27.760765Z","shell.execute_reply.started":"2023-11-05T21:07:27.754799Z","shell.execute_reply":"2023-11-05T21:07:27.759798Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from torch.utils.data import DataLoader\ntrain_loader = DataLoader(train_dataset,shuffle=False,collate_fn = collate,batch_size=2)","metadata":{"execution":{"iopub.status.busy":"2023-11-05T21:07:27.762005Z","iopub.execute_input":"2023-11-05T21:07:27.762347Z","iopub.status.idle":"2023-11-05T21:07:27.774113Z","shell.execute_reply.started":"2023-11-05T21:07:27.762301Z","shell.execute_reply":"2023-11-05T21:07:27.773309Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_gen = iter(train_loader)\na = next(train_gen)","metadata":{"execution":{"iopub.status.busy":"2023-11-05T21:07:27.775540Z","iopub.execute_input":"2023-11-05T21:07:27.775877Z","iopub.status.idle":"2023-11-05T21:07:30.200567Z","shell.execute_reply.started":"2023-11-05T21:07:27.775837Z","shell.execute_reply":"2023-11-05T21:07:30.199394Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport matplotlib.patches as patches\n\nfor i in range(len(a[0])): \n    img_x,y_dict = a[0][i],a[1][i]\n    label = y_dict[\"labels\"][0]\n   \n    img_y = y_dict[\"masks\"]\n    img_y = img_y.sum(dim=0).clip(0,1)\n\n    \n    fig,axs=plt.subplots(1,3)\n    axs[0].imshow(img_x.numpy(),cmap='Greys')\n    axs[1].imshow(img_y.numpy())\n    axs[2].imshow(img_x.numpy())\n    axs[2].imshow(img_y.numpy(),alpha=0.05,cmap='Greys',  interpolation='nearest')\n    \n    \n    for box in y_dict[\"boxes\"]:\n        # Create a Rectangle patch\n        rect = patches.Rectangle((box[0], box[1]), box[2]-box[0],  box[3]-box[1], linewidth=1, edgecolor='r', facecolor='none')\n\n        # Add the patch to the Axes\n        axs[1].add_patch(rect)\n    \n    print(label)\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2023-11-05T21:07:30.202708Z","iopub.execute_input":"2023-11-05T21:07:30.203093Z","iopub.status.idle":"2023-11-05T21:07:32.715708Z","shell.execute_reply.started":"2023-11-05T21:07:30.203059Z","shell.execute_reply":"2023-11-05T21:07:32.714762Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from torchvision.models.detection import maskrcnn_resnet50_fpn\nfrom torchvision.models.detection import MaskRCNN_ResNet50_FPN_Weights\nmodel = maskrcnn_resnet50_fpn(weights=MaskRCNN_ResNet50_FPN_Weights.DEFAULT)\n# model = maskrcnn_resnet50_fpn(weights=None)","metadata":{"execution":{"iopub.status.busy":"2023-11-05T21:07:32.716737Z","iopub.execute_input":"2023-11-05T21:07:32.717000Z","iopub.status.idle":"2023-11-05T21:07:35.626389Z","shell.execute_reply.started":"2023-11-05T21:07:32.716977Z","shell.execute_reply":"2023-11-05T21:07:35.625475Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torchvision\nfrom torchvision.models.detection.roi_heads import RoIHeads\nfrom torchvision.models.detection.rpn import RPNHead\nfrom torchvision.models.detection.anchor_utils import AnchorGenerator\n\n# model.rpn.anchor_generator = AnchorGenerator([(64,128, 256) for i in range(256)])\nmodel.rpn.head = RPNHead(256,3)\n\nmodel.roi_heads.box_head = torchvision.models.detection.faster_rcnn.TwoMLPHead(model.roi_heads.box_head.fc6.in_features,1024)\nmodel.roi_heads.box_predictor = torchvision.models.detection.faster_rcnn.FastRCNNPredictor(model.roi_heads.box_predictor.cls_score.in_features,3)\n\nmodel.roi_heads.mask_head = torchvision.models.detection.mask_rcnn.MaskRCNNHeads(model.roi_heads.mask_head[0][0].in_channels,[256,256,256,256],1)\nmodel.roi_heads.mask_predictor = torchvision.models.detection.mask_rcnn.MaskRCNNPredictor(256,256,3)\n\nfor param in model.parameters():\n    param.requires_grad = False\nfor param in model.roi_heads.parameters():\n    param.requires_grad = True\nfor param in model.rpn.parameters():\n    param.requires_grad = True","metadata":{"execution":{"iopub.status.busy":"2023-11-05T21:07:35.627818Z","iopub.execute_input":"2023-11-05T21:07:35.628219Z","iopub.status.idle":"2023-11-05T21:07:35.822956Z","shell.execute_reply.started":"2023-11-05T21:07:35.628183Z","shell.execute_reply":"2023-11-05T21:07:35.822073Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def process_img(d):\n    d[\"masks\"] = d[\"masks\"].to(device)\n    d[\"labels\"] = d[\"labels\"].long().to(device)\n    d[\"boxes\"]  = d[\"boxes\"].to(device)\n    return d","metadata":{"execution":{"iopub.status.busy":"2023-11-05T21:07:35.824204Z","iopub.execute_input":"2023-11-05T21:07:35.824531Z","iopub.status.idle":"2023-11-05T21:07:35.830119Z","shell.execute_reply.started":"2023-11-05T21:07:35.824504Z","shell.execute_reply":"2023-11-05T21:07:35.829116Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lr = 0.0002\nepochs = 25\nopt = torch.optim.Adam(params=model.parameters(),lr=lr)\nmodel.to(device)\ny_pred= None","metadata":{"execution":{"iopub.status.busy":"2023-11-05T21:07:35.831579Z","iopub.execute_input":"2023-11-05T21:07:35.832443Z","iopub.status.idle":"2023-11-05T21:07:38.882852Z","shell.execute_reply.started":"2023-11-05T21:07:35.832406Z","shell.execute_reply":"2023-11-05T21:07:38.882059Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"wandb.init(\n    # set the wandb project where this run will be logged\n    project=\"Maskrcnn\",\n    \n    # track hyperparameters and run metadata\n    config={\n    \"learning_rate\": lr,\n    \"epochs\": epochs,\n    \"dataset\": \"sartorius-cell-instance-segmentation\"\n    }\n)","metadata":{"execution":{"iopub.status.busy":"2023-11-05T21:07:38.884062Z","iopub.execute_input":"2023-11-05T21:07:38.884847Z","iopub.status.idle":"2023-11-05T21:08:09.882239Z","shell.execute_reply.started":"2023-11-05T21:07:38.884809Z","shell.execute_reply":"2023-11-05T21:08:09.881351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from torchmetrics.detection.mean_ap import MeanAveragePrecision \n\ntrain_metric = MeanAveragePrecision(max_detection_thresholds=[10,50,100,1000])\n\nmodel.train()\nwandb.watch(model,log_freq=5)\nfor e in range(epochs):\n    \n    train_gen = iter(train_loader)\n    epochLoss = 0\n    loss_classifier=0\n    loss_mask=0\n    loss_rpn_box_reg=0\n    loss_box_reg=0\n    loss_objectness=0\n    \n    train_metric.reset()\n    \n    for imgs_x,imgs_y in train_gen:\n\n        \n        #Input \n\n        x = torch.stack(list(map(lambda d: torch.stack([d,d,d]),imgs_x)))\n        x=x.to(device)\n\n        y_train=list(map(process_img,imgs_y))\n        y_pred = model(x,y_train)\n\n        l = y_pred[\"loss_classifier\"] + y_pred[\"loss_mask\"] + y_pred[\"loss_rpn_box_reg\"]  + y_pred[\"loss_box_reg\"] + y_pred[\"loss_objectness\"]\n\n        #Backpropagate\n        l.backward()\n        opt.step()\n        opt.zero_grad()\n         \n        with torch.no_grad():\n            epochLoss += l\n            \n            loss_classifier+=y_pred[\"loss_classifier\"]\n            loss_mask+= y_pred[\"loss_mask\"]\n            loss_rpn_box_reg+=y_pred[\"loss_rpn_box_reg\"]\n            loss_box_reg+=y_pred[\"loss_box_reg\"]\n            loss_objectness+=y_pred[\"loss_objectness\"]\n            \n            model.eval()\n            y_pred = model(x)\n            acc = train_metric(y_pred, y_train)\n            model.train()\n#         print(f\"L:{l.item()}\")\n\n    m = train_metric.compute()    \n    wandb.log({\n                \"epoch\": e,\n                \"loss\": epochLoss,\n                \"loss_classifier\": loss_classifier,\n                \"loss_mask\": loss_mask,\n                \"loss_rpn_box_reg\": loss_rpn_box_reg,\n                \"loss_box_reg\": loss_box_reg,\n                \"loss_objectness\": loss_objectness,\n                **m\n            })\n    \n    print(f\"Epoch {e} Loss {epochLoss} Metric : {m}\")\n        ","metadata":{"execution":{"iopub.status.busy":"2023-11-05T21:08:09.883927Z","iopub.execute_input":"2023-11-05T21:08:09.884260Z","iopub.status.idle":"2023-11-05T21:18:56.190001Z","shell.execute_reply.started":"2023-11-05T21:08:09.884228Z","shell.execute_reply":"2023-11-05T21:18:56.189064Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# torch.save(model,\"/kaggle/working/md_trasnfer.torch\")","metadata":{"execution":{"iopub.status.busy":"2023-11-05T21:18:56.191592Z","iopub.execute_input":"2023-11-05T21:18:56.192443Z","iopub.status.idle":"2023-11-05T21:18:56.198444Z","shell.execute_reply.started":"2023-11-05T21:18:56.192406Z","shell.execute_reply":"2023-11-05T21:18:56.197270Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# model = torch.load(\"/kaggle/working/md.torch\")","metadata":{"execution":{"iopub.status.busy":"2023-11-05T21:18:56.199608Z","iopub.execute_input":"2023-11-05T21:18:56.199909Z","iopub.status.idle":"2023-11-05T21:18:56.209154Z","shell.execute_reply.started":"2023-11-05T21:18:56.199884Z","shell.execute_reply":"2023-11-05T21:18:56.208198Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport matplotlib.patches as patches\nmodel.eval()\nwith torch.no_grad():\n    train_gen = iter(train_loader)\n    for imgs_x,imgs_y in train_gen:\n        x = torch.stack(list(map(lambda d: torch.stack([d,d,d]),imgs_x)))\n    #         y_train=list(map(process_img,imgs_y))\n        y_preds = model(x.to(device))\n        for j,y_pred in enumerate(y_preds):\n            \n            img_x = x[j][0,:,:]\n            img_y = imgs_y[j][\"masks\"]\n            \n\n#             img_y = img_y.view((img_y.shape[0],img_y.shape[2],img_y.shape[3]))\n            img_y = img_y.sum(dim=0).clip(0,1)\n            \n            img_y_pred = y_pred[\"masks\"].to(\"cpu\")\n            print(img_y_pred.shape)\n            img_y_pred = img_y_pred.view((img_y_pred.shape[0],img_y_pred.shape[2],img_y_pred.shape[3])) >= 0.5\n            img_y_pred = img_y_pred.sum(dim=0).clip(0,1)\n\n                \n#             for i in range(y_pred[\"labels\"].shape[0]):\n\n#                 label = y_pred[\"labels\"][i]\n#                 score = y_pred[\"scores\"][i]\n                \n                \n\n\n            print(img_y_pred.shape)\n\n\n            fig,axs=plt.subplots(1,3)\n            axs[0].imshow(img_x.numpy(),cmap='Greys')\n            axs[1].imshow(img_y.numpy())\n            axs[2].imshow(img_y_pred.numpy())\n#             axs[3].imshow(img_x.numpy())\n#             axs[3].imshow(img_y.numpy(),alpha=0.05,cmap='Greys',  interpolation='nearest')\n\n\n    #             for box in y_dict[\"boxes\"][i]:\n    #                 # Create a Rectangle patch\n    #                 rect = patches.Rectangle((box[0], box[1]), box[2]-box[0],  box[3]-box[1], linewidth=1, edgecolor='r', facecolor='none')\n\n    #                 # Add the patch to the Axes\n    #                 axs[1].add_patch(rect)\n\n#                 print(label)\n            plt.show()\n        ","metadata":{"execution":{"iopub.status.busy":"2023-11-05T21:18:56.212771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"wandb.finish()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}