{"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 segmentation-models --no-index --find-links \"../input/python-wheels/\"\n","metadata":{"execution":{"iopub.status.busy":"2022-09-04T11:24:45.361792Z","iopub.execute_input":"2022-09-04T11:24:45.362726Z","iopub.status.idle":"2022-09-04T11:24:57.455675Z","shell.execute_reply.started":"2022-09-04T11:24:45.362611Z","shell.execute_reply":"2022-09-04T11:24:57.454477Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# move weights to the folder\n!cp -R ../input/keras-weights-dataset ~/.keras/models/","metadata":{"execution":{"iopub.status.busy":"2022-09-04T11:24:57.459180Z","iopub.execute_input":"2022-09-04T11:24:57.459810Z","iopub.status.idle":"2022-09-04T11:25:31.695525Z","shell.execute_reply.started":"2022-09-04T11:24:57.459778Z","shell.execute_reply":"2022-09-04T11:25:31.694206Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow import keras\nfrom tensorflow.keras import layers\nimport tensorflow_datasets as tfds\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport pandas as pd\nimport tifffile as tiff \nimport cv2\nfrom skimage.transform import resize\nimport seaborn as sns\nfrom skimage.color import rgb2gray\nfrom sklearn.model_selection import train_test_split as tts\nfrom tensorflow.keras.callbacks import ModelCheckpoint\nfrom pprint import pprint\nimport albumentations as A\n\n#from tensorflow.keras.applications import EfficientNetB4\n#import efficientnet.keras as efn\nfrom keras import backend as K\nfrom keras.losses import binary_crossentropy\nimport tensorflow as tf\n\n\nfrom PIL import Image, ImageOps\nfrom skimage import color\nfrom IPython.display import clear_output\nfrom tensorflow.keras import backend as K\nimport segmentation_models as sm\nsm.set_framework('tf.keras')\nsm.framework()\n\nfrom segmentation_models import Unet, FPN\nfrom segmentation_models.utils import set_trainable\ntf.config.experimental_run_functions_eagerly(True)\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-09-04T11:25:31.697579Z","iopub.execute_input":"2022-09-04T11:25:31.697954Z","iopub.status.idle":"2022-09-04T11:25:41.502636Z","shell.execute_reply.started":"2022-09-04T11:25:31.697917Z","shell.execute_reply":"2022-09-04T11:25:41.500782Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"CFG = {\n    \"data_dir\": \"../input/hubmap-organ-segmentation/\",\n    \"seed\": 42,\n    \"epochs\": 30,\n    \"image_size\": 512,\n    \"batch_size\": 4,\n    \"test_size\": 0.15,\n    \"cat_features\": ['tissue_thickness','age','organ','sex'],\n    \"fit_verbose\": 2, # one line per epoch\n    \"unet_configs\": {\n        \"backbone_name\":'efficientnetb6',\n        \"input_shape\": (512, 512, 3),\n        \"classes\": 1,\n        \"activation\": 'sigmoid',\n        \"encoder_weights\": \"imagenet\",\n    },\n    \"adam_learning_rate\": 1e-4,\n}\n\npprint(CFG)","metadata":{"execution":{"iopub.status.busy":"2022-09-04T11:25:41.505323Z","iopub.execute_input":"2022-09-04T11:25:41.506101Z","iopub.status.idle":"2022-09-04T11:25:41.514448Z","shell.execute_reply.started":"2022-09-04T11:25:41.506070Z","shell.execute_reply":"2022-09-04T11:25:41.513291Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Meta and Image Data**","metadata":{}},{"cell_type":"code","source":"train_df = pd.read_csv(CFG[\"data_dir\"] + \"train.csv\")\n","metadata":{"execution":{"iopub.status.busy":"2022-09-04T11:25:41.516236Z","iopub.execute_input":"2022-09-04T11:25:41.517300Z","iopub.status.idle":"2022-09-04T11:25:41.813624Z","shell.execute_reply.started":"2022-09-04T11:25:41.517264Z","shell.execute_reply":"2022-09-04T11:25:41.812556Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Train Pie Chart\ndef pie_target(feat,df):\n    fig, ax = plt.subplots(4,2,figsize=(22,22))\n    for i in enumerate(feat):\n            fig.suptitle('Pie chart and Count Plot', size = 29)\n            ax[i[0],0].title.set_text(f'Pie of {i[1]}')\n            labels = list(df[i[1]].value_counts().index)\n            values = df[i[1]].value_counts()\n            \n            ax[i[0],0].pie(values,startangle=60, labels=labels,autopct='%1.0f%%', pctdistance=0.6)\n            ax[i[0],1].title.set_text(f'Count Plot for {i[1]}')\n            sns.countplot(x=i[1],data=df ,ax=ax[i[0],1])\n            ax[i[0],0].add_artist(plt.Circle((0,0),0.4,fc='white'))\n    fig.tight_layout()        \n    plt.show()\n    \n#pie_target(CFG[\"cat_features\"],train_df)","metadata":{"execution":{"iopub.status.busy":"2022-09-04T11:25:41.815007Z","iopub.execute_input":"2022-09-04T11:25:41.815358Z","iopub.status.idle":"2022-09-04T11:25:41.825359Z","shell.execute_reply.started":"2022-09-04T11:25:41.815324Z","shell.execute_reply":"2022-09-04T11:25:41.824313Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## **Masking and Unmaksing Function**","metadata":{}},{"cell_type":"code","source":"def rle2mask(rle, width, target_size=None):\n    if target_size == None:\n        target_size = width\n\n    rle = np.array(list(map(int, rle.split())))\n    label = np.zeros((width*width))\n    \n    for start, end in zip(rle[::2], rle[1::2]):\n        label[start:start+end] = 1\n        \n    #Convert label to image\n    label = Image.fromarray(label.reshape(width, width))\n    #Resize label\n    label = label.resize((target_size, target_size))\n    label = np.array(label).astype(float)\n    #rescale label\n    label = np.round((label - label.min())/(label.max() - label.min()))\n    \n    return label.T\n\ndef mask2rle(mask, orig_dim=160):\n    #Rescale image to original size\n    size = int(len(mask.flatten())**.5)\n    n = Image.fromarray(mask.reshape((size, size))*255.0)\n    n = n.resize((orig_dim, orig_dim))\n    n = np.array(n).astype(np.float32)\n    #Get pixels to flatten\n    pixels = n.T.flatten()\n    #Round the pixels using the half of the range of pixel value\n    pixels = (pixels-min(pixels) > ((max(pixels)-min(pixels))/2)).astype(int)\n    pixels = np.nan_to_num(pixels) #incase of zero-div-error\n    \n    pixels = np.concatenate([[0], pixels, [0]])\n    runs = np.where(pixels[1:] != pixels[:-1])[0]\n    runs[1::2] -= runs[::2]\n    \n    return ' '.join(str(x) for x in runs)","metadata":{"execution":{"iopub.status.busy":"2022-09-04T11:25:41.827067Z","iopub.execute_input":"2022-09-04T11:25:41.827683Z","iopub.status.idle":"2022-09-04T11:25:41.840085Z","shell.execute_reply.started":"2022-09-04T11:25:41.827645Z","shell.execute_reply":"2022-09-04T11:25:41.839047Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Organ Data Generator**","metadata":{}},{"cell_type":"code","source":"class ImageDataGenerator(tf.keras.utils.Sequence):\n    def __init__(self, df, batch_size=32, train=False, size=256):\n        self.df = df.reset_index(drop=True)\n        self.dim = size\n        self.train = train\n        if self.train: self.batch_size = batch_size // 4\n        else: self.batch_size = batch_size\n        self.pref = 'train' if train else 'test'\n    \n    def __len__(self):\n        return np.ceil(len(self.df) / self.batch_size).astype(int)\n    \n    def on_epoch_end(self):\n        if self.train: #Reshuffle train on end of epoch\n            self.df = self.df.sample(frac=1.0).reset_index(drop=True)\n            \n    def __getitem__(self, idx):\n        batch_x = self.df.iloc[idx*self.batch_size:(idx+1)*self.batch_size].id.values\n        \n        if not self.train:\n            X = np.zeros((batch_x.shape[0], self.dim, self.dim, 3))\n            \n            for i in range(batch_x.shape[0]):\n                image = Image.open(CFG[\"data_dir\"] + f\"{self.pref}_images/{batch_x[i]}.tiff\")\n                image = image.resize((self.dim, self.dim))\n                image = np.array(image) / 255.\n                X[i,] = image\n                \n            return X\n                \n        else:\n            batch_y = self.df.iloc[idx*self.batch_size:(idx+1)*self.batch_size].rle.values\n            batch_w = self.df.iloc[idx*self.batch_size:(idx+1)*self.batch_size].img_width.values\n            #print(batch_y, batch_w)\n            X = np.zeros((batch_x.shape[0]*4, self.dim, self.dim, 3))\n            Y = np.zeros((batch_x.shape[0]*4, self.dim, self.dim, 1))\n            \n            for i in range(batch_x.shape[0]):\n                image = Image.open(CFG[\"data_dir\"] + f\"{self.pref}_images/{batch_x[i]}.tiff\")\n                image = image.resize((self.dim, self.dim))\n                image = np.array(image)\n                #image = np.array(image) / 255\n                rle = rle2mask(batch_y[i], batch_w[i], self.dim)\n                rle = rle.reshape((self.dim, self.dim, 1))\n\n                for n, (h, v) in enumerate([(0, 0), (0, 1), (1, 0), (1, 1)]):\n                    X[i*4 + n, :, :, :], Y[i*4 + n, :, :, :] = self.augumention(image,rle)\n                    \n            return X, Y#.reshape(Y.shape[:-1])\n                \n    def getAuguments(self):\n        auguments = [\n                A.Blur(blur_limit=7, always_apply=False, p=0.5),\n                A.CLAHE(clip_limit=5.0, tile_grid_size=(8, 8), always_apply=False, p=0.66),\n                A.RandomBrightnessContrast(brightness_limit=0.3, contrast_limit=0.3, p=0.5),\n                A.Posterize (num_bits=6, p=0.3),\n                A.RandomGamma (gamma_limit=(50, 300), p=0.3),    \n                A.Sharpen (alpha=(0.2, 0.7), lightness=(0.7, 1.0), p=0.4),\n                A.Flip(p=0.5),\n                A.ElasticTransform (alpha_affine=60, p=0.5),\n                A.RandomResizedCrop(self.dim,self.dim, p=0.33),\n                A.Rotate (limit=180, p=0.5)\n        ]\n        return A.Compose(auguments)\n    \n    def augumention(self, image,mask):\n        transform = self.getAuguments()\n        transformed = transform(image=image.astype('uint8'), mask=mask.astype('int'))\n        return transformed['image'] / 255, transformed['mask']","metadata":{"execution":{"iopub.status.busy":"2022-09-04T11:25:41.841710Z","iopub.execute_input":"2022-09-04T11:25:41.842158Z","iopub.status.idle":"2022-09-04T11:25:41.862522Z","shell.execute_reply.started":"2022-09-04T11:25:41.842123Z","shell.execute_reply":"2022-09-04T11:25:41.861221Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#train_loader = ImageDataGenerator(train_df, batch_size=CFG[], train=True, size=256)\n#dataget_check = train_loader.__getitem__(1)","metadata":{"execution":{"iopub.status.busy":"2022-09-04T11:25:41.864523Z","iopub.execute_input":"2022-09-04T11:25:41.864966Z","iopub.status.idle":"2022-09-04T11:25:41.877029Z","shell.execute_reply.started":"2022-09-04T11:25:41.864930Z","shell.execute_reply":"2022-09-04T11:25:41.876063Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## **Graph Plot Visualize**","metadata":{}},{"cell_type":"code","source":"\nclass PlotLearning(tf.keras.callbacks.Callback):\n    \"\"\"\n    Callback to plot the learning curves of the model during training.\n    \"\"\"\n    def on_train_begin(self, logs={}):\n        self.metrics = {}\n        for metric in logs:\n            self.metrics[metric] = []\n        \n    def on_epoch_end(self, epoch, logs={}):\n        # Storing metrics\n        for metric in logs:\n            if metric in self.metrics:\n                self.metrics[metric].append(logs.get(metric))\n            else:\n                self.metrics[metric] = [logs.get(metric)]\n        \n        # Plotting\n        metrics = [x for x in logs if 'val' not in x]\n        \n        f, axs = plt.subplots(1, len(metrics), figsize=(15,5))\n        clear_output(wait=True)\n\n        for i, metric in enumerate(metrics):\n            axs[i].plot(range(1, epoch + 2), \n                        self.metrics[metric], \n                        label=metric)\n            if logs['val_' + metric]:\n                axs[i].plot(range(1, epoch + 2), \n                            self.metrics['val_' + metric], \n                            label='val_' + metric)\n                \n            axs[i].legend()\n            axs[i].grid()\n\n        plt.tight_layout()\n        plt.show()\n        ","metadata":{"execution":{"iopub.status.busy":"2022-09-04T11:25:41.881396Z","iopub.execute_input":"2022-09-04T11:25:41.882247Z","iopub.status.idle":"2022-09-04T11:25:41.892571Z","shell.execute_reply.started":"2022-09-04T11:25:41.882210Z","shell.execute_reply":"2022-09-04T11:25:41.891606Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **PreTrained Segmentation Model**","metadata":{}},{"cell_type":"markdown","source":"# **Metric's and Loss Function**","metadata":{}},{"cell_type":"code","source":"def dice_coef(y_true, y_pred, smooth=1):\n    y_true_f = K.flatten(y_true)\n    y_pred_f = K.flatten(y_pred)\n    intersection = K.sum(y_true_f * y_pred_f)\n    return (2. * intersection + smooth) / (K.sum(y_true_f) + K.sum(y_pred_f) + smooth)\n\ndef iou_coef(y_true, y_pred, smooth=1):\n    intersection = K.sum(K.abs(y_true * y_pred), axis=[1,2,3])\n    union = K.sum(y_true,[1,2,3])+K.sum(y_pred,[1,2,3])-intersection\n    iou = K.mean((intersection + smooth) / (union + smooth), axis=0)\n    return iou\n\n\ndef dice_loss(y_true, y_pred):\n    smooth = 1.\n    y_true_f = K.flatten(y_true)\n    y_pred_f = K.flatten(y_pred)\n    intersection = y_true_f * y_pred_f\n    score = (2. * K.sum(intersection) + smooth) / (K.sum(y_true_f) + K.sum(y_pred_f) + smooth)\n    return 1. - score\n\ndef bce_dice_loss(y_true, y_pred):\n    return binary_crossentropy(tf.cast(y_true, tf.float32), y_pred) + 0.5 * dice_loss(tf.cast(y_true, tf.float32), y_pred)\n\ndef weighted_loss(y_true, y_pred):\n    # Calculate the base loss\n    ce = K.sparse_categorical_crossentropy(y_true, y_pred)\n    # Apply the weights\n    one_weight = 1.0\n    zero_weight = 1e-2\n    weight_vector = y_true * one_weight + (1. - y_true) * zero_weight\n    weight_vector = K.squeeze(weight_vector, axis=-1)\n    weighted_ce = weight_vector * ce\n\n    # Return the mean error\n    return K.mean(weighted_ce)","metadata":{"execution":{"iopub.status.busy":"2022-09-04T11:25:41.894163Z","iopub.execute_input":"2022-09-04T11:25:41.894755Z","iopub.status.idle":"2022-09-04T11:25:41.908131Z","shell.execute_reply.started":"2022-09-04T11:25:41.894719Z","shell.execute_reply":"2022-09-04T11:25:41.907197Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### **Model Parameters**","metadata":{}},{"cell_type":"code","source":"\n#We will be training a model for each organ\norgans = train_df.organ.unique()\nprint(\"Organs:\", organs)","metadata":{"execution":{"iopub.status.busy":"2022-09-04T11:25:41.909685Z","iopub.execute_input":"2022-09-04T11:25:41.910048Z","iopub.status.idle":"2022-09-04T11:25:41.931883Z","shell.execute_reply.started":"2022-09-04T11:25:41.910013Z","shell.execute_reply":"2022-09-04T11:25:41.930827Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Model Training and Evaluation**","metadata":{}},{"cell_type":"code","source":"def train_organ(organ, plot_training_history=True):\n    print(\"Training for organ:\", organ)\n\n    model = Unet(**CFG[\"unet_configs\"])\n    model.compile(\n        loss=bce_dice_loss, \n        optimizer=tf.keras.optimizers.Adam(learning_rate=CFG[\"adam_learning_rate\"]),\n        metrics=['accuracy', dice_coef])\n\n    X = train_df[train_df.organ == organ].reset_index(drop=True)\n    train_X, valid_X = tts(X, test_size=CFG[\"test_size\"], shuffle=True, random_state=CFG[\"seed\"])\n    train_loader = ImageDataGenerator(train_X, CFG[\"batch_size\"], True, CFG[\"image_size\"])\n    valid_loader = ImageDataGenerator(valid_X, CFG[\"batch_size\"], True, CFG[\"image_size\"])\n    \n    callbacks_list = [\n        PlotLearning(), \n        ModelCheckpoint(f\"{organ}_model.h5\", monitor='val_dice_coef', save_best_only=True, mode='max', verbose=True),\n    ]\n\n    history = model.fit(\n        train_loader,\n        validation_data=valid_loader,\n        epochs=CFG[\"epochs\"],\n        use_multiprocessing=False,\n        callbacks=callbacks_list,\n        verbose=CFG[\"fit_verbose\"],\n    )\n    \n    if plot_training_history:\n        fig, ax = plt.subplots(figsize=(15, 15))\n        ax1 = ax.plot(history.history[\"loss\"] , label=\"loss\")\n        ax2 = ax.plot(history.history[\"val_loss\"], label = \"val_loss\")\n        plt.rcParams[\"figure.figsize\"] = (15, 15)\n        plt.xlabel(\"Epochs\")\n        plt.legend()\n        plt.title(\"Training and Validation loss\")\n        plt.show()\n        \n\n    # Model Evaluation and Predidtion\n    model = tf.keras.models.load_model(f\"{organ}_model.h5\",compile=False)\n    tx, ty = valid_loader[0]\n    pty = model.predict(tx).round()\n\n    # Orginal Image VS Mask\n    plt.figure(figsize=(20, 20))\n    for i in range(4):\n        plt.figure(figsize=(20, 20))\n        plt.subplot(1, 2, 1)\n        plt.title('Orginal')\n        plt.imshow(tx[i])\n        plt.imshow(ty[i], cmap='coolwarm', alpha=0.5)\n        plt.subplot(1, 2, 2)\n        plt.title('Predicted')\n        plt.imshow(tx[i])\n        plt.imshow(pty[i], cmap='coolwarm', alpha=0.5)","metadata":{"execution":{"iopub.status.busy":"2022-09-04T11:25:41.933447Z","iopub.execute_input":"2022-09-04T11:25:41.934116Z","iopub.status.idle":"2022-09-04T11:25:41.948230Z","shell.execute_reply.started":"2022-09-04T11:25:41.934079Z","shell.execute_reply":"2022-09-04T11:25:41.947229Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_organ(organs[0])\nprint(\"Training Complected for\", organs[0])","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-09-04T11:25:41.949915Z","iopub.execute_input":"2022-09-04T11:25:41.950254Z","iopub.status.idle":"2022-09-04T11:27:52.494137Z","shell.execute_reply.started":"2022-09-04T11:25:41.950220Z","shell.execute_reply":"2022-09-04T11:27:52.490876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_organ(organs[1])\nprint(\"Training Complected for\", organs[1])","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-09-04T11:27:52.495449Z","iopub.status.idle":"2022-09-04T11:27:52.495968Z","shell.execute_reply.started":"2022-09-04T11:27:52.495706Z","shell.execute_reply":"2022-09-04T11:27:52.495731Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_organ(organs[2])\nprint(\"Training Complected for\", organs[2])","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-09-04T11:27:52.497746Z","iopub.status.idle":"2022-09-04T11:27:52.498389Z","shell.execute_reply.started":"2022-09-04T11:27:52.498130Z","shell.execute_reply":"2022-09-04T11:27:52.498155Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_organ(organs[3])\nprint(\"Training Complected for\", organs[3])","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-09-04T11:27:52.500607Z","iopub.status.idle":"2022-09-04T11:27:52.501125Z","shell.execute_reply.started":"2022-09-04T11:27:52.500908Z","shell.execute_reply":"2022-09-04T11:27:52.500932Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_organ(organs[4])\nprint(\"Training Complected for\", organs[4])","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-09-04T11:27:52.508213Z","iopub.status.idle":"2022-09-04T11:27:52.508920Z","shell.execute_reply.started":"2022-09-04T11:27:52.508659Z","shell.execute_reply":"2022-09-04T11:27:52.508684Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Test Prediction**","metadata":{}},{"cell_type":"code","source":"test_df = pd.read_csv(CFG[\"data_dir\"] + \"test.csv\")\nsub = {'id':[], 'rle':[]}\n\nfor organ in organs:\n    print(\"Predicting on organ:\", organ)\n\n    test_X = test_df[test_df.organ == organ].reset_index(drop=True)\n    if len(test_X) == 0: continue #Skip organs without item in test\n        \n    model = tf.keras.models.load_model(f\"./{organ}_model.h5\", compile=False)\n    \n    test_loader = ImageDataGenerator(test_X, CFG[\"batch_size\"], False,CFG[\"image_size\"])\n    preds = model.predict(test_loader)\n    rle = [mask2rle(m, d) for m,d in zip(preds.round(), test_X.img_width)]\n    sub['id'] += test_X.id.values.tolist()\n    sub['rle'] += rle\n    \n    \nsub = pd.DataFrame(sub)\ntest_df = test_df.merge(sub, on='id')\nsub = test_df[['id', 'rle']].copy()\nsub.to_csv('submission.csv', index=False)\nsub","metadata":{"execution":{"iopub.status.busy":"2022-09-04T11:27:52.510811Z","iopub.status.idle":"2022-09-04T11:27:52.515356Z","shell.execute_reply.started":"2022-09-04T11:27:52.514902Z","shell.execute_reply":"2022-09-04T11:27:52.514961Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(20, 20))\nfor i in range(1):\n    plt.figure(figsize=(20, 20))\n    plt.subplot(1, 2, 1)\n    plt.title('Orginal')\n    plt.imshow(test_loader[0][0])\n    plt.subplot(1, 2, 2)\n    plt.title('Predicted')\n    plt.imshow(test_loader[0][0])\n    plt.imshow(preds[i], cmap='coolwarm', alpha=0.5)","metadata":{"execution":{"iopub.status.busy":"2022-09-04T11:27:52.518466Z","iopub.status.idle":"2022-09-04T11:27:52.519096Z","shell.execute_reply.started":"2022-09-04T11:27:52.518841Z","shell.execute_reply":"2022-09-04T11:27:52.518865Z"},"trusted":true},"execution_count":null,"outputs":[]}]}