{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.7.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":14774,"databundleVersionId":875431,"sourceType":"competition"},{"sourceId":2220078,"sourceType":"datasetVersion","datasetId":1172878}],"dockerImageVersionId":30236,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"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)\n\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\nimport os\nfor 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","scrolled":true,"_kg_hide-output":true,"execution":{"iopub.status.busy":"2023-12-06T15:09:09.407997Z","iopub.execute_input":"2023-12-06T15:09:09.408900Z","iopub.status.idle":"2023-12-06T15:09:14.587244Z","shell.execute_reply.started":"2023-12-06T15:09:09.408453Z","shell.execute_reply":"2023-12-06T15:09:14.586245Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Importing libraries and modules","metadata":{}},{"cell_type":"code","source":"# Necessary utility modules and libraries\nimport os\nimport shutil\nimport random\nimport cv2\n\n# Plotting libraries \nimport numpy as np\nimport matplotlib.pyplot as plt\nimport matplotlib.image as mpimg\nfrom scipy.signal import gaussian, convolve2d\nimport seaborn as sns\n\n# Libraries for building the model\nimport tensorflow as tf\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\nfrom tensorflow.keras import layers, regularizers\nfrom tensorflow.keras.applications import EfficientNetB7, EfficientNetB0\nfrom tensorflow.keras.models import Sequential, Model\nfrom tensorflow.keras import backend as K\nfrom tensorflow.keras.regularizers import l2, l1\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import precision_score, recall_score, f1_score, confusion_matrix","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:09:14.589215Z","iopub.execute_input":"2023-12-06T15:09:14.589911Z","iopub.status.idle":"2023-12-06T15:09:20.867290Z","shell.execute_reply.started":"2023-12-06T15:09:14.589872Z","shell.execute_reply":"2023-12-06T15:09:20.866465Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Data Loading and Pre-processing","metadata":{}},{"cell_type":"code","source":"classes = ['No_DR', 'Mild', 'Moderate', 'Severe', 'Proliferate_DR']","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:09:20.868358Z","iopub.execute_input":"2023-12-06T15:09:20.868880Z","iopub.status.idle":"2023-12-06T15:09:20.873718Z","shell.execute_reply.started":"2023-12-06T15:09:20.868850Z","shell.execute_reply":"2023-12-06T15:09:20.872620Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dir_path = '/kaggle/input/aptos2019-blindness-detection/'\nos.listdir(dir_path)","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2023-12-06T15:09:20.876656Z","iopub.execute_input":"2023-12-06T15:09:20.877014Z","iopub.status.idle":"2023-12-06T15:09:20.895486Z","shell.execute_reply.started":"2023-12-06T15:09:20.876979Z","shell.execute_reply":"2023-12-06T15:09:20.894595Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train = pd.read_csv(\"/kaggle/input/aptos2019-blindness-detection/train.csv\").sample(frac=1, random_state=42)\ndf_test = pd.read_csv(\"/kaggle/input/aptos2019-blindness-detection/test.csv\").sample(frac=1, random_state=42)","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:09:20.896508Z","iopub.execute_input":"2023-12-06T15:09:20.896855Z","iopub.status.idle":"2023-12-06T15:09:20.924965Z","shell.execute_reply.started":"2023-12-06T15:09:20.896827Z","shell.execute_reply":"2023-12-06T15:09:20.924291Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(df_train), len(df_test)","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:09:20.926147Z","iopub.execute_input":"2023-12-06T15:09:20.926874Z","iopub.status.idle":"2023-12-06T15:09:20.932977Z","shell.execute_reply.started":"2023-12-06T15:09:20.926837Z","shell.execute_reply":"2023-12-06T15:09:20.932036Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.sample(5)","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:09:20.934138Z","iopub.execute_input":"2023-12-06T15:09:20.934508Z","iopub.status.idle":"2023-12-06T15:09:20.952535Z","shell.execute_reply.started":"2023-12-06T15:09:20.934472Z","shell.execute_reply":"2023-12-06T15:09:20.951576Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train['diagnosis'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:09:20.953706Z","iopub.execute_input":"2023-12-06T15:09:20.953952Z","iopub.status.idle":"2023-12-06T15:09:20.966122Z","shell.execute_reply.started":"2023-12-06T15:09:20.953928Z","shell.execute_reply":"2023-12-06T15:09:20.965321Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class_code = {0: \"No_DR\",\n              1: \"Mild\", \n              2: \"Moderate\",\n              3: \"Severe\",\n              4: \"Proliferate_DR\"}","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:09:20.967346Z","iopub.execute_input":"2023-12-06T15:09:20.967711Z","iopub.status.idle":"2023-12-06T15:09:20.972751Z","shell.execute_reply.started":"2023-12-06T15:09:20.967675Z","shell.execute_reply":"2023-12-06T15:09:20.971836Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:09:20.977088Z","iopub.execute_input":"2023-12-06T15:09:20.977483Z","iopub.status.idle":"2023-12-06T15:09:20.989002Z","shell.execute_reply.started":"2023-12-06T15:09:20.977444Z","shell.execute_reply":"2023-12-06T15:09:20.988119Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def mapping_temp(df, root=dir_path):\n    df['label'] = list(map(class_code.get, df['diagnosis']))\n    df['path'] = [i[1]['label']+'/'+i[1]['id_code']+'.png' for i in df.iterrows()]\n    return df\n\ndf_train = mapping_temp(df_train)\ndf_train","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:09:20.990190Z","iopub.execute_input":"2023-12-06T15:09:20.990564Z","iopub.status.idle":"2023-12-06T15:09:21.217512Z","shell.execute_reply.started":"2023-12-06T15:09:20.990527Z","shell.execute_reply":"2023-12-06T15:09:21.216598Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Dropping the diagnosis column because the model assigns different codes for prediction\ndf_train.drop(['diagnosis'], axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:09:21.218664Z","iopub.execute_input":"2023-12-06T15:09:21.218958Z","iopub.status.idle":"2023-12-06T15:09:21.224964Z","shell.execute_reply.started":"2023-12-06T15:09:21.218933Z","shell.execute_reply":"2023-12-06T15:09:21.224132Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train['label'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:09:21.226092Z","iopub.execute_input":"2023-12-06T15:09:21.228412Z","iopub.status.idle":"2023-12-06T15:09:21.237411Z","shell.execute_reply.started":"2023-12-06T15:09:21.228374Z","shell.execute_reply":"2023-12-06T15:09:21.236549Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Making no. of DR and non DR classes equal\n# num_images_classes = {'No_DR': 500, 'Moderate': 400}\nfor class_name in classes:\n    class_samples = df_train[df_train['label'] == class_name]\n    selected_samples = class_samples.sample(n=193, random_state=42)\n    samples_to_delete = class_samples.index.difference(selected_samples.index)\n    df_train.drop(samples_to_delete, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:09:21.238496Z","iopub.execute_input":"2023-12-06T15:09:21.238797Z","iopub.status.idle":"2023-12-06T15:09:21.260979Z","shell.execute_reply.started":"2023-12-06T15:09:21.238771Z","shell.execute_reply":"2023-12-06T15:09:21.260118Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# wiener filter\ndef wiener_filter(img, kernel, K):\n    kernel /= np.sum(kernel)\n    dummy = np.copy(img)\n    dummy = np.fft.fft2(dummy)\n    kernel = np.fft.fft2(kernel, s = img.shape)\n    kernel = np.conj(kernel) / (np.abs(kernel) ** 2 + K)\n    dummy = dummy * kernel\n    dummy = np.abs(np.fft.ifft2(dummy))\n    return dummy.astype('uint8')\n\ndef gaussian_kernel(kernel_size = 3):\n    h = gaussian(kernel_size, kernel_size / 3).reshape(kernel_size, 1)\n    h = np.dot(h, h.transpose())\n    h /= np.sum(h)\n    return h","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:09:21.262070Z","iopub.execute_input":"2023-12-06T15:09:21.262363Z","iopub.status.idle":"2023-12-06T15:09:21.270277Z","shell.execute_reply.started":"2023-12-06T15:09:21.262338Z","shell.execute_reply":"2023-12-06T15:09:21.269303Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def crop_image_from_gray(img,tol=7):\n    if img.ndim ==2:\n        mask = img>tol\n        return img[np.ix_(mask.any(1),mask.any(0))]\n    elif img.ndim==3:\n        gray_img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)\n        mask = gray_img>tol\n        \n        check_shape = img[:,:,0][np.ix_(mask.any(1),mask.any(0))].shape[0]\n        if (check_shape == 0): # image is too dark so that we crop out everything,\n            return img # return original image\n        else:\n            img1=img[:,:,0][np.ix_(mask.any(1),mask.any(0))]\n            img2=img[:,:,1][np.ix_(mask.any(1),mask.any(0))]\n            img3=img[:,:,2][np.ix_(mask.any(1),mask.any(0))]\n            img = np.stack([img1,img2,img3],axis=-1)\n        return img\n    \ndef image_preprocessing(image):\n    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n    image = crop_image_from_gray(image)\n    image = cv2.resize(image, (512, 512))\n    kernel = gaussian_kernel(kernel_size=3)\n    image = wiener(image)\n\n    # Apply CLAHE on green channel\n    green=image[:, :, 1]\n    clipLimit = 2.0\n    tileGridSize = (8,8)\n    clahe=cv2.createCLAHE(clipLimit = clipLimit, tileGridSize = tileGridSize)\n    cla=clahe.apply(green.astype('uint8'))\n    image=cv2.merge((cla,cla,cla))\n    plt.imshow(image)\n    return image.astype('float64')\n\ndef wiener(image):\n    green=image[:, :, 1]\n    wiener = wiener_filter(green, gaussian_kernel(3), 10)\n#     print(wiener.dtype, green.dtype)\n    green = cv2.addWeighted(green, 1.5, wiener, -0.5, 0)\n    img=cv2.merge((green,green,green))\n    return img","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:09:21.271429Z","iopub.execute_input":"2023-12-06T15:09:21.271716Z","iopub.status.idle":"2023-12-06T15:09:21.287837Z","shell.execute_reply.started":"2023-12-06T15:09:21.271682Z","shell.execute_reply":"2023-12-06T15:09:21.287049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"random_img = random.sample(os.listdir(dir_path+'/train_images'), 1)[0]\nrandom_img_path = dir_path+'/train_images/'+random_img\nimage = cv2.imread(random_img_path)\nimage = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\npro = image_preprocessing(image)\nfilename = os.path.basename(random_img_path)\nprint(df_train[df_train['id_code']==random_img[:-4]]['label'])","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:09:21.289298Z","iopub.execute_input":"2023-12-06T15:09:21.289646Z","iopub.status.idle":"2023-12-06T15:09:21.951553Z","shell.execute_reply.started":"2023-12-06T15:09:21.289611Z","shell.execute_reply":"2023-12-06T15:09:21.950641Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# random_img_path = [dir_path+'/train_images/'+img for img in random.sample(os.listdir(dir_path+'train_images'), 50)]\n\n# plt.figure(figsize=(20, 15))\n# plt.suptitle(\"Image Dataset for CLAHE Processed Images\", fontsize=20)\n\n# for i in range(1, 51):\n#     plt.subplot(5, 10, i)\n#     plt.title(list(df_train[df_train['id_code']==random_img_path[i-1].split('/')[-1][:-4]]['label'])[0])\n#     img = cv2.imread(random_img_path[i-1])\n#     img_pro = image_preprocessing(img)\n# #     plt.imshow(img_pro, aspect=\"auto\")\n#     plt.axis(False);","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:09:33.324413Z","iopub.execute_input":"2023-12-06T15:09:33.324805Z","iopub.status.idle":"2023-12-06T15:09:33.329969Z","shell.execute_reply.started":"2023-12-06T15:09:33.324767Z","shell.execute_reply":"2023-12-06T15:09:33.328924Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(5):\n    os.mkdir('./'+class_code[i])","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:09:33.331482Z","iopub.execute_input":"2023-12-06T15:09:33.331765Z","iopub.status.idle":"2023-12-06T15:09:33.360161Z","shell.execute_reply.started":"2023-12-06T15:09:33.331739Z","shell.execute_reply":"2023-12-06T15:09:33.359312Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport shutil\nres = [[i[1][1], i[1][2]] for i in df_train.iterrows()]\nfor i in res:\n    filename = i[1].split('/')[1]\n    src = os.path.join(dir_path+'train_images/', filename)\n    class_name = i[0]\n    des = os.path.join('./'+class_name+'/', filename)\n    img = cv2.imread(src)\n    img = image_preprocessing(img)\n    cv2.imwrite(des, img)","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2023-12-06T15:09:33.361807Z","iopub.execute_input":"2023-12-06T15:09:33.362118Z","iopub.status.idle":"2023-12-06T15:14:29.784114Z","shell.execute_reply.started":"2023-12-06T15:09:33.362090Z","shell.execute_reply":"2023-12-06T15:14:29.783175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# The model assigns labels in ascending order\nclasses = sorted(classes)\nclasses","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:14:29.785412Z","iopub.execute_input":"2023-12-06T15:14:29.785717Z","iopub.status.idle":"2023-12-06T15:14:29.792215Z","shell.execute_reply.started":"2023-12-06T15:14:29.785688Z","shell.execute_reply":"2023-12-06T15:14:29.791307Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Initializing the input size\nIMG_SHAPE = (128, 128)\nEPOCHS = 20\nBATCH_SIZE = 8\n\ntrain_df, val_df = train_test_split(df_train, test_size=0.2, stratify=df_train['label'], random_state=42)","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:14:29.794565Z","iopub.execute_input":"2023-12-06T15:14:29.794866Z","iopub.status.idle":"2023-12-06T15:14:29.808189Z","shell.execute_reply.started":"2023-12-06T15:14:29.794838Z","shell.execute_reply":"2023-12-06T15:14:29.807436Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_datagen = ImageDataGenerator(rescale = 1./255,\n                                   rotation_range=20,\n                                   width_shift_range=0.2,\n                                   height_shift_range=0.2,\n                                   zoom_range=0.2,\n                                   shear_range=0.2)\n\nvalid_datagen = ImageDataGenerator(rescale = 1./255)\n\ntrain_data = train_datagen.flow_from_dataframe(dataframe=train_df, \n                                       x_col='path',\n                                       y_col='label',\n                                       class_mode='categorical',\n                                       batch_size=BATCH_SIZE,        \n                                       target_size=IMG_SHAPE)\n\nvalid_data = valid_datagen.flow_from_dataframe(dataframe=val_df, \n                                       x_col='path',\n                                       y_col='label',\n                                       class_mode=\"categorical\",\n                                       batch_size=BATCH_SIZE,\n                                       target_size=IMG_SHAPE)","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:14:29.809322Z","iopub.execute_input":"2023-12-06T15:14:29.809597Z","iopub.status.idle":"2023-12-06T15:14:29.838215Z","shell.execute_reply.started":"2023-12-06T15:14:29.809571Z","shell.execute_reply":"2023-12-06T15:14:29.837319Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Evaluation metric helper functions","metadata":{}},{"cell_type":"code","source":"def cm(y_true, y_pred):\n    classes.sort()\n    cm = confusion_matrix(y_true, y_pred)\n    cm_df = pd.DataFrame(cm,\n                     index = classes, \n                     columns = classes)\n    #Plotting the confusion matrix\n    plt.figure(figsize=(5,4))\n    sns.heatmap(cm_df, annot=True)\n    plt.title('Confusion Matrix')\n    plt.ylabel('Actal Values')\n    plt.xlabel('Predicted Values')\n    plt.show()\n\ndef metrics(y_test, y_pred_binary):\n    '''\n    Function to display accuracy, precision, recall and f1-score for the classification task.\n    \n    Parameters:\n    y_test: True labels.\n    y_pred_binary: Predicted binary labels.\n\n    Returns:\n    Pandas dataframe containing class-wise Sensitivity, Specificity, and F1-score.\n    \n    '''\n    df_res = []\n    precision_per_class = precision_score(y_test, y_pred_binary, average=None)\n    recall_per_class = recall_score(y_test, y_pred_binary, average=None)\n    f1_per_class = f1_score(y_test, y_pred_binary, average=None)\n\n    for i in range(len(classes)):\n        df_res.append([classes[i], recall_per_class[i], precision_per_class[i], f1_per_class[i]])\n    df_res = pd.DataFrame(df_res, columns = ['Class','Sensitivity','Specificity', 'F1-score'])\n    return df_res\n\n# Function to make predictions on the test data\ndef make_predictions(model_test):\n    # Evaluate the model\n    predictions = model_test.predict(valid_data, verbose=1)\n    y_preds = np.argmax(predictions, axis=1)\n    return y_preds\n\n# Function to plot the performance metrics\ndef plot_result(hist):\n    plt.figure(figsize=(10, 5));\n    plt.suptitle(f\"Performance Metrics\", fontsize=20)\n    \n    # Actual and validation losses\n    plt.subplot(1, 2, 1);\n    plt.plot(hist['loss'], label='train')\n    plt.plot(hist['val_loss'], label='validation')\n    plt.title('Train and val loss curve')\n    plt.legend()\n\n    # Actual and validation accuracy\n    plt.subplot(1, 2, 2);\n    plt.plot(hist['binary_accuracy'], label='train')\n    plt.plot(hist['val_binary_accuracy'], label='validation')\n    plt.title('Train and val accuracy curve')\n    plt.legend()\n    \n# View random images in the dataset\ndef view_random_images(root_dir, classes=classes):\n    class_paths = [root_dir + \"/\" + image_class for image_class in classes]\n    # print(class_paths)\n    images_path = []\n    labels = []\n    for i in range(len(class_paths)):\n        random_images = random.sample(os.listdir(class_paths[i]), 10)\n        random_images_path = [class_paths[i]+'/'+img for img in random_images]\n        for j in random_images_path:\n            images_path.append(j)\n            labels.append(classes[i])\n    images_path\n\n    plt.figure(figsize=(17, 10))\n    plt.suptitle(\"Image Dataset\", fontsize=20)\n\n    for i in range(1, 51):\n        plt.subplot(5, 10, i)\n        img = mpimg.imread(images_path[i-1])\n        plt.imshow(img, aspect=\"auto\")\n        plt.title(labels[i-1])\n        plt.axis(False);","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:14:29.839360Z","iopub.execute_input":"2023-12-06T15:14:29.839641Z","iopub.status.idle":"2023-12-06T15:14:29.859031Z","shell.execute_reply.started":"2023-12-06T15:14:29.839614Z","shell.execute_reply":"2023-12-06T15:14:29.858073Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Observing the images\nview_random_images(root_dir='./')","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:14:29.860174Z","iopub.execute_input":"2023-12-06T15:14:29.860489Z","iopub.status.idle":"2023-12-06T15:14:35.094221Z","shell.execute_reply.started":"2023-12-06T15:14:29.860462Z","shell.execute_reply":"2023-12-06T15:14:35.093184Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Modelling (base Models)\nWe'll use the variations of EfficientNet and Unets and observe the variations of the accuracy of the predicitions as predicted by the models:\n* EfficientNetB0\n* EffB0Unet\n* EfficientNetB7\n* EffB7Unet","metadata":{}},{"cell_type":"code","source":"def callback(name, patience=9):\n    early_stopping = tf.keras.callbacks.EarlyStopping(patience=patience, restore_best_weights=True)\n    model_checkpoint = tf.keras.callbacks.ModelCheckpoint(f\"{name}.h5\", save_best_only=True)\n    return [early_stopping, model_checkpoint]","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:14:35.095675Z","iopub.execute_input":"2023-12-06T15:14:35.095977Z","iopub.status.idle":"2023-12-06T15:14:35.101391Z","shell.execute_reply.started":"2023-12-06T15:14:35.095948Z","shell.execute_reply":"2023-12-06T15:14:35.100299Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Model-1. EfficientNetB0","metadata":{}},{"cell_type":"code","source":"# Basic architecture of DenseNet\nbase_model_efficientnet=EfficientNetB0(include_top=False, input_shape=IMG_SHAPE+(3,)) \nmodel_efficientnet=Sequential()\nmodel_efficientnet.add(base_model_efficientnet)\nmodel_efficientnet.add(layers.GlobalAveragePooling2D())\nmodel_efficientnet.add(layers.Dropout(0.2))\nmodel_efficientnet.add(layers.Dense(5, activation='sigmoid'))\n# Summary of the denseNet model\nmodel_efficientnet.summary()","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:14:35.102613Z","iopub.execute_input":"2023-12-06T15:14:35.102915Z","iopub.status.idle":"2023-12-06T15:14:40.536360Z","shell.execute_reply.started":"2023-12-06T15:14:35.102878Z","shell.execute_reply":"2023-12-06T15:14:40.535406Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_efficientnet.compile(loss='binary_crossentropy',\n                  optimizer=tf.keras.optimizers.Adam(learning_rate=0.0001),\n                  metrics=['binary_accuracy'])\n\nmodel_efficientnet_history = model_efficientnet.fit(train_data,\n                                                   validation_data=valid_data,\n                                                   steps_per_epoch=int(train_data.n//train_data.batch_size),\n                                                   epochs=20,\n                                                   validation_steps=int(valid_data.n//valid_data.batch_size),\n                                                   callbacks=[callback(patience=5, name=\"efficientnet_301023\")])","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2023-12-06T15:14:40.539975Z","iopub.execute_input":"2023-12-06T15:14:40.540352Z","iopub.status.idle":"2023-12-06T15:16:35.803114Z","shell.execute_reply.started":"2023-12-06T15:14:40.540325Z","shell.execute_reply":"2023-12-06T15:16:35.801495Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_preds_model_efficientnet = make_predictions(model_efficientnet)\ny_true = valid_data.classes\n# Metrics for effUNet\nmetrics(y_true, y_preds_model_efficientnet)","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:16:35.805078Z","iopub.execute_input":"2023-12-06T15:16:35.805414Z","iopub.status.idle":"2023-12-06T15:16:38.933827Z","shell.execute_reply.started":"2023-12-06T15:16:35.805385Z","shell.execute_reply":"2023-12-06T15:16:38.932711Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"score_0 = model_efficientnet.evaluate(valid_data, verbose = 1)\nprint(f'Validation loss:{score_0[0]}\\n Validation accuracy:{score_0[1]}')","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:16:38.935169Z","iopub.execute_input":"2023-12-06T15:16:38.935488Z","iopub.status.idle":"2023-12-06T15:16:40.626043Z","shell.execute_reply.started":"2023-12-06T15:16:38.935460Z","shell.execute_reply":"2023-12-06T15:16:40.625075Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cm(y_true, y_preds_model_efficientnet)","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:16:40.627534Z","iopub.execute_input":"2023-12-06T15:16:40.627934Z","iopub.status.idle":"2023-12-06T15:16:40.877664Z","shell.execute_reply.started":"2023-12-06T15:16:40.627896Z","shell.execute_reply":"2023-12-06T15:16:40.876722Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_result(model_efficientnet_history.history)","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:16:40.878985Z","iopub.execute_input":"2023-12-06T15:16:40.880605Z","iopub.status.idle":"2023-12-06T15:16:41.178798Z","shell.execute_reply.started":"2023-12-06T15:16:40.880572Z","shell.execute_reply":"2023-12-06T15:16:41.177949Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Model-2. EffUnetB0 implementation","metadata":{}},{"cell_type":"code","source":"# Convolution, Batch Normalization, Activation then Residual Connection\ndef CBAR_block(input, num_filters):\n    x = layers.Conv2D(filters=num_filters, kernel_size=3, padding='same')(input)\n    x = layers.BatchNormalization()(x)\n    x = layers.Activation('relu')(x)\n\n    x = layers.Conv2D(filters=num_filters, kernel_size=3, padding='same')(x)\n    x = layers.BatchNormalization()(x)\n\n    xd = layers.Conv2D(filters=num_filters, kernel_size=1)(input)\n    x = layers.Add()([x, xd])\n\n    return x\n\n\ndef get_efficientnet(name='B0', input_shape=IMG_SHAPE+(3,)):\n    return EfficientNetB0(\n        include_top=False,\n        weights='imagenet',\n        input_tensor=None,\n        input_shape=input_shape,\n        pooling=None,\n    )\n\n\ndef efficientnet_unet(input_shape = IMG_SHAPE+(3,), num_classes=5):\n    encoder_model = get_efficientnet(name='B0', input_shape=input_shape)\n    new_input = encoder_model.input\n    # encoder output, we won't use the top_conv (which has 1280 filters)\n    # let's just use 7a bn, which is 7 x 7 x 320\n    encoder_output = encoder_model.get_layer(name='block7a_project_bn').output\n\n    # filter number for the bottleneck\n    fn_bottle_neck = encoder_output.shape[-1]\n    bottleneck = CBAR_block(encoder_output, fn_bottle_neck)\n    print(bottleneck.shape)\n    # Decoder block 1\n    c1 = encoder_model.get_layer(name='block5c_drop').output\n    fn_1 = c1.shape[-1]\n    upsampling1 = tf.keras.layers.UpSampling2D()(bottleneck)\n    print(upsampling1.shape)\n    print(c1.shape)\n    concatenation1 = tf.keras.layers.concatenate(\n            [upsampling1, c1], axis=3)\n    decoder1 = CBAR_block(concatenation1, fn_1)\n\n    # Decoder block 2\n    c2 = encoder_model.get_layer(name='block3b_drop').output\n    fn_2 = c2.shape[-1]\n    upsampling2 = tf.keras.layers.UpSampling2D()(decoder1)\n    print(upsampling2.shape)\n    print(c2.shape)\n    concatenation2 = tf.keras.layers.concatenate(\n            [upsampling2, c2], axis=3)\n    decoder2 = CBAR_block(concatenation2, fn_2)\n\n    # Decoder block 3\n    c3 = encoder_model.get_layer(name='block2b_drop').output\n    fn_3 = c3.shape[-1]\n    upsampling3 = tf.keras.layers.UpSampling2D()(decoder2)\n    print(upsampling3.shape)\n    print(c3.shape)\n    concatenation3 = tf.keras.layers.concatenate(\n            [upsampling3, c3], axis=3)\n    decoder3 = CBAR_block(concatenation3, fn_3)\n\n    # Decoder block 4\n    # 1a does not have dropout\n    c4 = encoder_model.get_layer(name='block1a_project_bn').output\n    fn_4 = c4.shape[-1]\n    upsampling4 = tf.keras.layers.UpSampling2D()(decoder3)\n    print(upsampling4.shape)\n    print(c4.shape)\n    concatenation4 = tf.keras.layers.concatenate(\n            [upsampling4, c4], axis=3)\n    decoder4 = CBAR_block(concatenation4, fn_4)\n\n    # Decoder block 5\n    # the only layer with original shape is input...\n    fn_5 = fn_4 # let's resuse this filter number for now\n    upsampling5 = tf.keras.layers.UpSampling2D()(decoder4)\n    print(upsampling5.shape)\n    print(new_input.shape)\n    concatenation5 = tf.keras.layers.concatenate(\n            [upsampling5, new_input], axis=3)\n    decoder5 = CBAR_block(concatenation5, fn_5)\n\n    # Now we can add in the output portion\n    final_activation = 'sigmoid'\n    new_output = layers.Conv2D(filters=5, kernel_size=1, activation=final_activation)(decoder5)\n    final_output = layers.GlobalAveragePooling2D()(new_output)\n\n    print(\"output shape\", new_output.shape)\n    \n    efficient_unet = tf.keras.Model(inputs=new_input, outputs=final_output)\n\n    return efficient_unet","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:16:41.179947Z","iopub.execute_input":"2023-12-06T15:16:41.180220Z","iopub.status.idle":"2023-12-06T15:16:41.202914Z","shell.execute_reply.started":"2023-12-06T15:16:41.180193Z","shell.execute_reply":"2023-12-06T15:16:41.202020Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_effUnet = efficientnet_unet(num_classes = 5)\nmodel_effUnet.compile(loss='binary_crossentropy',\n              optimizer=tf.keras.optimizers.Adam(learning_rate=1e-4),\n              metrics=['binary_accuracy'])\nmodel_effUnet.summary()\nmodel_effUnet.save('EU_Test.h5')","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2023-12-06T15:16:41.204045Z","iopub.execute_input":"2023-12-06T15:16:41.204405Z","iopub.status.idle":"2023-12-06T15:16:43.776889Z","shell.execute_reply.started":"2023-12-06T15:16:41.204377Z","shell.execute_reply":"2023-12-06T15:16:43.775853Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_effUnet_history = model_effUnet.fit(train_data,\n                                       validation_data=valid_data,\n                                       steps_per_epoch=int(train_data.n//train_data.batch_size),\n                                       epochs=30,\n                                       validation_steps=int(valid_data.n//valid_data.batch_size),\n                                       callbacks=[callback(patience=9, name=\"effUnet_061223\")])","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2023-12-06T15:16:43.778464Z","iopub.execute_input":"2023-12-06T15:16:43.778862Z","iopub.status.idle":"2023-12-06T15:19:51.405937Z","shell.execute_reply.started":"2023-12-06T15:16:43.778820Z","shell.execute_reply":"2023-12-06T15:19:51.404899Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_preds_model_effUNet = make_predictions(model_effUnet)\nscore_1 = model_effUnet.evaluate(valid_data, verbose = 1)\nprint(f'Validation loss:{score_1[0]}\\n Validation accuracy:{score_1[1]}')\ny_true = valid_data.classes\n# Metrics for effUNet\nmetrics(y_true, y_preds_model_effUNet)","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:19:51.409493Z","iopub.execute_input":"2023-12-06T15:19:51.409810Z","iopub.status.idle":"2023-12-06T15:19:56.604391Z","shell.execute_reply.started":"2023-12-06T15:19:51.409781Z","shell.execute_reply":"2023-12-06T15:19:56.603450Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cm(y_true, y_preds_model_effUNet)","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:19:56.605817Z","iopub.execute_input":"2023-12-06T15:19:56.606473Z","iopub.status.idle":"2023-12-06T15:19:56.922879Z","shell.execute_reply.started":"2023-12-06T15:19:56.606434Z","shell.execute_reply":"2023-12-06T15:19:56.921877Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_result(model_effUnet_history.history)","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:19:56.924357Z","iopub.execute_input":"2023-12-06T15:19:56.924678Z","iopub.status.idle":"2023-12-06T15:19:57.252970Z","shell.execute_reply.started":"2023-12-06T15:19:56.924647Z","shell.execute_reply":"2023-12-06T15:19:57.252028Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Model-3. EfficientNetB7","metadata":{}},{"cell_type":"code","source":"# Basic architecture of DenseNet\nbase_model_efficientnet_b7=EfficientNetB7(include_top=False, input_shape=IMG_SHAPE+(3,)) \nmodel_efficientnet_b7=Sequential()\nmodel_efficientnet_b7.add(base_model_efficientnet_b7)\nmodel_efficientnet_b7.add(layers.GlobalAveragePooling2D())\nmodel_efficientnet_b7.add(layers.Dropout(0.2))\nmodel_efficientnet_b7.add(layers.Dense(5, activation='sigmoid'))\n# Summary of the denseNet model\nmodel_efficientnet_b7.summary()","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:19:57.254387Z","iopub.execute_input":"2023-12-06T15:19:57.254760Z","iopub.status.idle":"2023-12-06T15:20:06.065681Z","shell.execute_reply.started":"2023-12-06T15:19:57.254720Z","shell.execute_reply":"2023-12-06T15:20:06.064690Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_efficientnet_b7.compile(loss='binary_crossentropy',\n                  optimizer=tf.keras.optimizers.Adam(learning_rate=0.0001),\n                  metrics=['binary_accuracy'])\n\nmodel_efficientnet_b7_history = model_efficientnet_b7.fit(train_data,\n                                                   validation_data=valid_data,\n                                                   steps_per_epoch=int(train_data.n//train_data.batch_size),\n                                                   epochs=50,\n                                                   validation_steps=int(valid_data.n//valid_data.batch_size),\n                                                   callbacks=[callback(patience=9, name=\"efficientnetb7_061223\")])","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2023-12-06T15:20:06.067127Z","iopub.execute_input":"2023-12-06T15:20:06.067541Z","iopub.status.idle":"2023-12-06T15:26:50.513821Z","shell.execute_reply.started":"2023-12-06T15:20:06.067502Z","shell.execute_reply":"2023-12-06T15:26:50.512752Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_preds_model_efficientnet_b7 = make_predictions(model_efficientnet_b7)\nscore_2 = model_efficientnet_b7.evaluate(valid_data, verbose = 1)\nprint(f'Validation loss:{score_2[0]}\\n Validation accuracy:{score_2[1]}')\ny_true = valid_data.classes\n# Metrics for effUNet\nmetrics(y_true, y_preds_model_efficientnet_b7)","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:26:50.515096Z","iopub.execute_input":"2023-12-06T15:26:50.515416Z","iopub.status.idle":"2023-12-06T15:26:58.562991Z","shell.execute_reply.started":"2023-12-06T15:26:50.515388Z","shell.execute_reply":"2023-12-06T15:26:58.561959Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cm(y_true, y_preds_model_efficientnet_b7)","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:26:58.564453Z","iopub.execute_input":"2023-12-06T15:26:58.564848Z","iopub.status.idle":"2023-12-06T15:26:58.876850Z","shell.execute_reply.started":"2023-12-06T15:26:58.564793Z","shell.execute_reply":"2023-12-06T15:26:58.875903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_result(model_efficientnet_b7_history.history)","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:26:58.878035Z","iopub.execute_input":"2023-12-06T15:26:58.878353Z","iopub.status.idle":"2023-12-06T15:26:59.196596Z","shell.execute_reply.started":"2023-12-06T15:26:58.878325Z","shell.execute_reply":"2023-12-06T15:26:59.195706Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Model-4. EffUnetB7 implementation","metadata":{}},{"cell_type":"code","source":"# Convolution, Batch Normalization, Activation then Residual Connection\ndef CBAR_block(input, num_filters):\n    x = layers.Conv2D(filters=num_filters, kernel_size=3, padding='same')(input)\n    x = layers.BatchNormalization()(x)\n    x = layers.Activation('relu')(x)\n\n#     x = layers.Conv2D(filters=num_filters, kernel_size=3, padding='same')(x)\n#     x = layers.BatchNormalization()(x)\n\n    xd = layers.Conv2D(filters=num_filters, kernel_size=1)(input)\n    x = layers.Add()([x, xd])\n\n    return x\n\n\ndef get_efficientnet(name='B7', input_shape=IMG_SHAPE+(3,)):\n    return EfficientNetB7(\n        include_top=False,\n        weights='imagenet',\n        input_tensor=None,\n        input_shape=input_shape,\n        pooling=None,\n    )\n\n\ndef efficientnet_unet(input_shape = IMG_SHAPE+(3,), num_classes=5):\n    encoder_model = get_efficientnet(name='B7', input_shape=input_shape)\n    new_input = encoder_model.input\n    # encoder output, we won't use the top_conv (which has 1280 filters)\n    # let's just use 7a bn, which is 7 x 7 x 320 // 16X16X640\n    encoder_output = encoder_model.get_layer(name='block7d_drop').output\n\n    # filter number for the bottleneck\n    fn_bottle_neck = encoder_output.shape[-1]\n    \n    bottleneck = CBAR_block(encoder_output, fn_bottle_neck)\n    # Decoder block 1\n    c1 = encoder_model.get_layer(name='block6a_expand_activation').output\n    fn_1 = c1.shape[-1]\n    upsampling1 = tf.keras.layers.UpSampling2D()(bottleneck)\n    concatenation1 = tf.keras.layers.concatenate(\n            [upsampling1, c1], axis=3)\n    decoder1 = CBAR_block(concatenation1, fn_1)\n\n    # Decoder block 2\n    c2 = encoder_model.get_layer(name='block4a_expand_activation').output\n    fn_2 = c2.shape[-1]\n    upsampling2 = tf.keras.layers.UpSampling2D()(decoder1)\n    concatenation2 = tf.keras.layers.concatenate(\n            [upsampling2, c2], axis=3)\n    decoder2 = CBAR_block(concatenation2, fn_2)\n\n    # Decoder block 3\n    c3 = encoder_model.get_layer(name='block3a_expand_activation').output\n    fn_3 = c3.shape[-1]\n    upsampling3 = tf.keras.layers.UpSampling2D()(decoder2)\n    concatenation3 = tf.keras.layers.concatenate(\n            [upsampling3, c3], axis=3)\n    decoder3 = CBAR_block(concatenation3, fn_3)\n\n    # Decoder block 4\n    # 1a does not have dropout\n    c4 = encoder_model.get_layer(name='block2a_expand_activation').output\n    fn_4 = c4.shape[-1]\n    upsampling4 = tf.keras.layers.UpSampling2D()(decoder3)\n    concatenation4 = tf.keras.layers.concatenate(\n            [upsampling4, c4], axis=3)\n    decoder4 = CBAR_block(concatenation4, fn_4)\n\n    # Decoder block 5\n    # the only layer with original shape is input...\n    fn_5 = fn_4 # let's resuse this filter number for now\n    upsampling5 = tf.keras.layers.UpSampling2D()(decoder4)\n    concatenation5 = tf.keras.layers.concatenate(\n            [upsampling5, new_input], axis=3)\n    decoder5 = CBAR_block(concatenation5, fn_5)\n\n    final_filter_num = num_classes\n    final_activation = 'sigmoid'\n    new_output = layers.Conv2D(filters=final_filter_num, kernel_size=1, activation=final_activation)(decoder5)\n    final_output = layers.GlobalAveragePooling2D()(new_output)\n    \n    efficient_unet = tf.keras.Model(inputs=new_input, outputs=final_output)\n\n    return efficient_unet","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:26:59.198099Z","iopub.execute_input":"2023-12-06T15:26:59.198487Z","iopub.status.idle":"2023-12-06T15:26:59.218233Z","shell.execute_reply.started":"2023-12-06T15:26:59.198450Z","shell.execute_reply":"2023-12-06T15:26:59.217275Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_effUnet_b7 = efficientnet_unet(num_classes = 5)\nmodel_effUnet_b7.compile(loss='binary_crossentropy',\n              optimizer=tf.keras.optimizers.Adam(learning_rate=0.0001),\n              metrics=['binary_accuracy'])\nmodel_effUnet_b7.summary()\nmodel_effUnet_b7.save('EU_Test_b7.h5')","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2023-12-06T15:26:59.219475Z","iopub.execute_input":"2023-12-06T15:26:59.219761Z","iopub.status.idle":"2023-12-06T15:27:07.892075Z","shell.execute_reply.started":"2023-12-06T15:26:59.219734Z","shell.execute_reply":"2023-12-06T15:27:07.891235Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_effUnet_b7_history = model_effUnet_b7.fit(train_data,\n                                       validation_data=valid_data,\n                                       steps_per_epoch=int(train_data.n//train_data.batch_size),\n                                       epochs=50,\n                                       validation_steps=int(valid_data.n//valid_data.batch_size),\n                                       callbacks=[callback(patience=9, name=\"effB7Unet_061223\")])","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2023-12-06T15:27:07.898282Z","iopub.execute_input":"2023-12-06T15:27:07.898578Z","iopub.status.idle":"2023-12-06T15:40:19.879332Z","shell.execute_reply.started":"2023-12-06T15:27:07.898551Z","shell.execute_reply":"2023-12-06T15:40:19.878438Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_preds_model_effUNet_b7 = make_predictions(model_effUnet_b7)\nscore_3 = model_effUnet_b7.evaluate(valid_data, verbose = 1)\nprint(f'Validation loss:{score_3[0]}\\n Validation accuracy:{score_3[1]}')\ny_true = valid_data.classes\n# Metrics for effUNet\nmetrics(y_true, y_preds_model_effUNet_b7)","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:40:19.880859Z","iopub.execute_input":"2023-12-06T15:40:19.881219Z","iopub.status.idle":"2023-12-06T15:40:28.331787Z","shell.execute_reply.started":"2023-12-06T15:40:19.881188Z","shell.execute_reply":"2023-12-06T15:40:28.330886Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.unique(y_true, return_counts=True), len(y_true)","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:43:59.376022Z","iopub.execute_input":"2023-12-06T15:43:59.377045Z","iopub.status.idle":"2023-12-06T15:43:59.385426Z","shell.execute_reply.started":"2023-12-06T15:43:59.376996Z","shell.execute_reply":"2023-12-06T15:43:59.384329Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cm(y_true, y_preds_model_effUNet_b7)","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:40:28.332823Z","iopub.execute_input":"2023-12-06T15:40:28.333111Z","iopub.status.idle":"2023-12-06T15:40:28.595687Z","shell.execute_reply.started":"2023-12-06T15:40:28.333083Z","shell.execute_reply":"2023-12-06T15:40:28.594719Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_result(model_effUnet_b7_history.history)","metadata":{"execution":{"iopub.status.busy":"2023-12-06T15:40:28.596767Z","iopub.execute_input":"2023-12-06T15:40:28.597044Z","iopub.status.idle":"2023-12-06T15:40:28.953118Z","shell.execute_reply.started":"2023-12-06T15:40:28.597017Z","shell.execute_reply":"2023-12-06T15:40:28.952126Z"},"trusted":true},"execution_count":null,"outputs":[]}]}