Switch to unified view

a b/Colab Notebooks/Deeptek-Task Segmentation - Unet_InceptionResnetv2.ipynb
1
{"cells":[{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":12674,"status":"ok","timestamp":1667542539234,"user":{"displayName":"Satvik Maheshwari","userId":"09768921556990219284"},"user_tz":-330},"id":"poHYeV3mMjlX","outputId":"ea0d3b8e-8c1f-4397-f19b-5f6eac5e3584"},"outputs":[{"output_type":"stream","name":"stdout","text":["Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n","Collecting pydicom\n","  Downloading pydicom-2.3.0-py3-none-any.whl (2.0 MB)\n","\u001b[K     |████████████████████████████████| 2.0 MB 4.5 MB/s \n","\u001b[?25hInstalling collected packages: pydicom\n","Successfully installed pydicom-2.3.0\n"]}],"source":["!pip install pydicom\n","import math\n","import os,sys\n","import pandas as pd\n","import numpy as np\n","import matplotlib.pyplot as plt\n","import seaborn as sns\n","from sklearn.model_selection import train_test_split\n","import pydicom\n","from pydicom import dcmread\n","from PIL import Image\n","import cv2\n","import tensorflow.keras.backend as K\n","from tensorflow.keras.backend import flatten\n","from tqdm.notebook import tqdm\n","from sklearn.metrics import classification_report,confusion_matrix"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"ZMBvYPXhRRGZ"},"outputs":[],"source":["df = pd.read_csv('/content/drive/MyDrive/Colab Notebooks/unique_df.csv')"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"lCdX4CB_N9sn"},"outputs":[],"source":["def create_mask(list1):\n","  for i in range(len(list1)):\n","    list1[i] = [int(item) for item in list1[i]]\n","  dim = np.zeros((1024,1024,))\n","  for i in range(len(list1)):\n","    x,y,w,h = list1[i]\n","    dim[x:x+w,y:y+h] = 1\n","  return dim"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"qNYoVc3rwsW1"},"outputs":[],"source":["from tensorflow.keras.utils import Sequence\n","\n","class DataGenerator(Sequence):\n","    'Generates data for Keras'\n","    def __init__(self, list_IDs, labels, batch_size=32, IMG_SIZE=None, n_channels=3,\n","                 n_classes=2, shuffle=True):\n","        'Initialization'\n","        self.IMG_SIZE = IMG_SIZE\n","        self.batch_size = batch_size\n","        self.labels = labels\n","        self.list_IDs = list_IDs\n","        self.n_channels = n_channels\n","        self.n_classes = n_classes\n","        self.shuffle = shuffle\n","        self.dim = (IMG_SIZE,IMG_SIZE)\n","        self.on_epoch_end()\n","        self.mapping = {k:v for k,v in zip(self.list_IDs,self.labels) }\n","            \n","    def __len__(self):\n","        'Denotes the number of batches per epoch'\n","        return int(np.floor(len(self.list_IDs) / self.batch_size))\n","\n","    def __getitem__(self, index):\n","        'Generate one batch of data'\n","        \n","        # Generate indexes of the batch\n","        indexes = self.indexes[index*self.batch_size:(index+1)*self.batch_size]\n","\n","        # Find list of IDs\n","        list_IDs_temp = [self.list_IDs[k] for k in indexes]\n","\n","        # Generate data\n","        X, y = self.__data_generation(list_IDs_temp)\n","        return X, y\n","\n","    def on_epoch_end(self):\n","        'Updates indexes after each epoch'\n","        self.indexes = np.arange(len(self.list_IDs))\n","        if self.shuffle == True:\n","            np.random.shuffle(self.indexes)\n","\n","    def __data_generation(self, list_IDs_temp):\n","        'Generates data containing batch_size samples' # X : (n_samples, *dim, n_channels)\n","        # Initialization\n","        X = np.empty((self.batch_size, *self.dim, self.n_channels))\n","        y = np.empty((self.batch_size, *self.dim, 1), dtype=int)\n","        \n","        # Generate data\n","        for i, ID in enumerate(list_IDs_temp):\n","\n","            # Store sample\n","            img = cv2.imread('/content/drive/MyDrive/Colab Notebooks/converted_train_images/' + ID + '.dcm.jpg')\n","\n","            #preprocessing of X-Ray images\n","            grayimg = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)\n","            clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(16, 16))\n","            image = clahe.apply(grayimg) \n","            fimg = cv2.cvtColor(image, cv2.COLOR_GRAY2BGR)\n","\n","            #normalizing the image \n","            fimg = fimg/fimg.max()\n","            fimg = fimg.astype('float')\n","\n","            #Store Images\n","            X[i,] = cv2.resize(fimg, (IMG_SIZE,IMG_SIZE))\n","\n","            # Store masks\n","            lst = self.mapping[ID]\n","            mask1 = create_mask(lst)\n","            y[i] = np.expand_dims(cv2.resize(mask1,(IMG_SIZE,IMG_SIZE)),-1)\n","\n","        return X,y"]},{"cell_type":"markdown","metadata":{"id":"3T_7flJdcwJy"},"source":["train_gen[batch no][X:0><Y:1][ith image in batch(range of i is 0 to 3]\n","\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"DgNKDkHzcwAC"},"outputs":[],"source":["Train = pd.read_csv('/content/drive/MyDrive/Data/Train.csv')\n","Val = pd.read_csv('/content/drive/MyDrive/Data/Valid.csv')\n","Test = pd.read_csv('/content/drive/MyDrive/Data/Test.csv')\n","\n","Train = Train.sample(frac=0.6,random_state=42)\n","Val = Val.sample(frac=0.6,random_state=42)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"NyASkMsXhy9D"},"outputs":[],"source":["Train['Masks'] = Train['Masks'].apply(lambda x: eval(x))\n","Test['Masks'] = Test['Masks'].apply(lambda x: eval(x))\n","Val['Masks'] = Val['Masks'].apply(lambda x: eval(x))"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":68,"status":"ok","timestamp":1667542541374,"user":{"displayName":"Satvik Maheshwari","userId":"09768921556990219284"},"user_tz":-330},"id":"bmK_HlgOdnJ6","outputId":"6c3dfc64-4ef8-4ea9-bb84-e9ed50acd1d9"},"outputs":[{"output_type":"stream","name":"stdout","text":["1400\n"]}],"source":["batch_size=8\n","IMG_SIZE=512\n","Train_gen = DataGenerator(list(Train.patientId),\n","                          list(Train.Masks),\n","                          batch_size=batch_size,\n","                          IMG_SIZE=IMG_SIZE,\n","                          shuffle=True)\n","print(len(Train_gen))"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":65,"status":"ok","timestamp":1667542541374,"user":{"displayName":"Satvik Maheshwari","userId":"09768921556990219284"},"user_tz":-330},"id":"VHAwwwbBdx-m","outputId":"98c69e19-cac8-4ad4-a04b-065b3c399c05"},"outputs":[{"output_type":"stream","name":"stdout","text":["300\n"]}],"source":["batch_size=8\n","IMG_SIZE=512\n","Val_gen = DataGenerator(list(Val.patientId),\n","                          list(Val.Masks),\n","                          batch_size=batch_size,\n","                          IMG_SIZE=IMG_SIZE,\n","                          shuffle=True)\n","print(len(Val_gen))"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":61,"status":"ok","timestamp":1667542541375,"user":{"displayName":"Satvik Maheshwari","userId":"09768921556990219284"},"user_tz":-330},"id":"F5NXUZGuN4jn","outputId":"227f42e8-048a-440f-8521-999bd6c7cbce"},"outputs":[{"output_type":"stream","name":"stdout","text":["4003\n"]}],"source":["batch_size=1\n","IMG_SIZE=512\n","Test_gen = DataGenerator(list(Test.patientId),\n","                          list(Test.Masks),\n","                          batch_size=batch_size,\n","                          IMG_SIZE=IMG_SIZE,\n","                          shuffle=False)\n","print(len(Test_gen))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"e6BjMecEt4oB"},"outputs":[],"source":["def mask_visualization(data,bno):\n","  for bi in range(8):\n","    fig = plt.figure(figsize=(15,10))\n","    rows=1\n","    columns=3\n","\n","    fig.add_subplot(rows,columns,1)\n","    # showing auto\n","    plt.imshow(data[bno][0][bi][:,:,-1],cmap='gray')\n","    plt.axis('image')\n","    plt.title(\"Xray\")\n","\n","    fig.add_subplot(rows,columns,2)\n","    # showing auto\n","    plt.imshow(data[bno][1][bi][:,:,-1],cmap='jet',alpha=0.3)\n","    plt.axis('image')\n","    plt.title(\"Mask\")\n","\n","    fig.add_subplot(rows,columns,3)\n","    # showing auto\n","    plt.imshow(data[bno][0][bi][:,:,-1],cmap='gray')\n","    plt.imshow(data[bno][1][bi][:,:,-1],cmap='jet',alpha=0.3)\n","    plt.axis('image')\n","    plt.title(\"Masked X-Ray\")"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":5806,"status":"ok","timestamp":1667542547148,"user":{"displayName":"Satvik Maheshwari","userId":"09768921556990219284"},"user_tz":-330},"id":"Av10dch6b7ng","outputId":"5d2c2bec-3518-4210-8c42-925fe457739b"},"outputs":[{"output_type":"stream","name":"stdout","text":["Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n","Collecting segmentation-models\n","  Downloading segmentation_models-1.0.1-py3-none-any.whl (33 kB)\n","Collecting keras-applications<=1.0.8,>=1.0.7\n","  Downloading Keras_Applications-1.0.8-py3-none-any.whl (50 kB)\n","\u001b[K     |████████████████████████████████| 50 kB 7.2 MB/s \n","\u001b[?25hCollecting image-classifiers==1.0.0\n","  Downloading image_classifiers-1.0.0-py3-none-any.whl (19 kB)\n","Collecting efficientnet==1.0.0\n","  Downloading efficientnet-1.0.0-py3-none-any.whl (17 kB)\n","Requirement already satisfied: scikit-image in /usr/local/lib/python3.7/dist-packages (from efficientnet==1.0.0->segmentation-models) (0.18.3)\n","Requirement already satisfied: numpy>=1.9.1 in /usr/local/lib/python3.7/dist-packages (from keras-applications<=1.0.8,>=1.0.7->segmentation-models) (1.21.6)\n","Requirement already satisfied: h5py in /usr/local/lib/python3.7/dist-packages (from keras-applications<=1.0.8,>=1.0.7->segmentation-models) (3.1.0)\n","Requirement already satisfied: cached-property in /usr/local/lib/python3.7/dist-packages (from h5py->keras-applications<=1.0.8,>=1.0.7->segmentation-models) (1.5.2)\n","Requirement already satisfied: networkx>=2.0 in /usr/local/lib/python3.7/dist-packages (from scikit-image->efficientnet==1.0.0->segmentation-models) (2.6.3)\n","Requirement already satisfied: imageio>=2.3.0 in /usr/local/lib/python3.7/dist-packages (from scikit-image->efficientnet==1.0.0->segmentation-models) (2.9.0)\n","Requirement already satisfied: tifffile>=2019.7.26 in /usr/local/lib/python3.7/dist-packages (from scikit-image->efficientnet==1.0.0->segmentation-models) (2021.11.2)\n","Requirement already satisfied: pillow!=7.1.0,!=7.1.1,>=4.3.0 in /usr/local/lib/python3.7/dist-packages (from scikit-image->efficientnet==1.0.0->segmentation-models) (7.1.2)\n","Requirement already satisfied: scipy>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from scikit-image->efficientnet==1.0.0->segmentation-models) (1.7.3)\n","Requirement already satisfied: PyWavelets>=1.1.1 in /usr/local/lib/python3.7/dist-packages (from scikit-image->efficientnet==1.0.0->segmentation-models) (1.3.0)\n","Requirement already satisfied: matplotlib!=3.0.0,>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from scikit-image->efficientnet==1.0.0->segmentation-models) (3.2.2)\n","Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.7/dist-packages (from matplotlib!=3.0.0,>=2.0.0->scikit-image->efficientnet==1.0.0->segmentation-models) (0.11.0)\n","Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib!=3.0.0,>=2.0.0->scikit-image->efficientnet==1.0.0->segmentation-models) (2.8.2)\n","Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib!=3.0.0,>=2.0.0->scikit-image->efficientnet==1.0.0->segmentation-models) (1.4.4)\n","Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib!=3.0.0,>=2.0.0->scikit-image->efficientnet==1.0.0->segmentation-models) (3.0.9)\n","Requirement already satisfied: typing-extensions in /usr/local/lib/python3.7/dist-packages (from kiwisolver>=1.0.1->matplotlib!=3.0.0,>=2.0.0->scikit-image->efficientnet==1.0.0->segmentation-models) (4.1.1)\n","Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.7/dist-packages (from python-dateutil>=2.1->matplotlib!=3.0.0,>=2.0.0->scikit-image->efficientnet==1.0.0->segmentation-models) (1.15.0)\n","Installing collected packages: keras-applications, image-classifiers, efficientnet, segmentation-models\n","Successfully installed efficientnet-1.0.0 image-classifiers-1.0.0 keras-applications-1.0.8 segmentation-models-1.0.1\n"]}],"source":["!pip install segmentation-models"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":34,"status":"ok","timestamp":1667542547149,"user":{"displayName":"Satvik Maheshwari","userId":"09768921556990219284"},"user_tz":-330},"id":"C1Ci2twRcf1l","outputId":"2bf0a0b0-118d-4b1c-b846-3ea1204a16ab"},"outputs":[{"output_type":"stream","name":"stdout","text":["Segmentation Models: using `keras` framework.\n"]}],"source":["import segmentation_models as sm\n","sm.set_framework('tf.keras')"]},{"cell_type":"code","execution_count":null,"metadata":{"executionInfo":{"elapsed":22342,"status":"ok","timestamp":1667542569468,"user":{"displayName":"Satvik Maheshwari","userId":"09768921556990219284"},"user_tz":-330},"id":"yn-eCIlCe5Bh","colab":{"base_uri":"https://localhost:8080/"},"outputId":"5906fe8b-19c3-4d03-def1-9bd05d859667"},"outputs":[{"output_type":"stream","name":"stdout","text":["Downloading data from https://github.com/fchollet/deep-learning-models/releases/download/v0.7/inception_resnet_v2_weights_tf_dim_ordering_tf_kernels_notop.h5\n","219055592/219055592 [==============================] - 14s 0us/step\n"]}],"source":["model = sm.Unet(backbone_name='inceptionresnetv2',\n","                         input_shape=(IMG_SIZE, IMG_SIZE, 3),\n","                         classes=1, activation='sigmoid',\n","                         weights=None,\n","                         encoder_weights='imagenet',\n","                         encoder_freeze=False,\n","                         encoder_features='default',\n","                         decoder_block_type='upsampling',\n","                         decoder_filters=(256, 128, 64, 32, 16),\n","                         decoder_use_batchnorm=True)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"o0MZMfpZg7cw"},"outputs":[],"source":["smooth = 0.000001\n","def dice_coef(y_true, y_pred):\n","    y_true_f = K.flatten(y_true)\n","    y_pred_f1 = K.flatten(K.round(y_pred))\n","    intersection = K.sum(y_true_f * y_pred_f1)\n","    return (2. * intersection) / (K.sum(y_true_f) + K.sum(y_pred_f1) + smooth)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"fvGNk3iLhk0T"},"outputs":[],"source":["smooth = 0.000001\n","def dice_loss(y_true, y_pred):\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"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"eDVwAHI-hpgJ"},"outputs":[],"source":["from tensorflow.keras.losses import binary_crossentropy\n","def weighted_bce_dice_loss(y_true, y_pred):\n","    return 0.85*binary_crossentropy(y_true, y_pred) + 0.15*dice_loss(y_true, y_pred)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"Re1SyMfWiEx2"},"outputs":[],"source":["from tensorflow.keras.optimizers import Adam\n","adam = Adam(learning_rate=0.0001)\n","model.compile(optimizer = adam, loss = binary_crossentropy , metrics=['accuracy',dice_coef])"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"dRiOUOxPiK5m"},"outputs":[],"source":["from tensorflow.keras.callbacks import CSVLogger,ModelCheckpoint, LearningRateScheduler, EarlyStopping, ReduceLROnPlateau\n","\n","base_model_path = '/content/drive/MyDrive/weights'\n","model_checkpoint = ModelCheckpoint(\n","        os.path.join(base_model_path,'Unet_InceptionResNet_1_min_val_loss.hdf5'),\n","        monitor=\"val_loss\", mode='min',save_best_only=True, verbose=1)\n","\n","early_stop = EarlyStopping(monitor = 'val_loss', patience = 5, restore_best_weights=True, verbose=1)\n","\n","model_checkpoint_dice = ModelCheckpoint(\n","        os.path.join(base_model_path,'Unet_InceptionResNet_max_val_dice.hdf5'),\n","        monitor=\"val_dice_coef\", mode='max',save_best_only=True, verbose=1)\n","\n","csv_path = '/content/drive/MyDrive/logs/Unet_InceptionResNet.csv' \n","csv_logger = CSVLogger(csv_path, append=True)\n","reduce_lr = ReduceLROnPlateau(monitor='val_loss', factor=0.1, patience=3, verbose=1, min_lr=1e-7)\n","\n","callbacks = [model_checkpoint, model_checkpoint_dice, reduce_lr, early_stop,csv_logger]"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"7hjQoXF7j-Ql","colab":{"base_uri":"https://localhost:8080/"},"outputId":"275667d7-7b34-48d5-e2c8-a16aa758e48d"},"outputs":[{"output_type":"stream","name":"stdout","text":["Epoch 1/15\n"," 890/1400 [==================>...........] - ETA: 26:21 - loss: 0.1869 - accuracy: 0.9585 - dice_coef: 0.0044"]}],"source":["#TRAINING\n","if os.path.exists(csv_path):\n","    os.remove(csv_path)\n","\n","model.fit(Train_gen,\n","          validation_data=Val_gen,\n","          epochs=15,\n","          verbose=1,\n","          callbacks=callbacks)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"ZH83rvXGGkNK"},"outputs":[],"source":["model.load_weights('/content/drive/MyDrive/weights/Unet_InceptionResNet_min_val_loss.hdf5')"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"tJNZFFxHHI99"},"outputs":[],"source":["def plot_masks(img,true,pred):\n","  plt.figure(figsize=(10,5))\n","  plt.subplot(1,2,1)\n","  plt.imshow(img)\n","  # plt.imshow(Test_gen[0][1][i][:,:,-1],cmap='jet',alpha=0.3)\n","  plt.imshow(true,cmap='jet',alpha=0.3)\n","\n","  plt.subplot(1,2,2)\n","  plt.imshow(img)\n","  # plt.imshow(np.squeeze(model.predict(Test_gen[i][0])),cmap='jet',alpha =0.3)\n","  plt.imshow(pred,cmap='jet',alpha=0.3)"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"background_save":true},"id":"8My-HNcAm-cU"},"outputs":[],"source":["# lst = list(Test[Test['Target'] == 1].index)\n","pred_prob = []\n","for i in tqdm(range(len(Test_gen))):\n","  img = np.squeeze(Test_gen[i][0])\n","  # pred_prob.append(np.squeeze(model.predict(Test_gen[i][0])))\n","  true = np.squeeze(Test_gen[i][1])\n","  pred=np.squeeze(model.predict(Test_gen[i][0]))\n","  plot_masks(img,true,pred)\n","  if(i==100): break"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"w4HYAHje8e5d"},"outputs":[],"source":["Test['pred_label']= Test.pred_prob.apply(lambda x: 1 if x>0.32 else 0)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"UBBz-jBRTW-y"},"outputs":[],"source":["TN, FP, FN, TP = confusion_matrix(Test.Target,Test.pred_label).ravel()"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":8,"status":"ok","timestamp":1667016902732,"user":{"displayName":"Satvik Maheshwari","userId":"09768921556990219284"},"user_tz":-330},"id":"k0Roptij8tKF","outputId":"235e4eaf-53ec-413e-b921-eb26d1338c1e"},"outputs":[{"name":"stdout","output_type":"stream","text":["572\n"]}],"source":["print(FP)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"HxTrmSct91QY"},"outputs":[],"source":["Precision = TP/(TP+FP)\n","Recall = TP / (FN+TP)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"1H2osrE6TuRt"},"outputs":[],"source":["print(\"Sensitivity:\", TP / (FN+TP))\n","print(\"Specificity:\", TN/(FP+TN))\n","print(\"Recall:\", TP / (FN+TP))\n","print(\"Precision:\", TP/(TP+FP))\n","print(\"F1-Score:\", 2 * (Precision * Recall)/ (Precision + Recall))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"vYYfVotdT6um"},"outputs":[],"source":["import sklearn.metrics as metrics\n","fpr, tpr, thresholds = metrics.roc_curve(Test.Target, Test.pred_prob)\n","roc_auc = metrics.auc(fpr, tpr)\n","# method I: plt\n","import matplotlib.pyplot as plt\n","plt.title('Receiver Operating Characteristic')\n","plt.plot(fpr, tpr, 'b', label = 'AUC = %0.2f' % roc_auc)\n","plt.legend(loc = 'lower right')\n","plt.ylabel('True Positive Rate')\n","plt.xlabel('False Positive Rate')\n","plt.show()"]},{"cell_type":"code","source":["model_tracker = pd.DataFrame(columns = ['model_id','architecture','batch_size','img_size','optimizer','lossfunction','weight_path','logs_path','Colab_URL','comments'])"],"metadata":{"id":"IqS7W8Aarz8U"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["model_tracker.append({'model_id' : \"UN_1\",\n","                      'architecture' : \"U-Net IncpetionV3\", \n","                      'batch_size' : 1,\n","                      'img_size' : 512,\n","                      'learning_rate' : 0.00001, \n","                      'optimizer' : \"Adam\", \n","                      'lossfunction' : \"Binary CrossEntropy\", \n","                      'weight_path' : \"/content/drive/MyDrive/weights/Unet_Inception_1_max_val_dice.hdf5 , /content/drive/MyDrive/weights/Unet_Inception_1_min_val_loss.hdf5\", \n","                      'logs_path' : \"/content/drive/MyDrive/logs/Unet_Inception_1.csv\", \n","                      'Colab_URL' : \"https://colab.research.google.com/drive/1m_V1-uCuR3uo--0Lj8e_cZyQAJ5e5YCB#scrollTo=U1OqRMPOr5rD\",\n","                      'comments' :\"The image size was 512 x 512 and it has a great AUC score of 0.91\" }, ignore_index = True)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":232},"id":"U1OqRMPOr5rD","executionInfo":{"status":"ok","timestamp":1667214681377,"user_tz":-330,"elapsed":511,"user":{"displayName":"Satvik Maheshwari","userId":"09768921556990219284"}},"outputId":"1a5da33c-9ba2-4914-c3a6-a0e99908b780"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["  model_id       architecture batch_size img_size optimizer  \\\n","0     UN_1  U-Net IncpetionV3          1      512      Adam   \n","\n","          lossfunction                                        weight_path  \\\n","0  Binary CrossEntropy  /content/drive/MyDrive/weights/Unet_Inception_...   \n","\n","                                          logs_path  \\\n","0  /content/drive/MyDrive/logs/Unet_Inception_1.csv   \n","\n","                                           Colab_URL  \\\n","0  https://colab.research.google.com/drive/1m_V1-...   \n","\n","                                            comments  learning_rate  \n","0  The image size was 512 x 512 and it has a grea...        0.00001  "],"text/html":["\n","  <div id=\"df-a97dd2ee-e3d2-48e2-91b4-2e530569e839\">\n","    <div class=\"colab-df-container\">\n","      <div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>model_id</th>\n","      <th>architecture</th>\n","      <th>batch_size</th>\n","      <th>img_size</th>\n","      <th>optimizer</th>\n","      <th>lossfunction</th>\n","      <th>weight_path</th>\n","      <th>logs_path</th>\n","      <th>Colab_URL</th>\n","      <th>comments</th>\n","      <th>learning_rate</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>UN_1</td>\n","      <td>U-Net IncpetionV3</td>\n","      <td>1</td>\n","      <td>512</td>\n","      <td>Adam</td>\n","      <td>Binary CrossEntropy</td>\n","      <td>/content/drive/MyDrive/weights/Unet_Inception_...</td>\n","      <td>/content/drive/MyDrive/logs/Unet_Inception_1.csv</td>\n","      <td>https://colab.research.google.com/drive/1m_V1-...</td>\n","      <td>The image size was 512 x 512 and it has a grea...</td>\n","      <td>0.00001</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>\n","      <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-a97dd2ee-e3d2-48e2-91b4-2e530569e839')\"\n","              title=\"Convert this dataframe to an interactive table.\"\n","              style=\"display:none;\">\n","        \n","  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n","       width=\"24px\">\n","    <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n","    <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n","  </svg>\n","      </button>\n","      \n","  <style>\n","    .colab-df-container {\n","      display:flex;\n","      flex-wrap:wrap;\n","      gap: 12px;\n","    }\n","\n","    .colab-df-convert {\n","      background-color: #E8F0FE;\n","      border: none;\n","      border-radius: 50%;\n","      cursor: pointer;\n","      display: none;\n","      fill: #1967D2;\n","      height: 32px;\n","      padding: 0 0 0 0;\n","      width: 32px;\n","    }\n","\n","    .colab-df-convert:hover {\n","      background-color: #E2EBFA;\n","      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n","      fill: #174EA6;\n","    }\n","\n","    [theme=dark] .colab-df-convert {\n","      background-color: #3B4455;\n","      fill: #D2E3FC;\n","    }\n","\n","    [theme=dark] .colab-df-convert:hover {\n","      background-color: #434B5C;\n","      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n","      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n","      fill: #FFFFFF;\n","    }\n","  </style>\n","\n","      <script>\n","        const buttonEl =\n","          document.querySelector('#df-a97dd2ee-e3d2-48e2-91b4-2e530569e839 button.colab-df-convert');\n","        buttonEl.style.display =\n","          google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n","        async function convertToInteractive(key) {\n","          const element = document.querySelector('#df-a97dd2ee-e3d2-48e2-91b4-2e530569e839');\n","          const dataTable =\n","            await google.colab.kernel.invokeFunction('convertToInteractive',\n","                                                     [key], {});\n","          if (!dataTable) return;\n","\n","          const docLinkHtml = 'Like what you see? Visit the ' +\n","            '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n","            + ' to learn more about interactive tables.';\n","          element.innerHTML = '';\n","          dataTable['output_type'] = 'display_data';\n","          await google.colab.output.renderOutput(dataTable, element);\n","          const docLink = document.createElement('div');\n","          docLink.innerHTML = docLinkHtml;\n","          element.appendChild(docLink);\n","        }\n","      </script>\n","    </div>\n","  </div>\n","  "]},"metadata":{},"execution_count":25}]},{"cell_type":"code","source":["model_tracker.to_csv('/content/drive/MyDrive/Model_Tracker_Deeptek_Segmentation.csv')"],"metadata":{"id":"V1KL4qOOuWaq"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":[],"metadata":{"id":"JqMLcCTKuX9D"},"execution_count":null,"outputs":[]}],"metadata":{"accelerator":"GPU","colab":{"collapsed_sections":[],"provenance":[{"file_id":"1m_V1-uCuR3uo--0Lj8e_cZyQAJ5e5YCB","timestamp":1667215043708},{"file_id":"1EanXRj0V1ttzigcm6cKz6LLUiD2MFOZN","timestamp":1661422765929}],"mount_file_id":"1qEd-oPMk1J1Q1l1hYsUqMTqjiFJ2jbZb","authorship_tag":"ABX9TyMjmwTB63UyyyTmblp3esMQ"},"gpuClass":"standard","kernelspec":{"display_name":"Python 3","name":"python3"},"language_info":{"name":"python"}},"nbformat":4,"nbformat_minor":0}