{"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":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom matplotlib import cm\nimport seaborn as sns\n\nimport random\nimport os\nimport gc  # garbage collector\nimport datetime\nfrom tqdm import tqdm\n\nimport cv2\nfrom sklearn.preprocessing import StandardScaler as scale \nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import accuracy_score, confusion_matrix, f1_score\n\nimport tensorflow as tf\nfrom tensorflow.keras.models import Model\nfrom tensorflow.keras.layers import Input, Conv2D, Dense, Flatten, MaxPooling2D, BatchNormalization, Dropout, GlobalAveragePooling2D\nfrom tensorflow.keras.callbacks import EarlyStopping, CSVLogger, ModelCheckpoint, TensorBoard\nfrom tensorflow.keras.preprocessing import image_dataset_from_directory\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\nfrom tensorflow.keras.applications import NASNetLarge","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-04-09T15:20:21.992631Z","iopub.execute_input":"2023-04-09T15:20:21.993037Z","iopub.status.idle":"2023-04-09T15:20:32.867602Z","shell.execute_reply.started":"2023-04-09T15:20:21.993004Z","shell.execute_reply":"2023-04-09T15:20:32.866751Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"resized_train_path =\"/kaggle/input/diabetic-retinopathy-resized/resized_train/resized_train\"\ntrain_labels_path = \"/kaggle/input/diabetic-retinopathy-resized/trainLabels.csv\"\ntrain_labels_cropped_path = \"/kaggle/input/diabetic-retinopathy-resized/trainLabels_cropped.csv\"","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:20:32.869230Z","iopub.execute_input":"2023-04-09T15:20:32.869798Z","iopub.status.idle":"2023-04-09T15:20:32.874898Z","shell.execute_reply.started":"2023-04-09T15:20:32.869752Z","shell.execute_reply":"2023-04-09T15:20:32.873566Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_labels = pd.read_csv(train_labels_path)\ntrain_labels.head()","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:20:32.876446Z","iopub.execute_input":"2023-04-09T15:20:32.877403Z","iopub.status.idle":"2023-04-09T15:20:32.940455Z","shell.execute_reply.started":"2023-04-09T15:20:32.877357Z","shell.execute_reply":"2023-04-09T15:20:32.939381Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_labels.info()","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:20:32.943367Z","iopub.execute_input":"2023-04-09T15:20:32.943936Z","iopub.status.idle":"2023-04-09T15:20:32.972541Z","shell.execute_reply.started":"2023-04-09T15:20:32.943907Z","shell.execute_reply":"2023-04-09T15:20:32.971272Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"level_cropped_col = train_labels['level']\nlevel_cropped_col","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:20:32.974111Z","iopub.execute_input":"2023-04-09T15:20:32.974421Z","iopub.status.idle":"2023-04-09T15:20:32.983309Z","shell.execute_reply.started":"2023-04-09T15:20:32.974390Z","shell.execute_reply":"2023-04-09T15:20:32.982050Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"level_cropped_col.plot(kind='hist', figsize=(10, 5), cmap=cm.get_cmap('flag'))","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:20:32.985157Z","iopub.execute_input":"2023-04-09T15:20:32.985627Z","iopub.status.idle":"2023-04-09T15:20:33.254927Z","shell.execute_reply.started":"2023-04-09T15:20:32.985586Z","shell.execute_reply":"2023-04-09T15:20:33.253844Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_labels_cropped = pd.read_csv(train_labels_cropped_path)\ntrain_labels_cropped","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:20:33.256140Z","iopub.execute_input":"2023-04-09T15:20:33.256449Z","iopub.status.idle":"2023-04-09T15:20:33.316022Z","shell.execute_reply.started":"2023-04-09T15:20:33.256419Z","shell.execute_reply":"2023-04-09T15:20:33.314571Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"level_cropped_col = train_labels_cropped['level']\nlevel_cropped_col","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:20:33.317575Z","iopub.execute_input":"2023-04-09T15:20:33.318107Z","iopub.status.idle":"2023-04-09T15:20:33.329117Z","shell.execute_reply.started":"2023-04-09T15:20:33.318060Z","shell.execute_reply":"2023-04-09T15:20:33.327751Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"level_cropped_col.plot(kind='hist', figsize=(10, 5), cmap=cm.get_cmap('ocean'))","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:20:33.330129Z","iopub.execute_input":"2023-04-09T15:20:33.330461Z","iopub.status.idle":"2023-04-09T15:20:33.530023Z","shell.execute_reply.started":"2023-04-09T15:20:33.330426Z","shell.execute_reply":"2023-04-09T15:20:33.529245Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"resized_train_list = os.listdir(resized_train_path)\nlen(resized_train_list)","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:20:33.533151Z","iopub.execute_input":"2023-04-09T15:20:33.533923Z","iopub.status.idle":"2023-04-09T15:20:34.068954Z","shell.execute_reply.started":"2023-04-09T15:20:33.533881Z","shell.execute_reply":"2023-04-09T15:20:34.067745Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(25, 20))\nfor i in range(1, 26):\n    plt.subplot(5, 5, i)\n    img_name = random.choice(resized_train_list)\n    img_path = os.path.join(resized_train_path, img_name)\n    img = cv2.imread(img_path)\n    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n    plt.imshow(img)\n    plt.xlabel(img.shape[1])\n    plt.ylabel(img.shape[0])","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:20:34.070138Z","iopub.execute_input":"2023-04-09T15:20:34.070455Z","iopub.status.idle":"2023-04-09T15:20:41.390509Z","shell.execute_reply.started":"2023-04-09T15:20:34.070427Z","shell.execute_reply":"2023-04-09T15:20:41.389055Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"resized_train_cropped_path ='/kaggle/input/diabetic-retinopathy-resized/resized_train_cropped/resized_train_cropped/'","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:20:41.391895Z","iopub.execute_input":"2023-04-09T15:20:41.392520Z","iopub.status.idle":"2023-04-09T15:20:41.397209Z","shell.execute_reply.started":"2023-04-09T15:20:41.392488Z","shell.execute_reply":"2023-04-09T15:20:41.396333Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"resized_train_cropped_list = os.listdir(resized_train_cropped_path)\nlen(resized_train_cropped_list)","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:20:41.398594Z","iopub.execute_input":"2023-04-09T15:20:41.399146Z","iopub.status.idle":"2023-04-09T15:20:43.195143Z","shell.execute_reply.started":"2023-04-09T15:20:41.399115Z","shell.execute_reply":"2023-04-09T15:20:43.193893Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(26, 24))\nfor i in range(1, 26):\n    plt.subplot(5, 5, i)\n    img_name = random.choice(resized_train_cropped_list)\n    img_path = os.path.join(resized_train_cropped_path, img_name)\n    img = cv2.imread(img_path)\n    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n    plt.imshow(img)\n    plt.xlabel(img.shape[1])\n    plt.ylabel(img.shape[0])","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:20:43.197428Z","iopub.execute_input":"2023-04-09T15:20:43.197844Z","iopub.status.idle":"2023-04-09T15:20:52.262671Z","shell.execute_reply.started":"2023-04-09T15:20:43.197804Z","shell.execute_reply":"2023-04-09T15:20:52.261244Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(20, 25))\nfor i in range(1, 16):\n    plt.subplot(5, 3, i)\n    plt.tight_layout()\n    plt.title(\"Color Histogram\")\n    plt.xlabel(\"Intensity Value\")\n    plt.ylabel(\"Number of Pixels\")\n    img_name = random.choice(resized_train_cropped_list)\n    img_path = os.path.join(resized_train_cropped_path, img_name)\n    img = cv2.imread(img_path)\n    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n    \n    channels = cv2.split(img)\n    colors = ['r', 'g', 'b']\n    for (channel, color) in zip(channels, colors):\n        hist = cv2.calcHist([channel], [0], None, [256], [0, 256])\n        plt.plot(hist, color=color)\n        plt.xlim([0, 256])","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:20:52.264670Z","iopub.execute_input":"2023-04-09T15:20:52.265668Z","iopub.status.idle":"2023-04-09T15:20:55.891265Z","shell.execute_reply.started":"2023-04-09T15:20:52.265628Z","shell.execute_reply":"2023-04-09T15:20:55.890441Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_width = 100\nimg_height = 100\n\ndef read_img(img_name, resize=False):\n    img_path = os.path.join(resized_train_cropped_path, img_name)\n    img = cv2.imread(img_path)\n    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n    \n    if resize:\n        img = cv2.resize(img, (img_width, img_hight))\n    \n    return img","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:20:55.892324Z","iopub.execute_input":"2023-04-09T15:20:55.892943Z","iopub.status.idle":"2023-04-09T15:20:55.900308Z","shell.execute_reply.started":"2023-04-09T15:20:55.892907Z","shell.execute_reply":"2023-04-09T15:20:55.897967Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def ben_graham(img):\n    img_ben = cv2.addWeighted(img, 4, cv2.GaussianBlur(img, (0, 0), 10), -4, 128)\n    return img_ben","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:20:55.902654Z","iopub.execute_input":"2023-04-09T15:20:55.903466Z","iopub.status.idle":"2023-04-09T15:20:55.923290Z","shell.execute_reply.started":"2023-04-09T15:20:55.903421Z","shell.execute_reply":"2023-04-09T15:20:55.922176Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def hist_equalization(img):\n    red, green, blue = cv2.split(img)\n    hist_red = cv2.equalizeHist(red)\n    hist_green = cv2.equalizeHist(green)\n    hist_blue = cv2.equalizeHist(blue)\n    \n    img_eq = cv2.merge((hist_red, hist_green, hist_blue))\n    \n    return img_eq","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:20:55.924545Z","iopub.execute_input":"2023-04-09T15:20:55.924919Z","iopub.status.idle":"2023-04-09T15:20:55.936426Z","shell.execute_reply.started":"2023-04-09T15:20:55.924885Z","shell.execute_reply":"2023-04-09T15:20:55.934762Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"equal_hist_images = resized_train_cropped_list.copy()\nlen(equal_hist_images)","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:20:55.937929Z","iopub.execute_input":"2023-04-09T15:20:55.938281Z","iopub.status.idle":"2023-04-09T15:20:55.956335Z","shell.execute_reply.started":"2023-04-09T15:20:55.938252Z","shell.execute_reply":"2023-04-09T15:20:55.954969Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(26, 24))\ncounter = 0\nfor img_name in equal_hist_images:\n    counter += 1\n    plt.subplot(5, 5, counter)\n    plt.tight_layout()\n    # level_cropped_col is the labels, we've created it above\n    plt.title(level_cropped_col[counter - 1])\n    \n    img = read_img(img_name)\n    \n    # Applying the Histogram Equaliztion\n    img_eq = hist_equalization(img)\n    plt.imshow(img_eq)\n    plt.xlabel(img_eq.shape[1])\n    plt.xlabel(img_eq.shape[0])\n    \n    if counter == 25:\n        break","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:20:55.957545Z","iopub.execute_input":"2023-04-09T15:20:55.957932Z","iopub.status.idle":"2023-04-09T15:21:09.285259Z","shell.execute_reply.started":"2023-04-09T15:20:55.957896Z","shell.execute_reply":"2023-04-09T15:21:09.284282Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(20, 25))\ncounter = 0\nfor img_name in equal_hist_images:\n    counter += 1\n    plt.subplot(5, 3, counter)\n    plt.tight_layout()\n    \n    img = read_img(img_name)\n    \n    # Applying the Histogram Equaliztion\n    img_eq = hist_equalization(img)\n    \n    channels = cv2.split(img_eq)\n    colors = ['r', 'g', 'b']\n    \n    for (channel, color) in zip(channels, colors):\n        hist = cv2.calcHist([channel], [0], None, [256], [0, 256])\n        plt.plot(hist, color=color)\n        plt.xlim([0, 256])\n    \n    if counter == 15:\n        break","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:21:09.286486Z","iopub.execute_input":"2023-04-09T15:21:09.286996Z","iopub.status.idle":"2023-04-09T15:21:12.942368Z","shell.execute_reply.started":"2023-04-09T15:21:09.286961Z","shell.execute_reply":"2023-04-09T15:21:12.941148Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ben_images = resized_train_cropped_list.copy()\nlen(ben_images)","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:21:12.943886Z","iopub.execute_input":"2023-04-09T15:21:12.944150Z","iopub.status.idle":"2023-04-09T15:21:12.949991Z","shell.execute_reply.started":"2023-04-09T15:21:12.944124Z","shell.execute_reply":"2023-04-09T15:21:12.949049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(26, 24))\ncounter = 0\nfor img_name in ben_images:\n    counter += 1\n    plt.subplot(5, 5, counter)\n    plt.tight_layout()\n    # level_cropped_col is the lebels list\n    plt.title(level_cropped_col[counter - 1])\n    \n    img = read_img(img_name)\n    \n    # Applying Ben Graham's Method\n    img_ben = ben_graham(img)\n    \n    plt.imshow(img_ben)\n    plt.xlabel(img_ben.shape[1])\n    plt.ylabel(img_ben.shape[0])\n    \n    if counter == 25:\n        break","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:21:12.951076Z","iopub.execute_input":"2023-04-09T15:21:12.951320Z","iopub.status.idle":"2023-04-09T15:21:26.248095Z","shell.execute_reply.started":"2023-04-09T15:21:12.951295Z","shell.execute_reply":"2023-04-09T15:21:26.246539Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(20, 25))\ncounter = 0\nfor img_name in equal_hist_images:\n    counter += 1\n    plt.subplot(5, 3, counter)\n    plt.tight_layout()\n    \n    img = read_img(img_name)\n    \n    # Applying Ben Graham's Method\n    img_ben = ben_graham(img)\n    \n    channels = cv2.split(img_ben)\n    colors = ['r', 'g', 'b']\n    \n    for (channel, color) in zip(channels, colors):\n        hist = cv2.calcHist([channel], [0], None, [256], [0, 256])\n        plt.plot(hist, color=color)\n        plt.xlim([0, 256])\n    \n    if counter == 15:\n        break","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:21:26.249966Z","iopub.execute_input":"2023-04-09T15:21:26.250327Z","iopub.status.idle":"2023-04-09T15:21:30.517140Z","shell.execute_reply.started":"2023-04-09T15:21:26.250294Z","shell.execute_reply":"2023-04-09T15:21:30.516341Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_labels_cropped.head()","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:21:30.518272Z","iopub.execute_input":"2023-04-09T15:21:30.519088Z","iopub.status.idle":"2023-04-09T15:21:30.530740Z","shell.execute_reply.started":"2023-04-09T15:21:30.519023Z","shell.execute_reply":"2023-04-09T15:21:30.529243Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_labels_cropped['image_name'] = [img + '.jpeg' for img in train_labels_cropped['image']]\ntrain_labels_cropped.head()","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:21:30.532987Z","iopub.execute_input":"2023-04-09T15:21:30.533333Z","iopub.status.idle":"2023-04-09T15:21:30.559116Z","shell.execute_reply.started":"2023-04-09T15:21:30.533301Z","shell.execute_reply":"2023-04-09T15:21:30.557796Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_ds, val_ds = train_test_split(train_labels_cropped, test_size=0.5)\ntrain_ds.shape, val_ds.shape","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:21:30.560724Z","iopub.execute_input":"2023-04-09T15:21:30.561090Z","iopub.status.idle":"2023-04-09T15:21:30.579863Z","shell.execute_reply.started":"2023-04-09T15:21:30.561057Z","shell.execute_reply":"2023-04-09T15:21:30.578622Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def my_processes(img):\n    img = cv2.resize(img, (img_width, img_height))\n    \n    # Apply your image processing method\n    img = ben_graham(img)\n    \n    return img","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:21:30.585472Z","iopub.execute_input":"2023-04-09T15:21:30.585974Z","iopub.status.idle":"2023-04-09T15:21:30.592401Z","shell.execute_reply.started":"2023-04-09T15:21:30.585927Z","shell.execute_reply":"2023-04-09T15:21:30.590961Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_datagen = ImageDataGenerator(rescale = 1./255.,\n                                  rotation_range = 40,\n                                  width_shift_range = 0.5,\n                                  height_shift_range = 0.5,\n                                  shear_range = 0.5,\n                                  horizontal_flip = True,\n                                  preprocessing_function=ben_graham)","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:21:30.593874Z","iopub.execute_input":"2023-04-09T15:21:30.594273Z","iopub.status.idle":"2023-04-09T15:21:30.602501Z","shell.execute_reply.started":"2023-04-09T15:21:30.594238Z","shell.execute_reply":"2023-04-09T15:21:30.601455Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_datagen = ImageDataGenerator(rescale = 1./255.)","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:21:30.603620Z","iopub.execute_input":"2023-04-09T15:21:30.604621Z","iopub.status.idle":"2023-04-09T15:21:30.613692Z","shell.execute_reply.started":"2023-04-09T15:21:30.604592Z","shell.execute_reply":"2023-04-09T15:21:30.612506Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"batch_size = 32\n\ntrain_dataset = train_datagen.flow_from_dataframe(train_ds,\n                                                 resized_train_cropped_path,\n                                                 x_col=\"image_name\",\n                                                 y_col=\"level\",\n                                                 class_mode='raw',\n                                                 batch_size=batch_size,\n                                                 target_size=(img_width, img_height))\nval_dataset = val_datagen.flow_from_dataframe(val_ds,\n                                             resized_train_cropped_path,\n                                             x_col='image_name',\n                                             y_col='level',\n                                             class_mode='raw',\n                                             batch_size=batch_size,\n                                             target_size=(img_width, img_height))","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:21:30.614893Z","iopub.execute_input":"2023-04-09T15:21:30.615199Z","iopub.status.idle":"2023-04-09T15:23:26.681330Z","shell.execute_reply.started":"2023-04-09T15:21:30.615167Z","shell.execute_reply":"2023-04-09T15:23:26.680476Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = tf.keras.applications.nasnet.NASNetLarge(\n    input_shape=None,\n    include_top=True,\n    weights='imagenet',\n    input_tensor=None,\n    pooling=None,\n    classes=1000,\n    classifier_activation='softmax'\n)","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:23:26.682349Z","iopub.execute_input":"2023-04-09T15:23:26.684131Z","iopub.status.idle":"2023-04-09T15:23:49.624200Z","shell.execute_reply.started":"2023-04-09T15:23:26.684090Z","shell.execute_reply":"2023-04-09T15:23:49.623118Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x = Dropout(0.2)(model.output)\nx = Dropout(0.5)(x)\n\nx = Dense(2048, activation='relu')(x)\nx = Dense(2048, activation='relu')(x)\nx = Dropout(0.5)(x)\nx = Dropout(0.5)(model.output)\n\nx = Dense(1024, activation='relu')(x)\nx = Dense(1024, activation='relu')(x)\nx = Dropout(0.5)(x)\n\nx = Dense(1024, activation='relu')(x)\nx = Dropout(0.1)(x)\n\nx = Dense(1024, activation='relu')(x)\nx = Dropout(0.1)(x)\nx = Dense(512, activation='relu')(x)\nx = Dense(512, activation='relu')(x)\nx = Dropout(0.2)(x)\n\nx = Dense(512, activation='relu')(x)\nx = Dropout(0.1)(x)\n\nx = Dense(512, activation='relu')(x)\nx = Dropout(0.1)(x)\n\n\n#x = GlobalAveragePooling2D()(x)\n#x = Dropout(0.1)(x)\nclassifier = Dense(5, activation='softmax')(x)\nx = Dense(512, activation='relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(512, activation='relu')(x)\nx = Dropout(0.1)(x)\n\nx = Dense(512, activation='relu')(x)\nx = Dense(512, activation='relu')(x)\nx = Dropout(0.2)(x)\n\nx = Dense(512, activation='relu')(x)\nx = Dropout(0.1)(x)\n\nx = Dense(512, activation='relu')(x)\nclassifier = Dropout(0.1)(x)\n\n\nmodel = Model(inputs = model.input, outputs=classifier)","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:32:44.771162Z","iopub.execute_input":"2023-04-09T15:32:44.772371Z","iopub.status.idle":"2023-04-09T15:32:45.082447Z","shell.execute_reply.started":"2023-04-09T15:32:44.772311Z","shell.execute_reply":"2023-04-09T15:32:45.081032Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(optimizer=tf.keras.optimizers.Adam(), loss='sparse_categorical_crossentropy', metrics=['sparse_categorical_accuracy'])","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:23:49.966563Z","iopub.execute_input":"2023-04-09T15:23:49.966913Z","iopub.status.idle":"2023-04-09T15:23:50.008359Z","shell.execute_reply.started":"2023-04-09T15:23:49.966875Z","shell.execute_reply":"2023-04-09T15:23:50.007134Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"metrics=['sparse_categorical_accuracy']","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:23:50.010824Z","iopub.execute_input":"2023-04-09T15:23:50.011755Z","iopub.status.idle":"2023-04-09T15:23:50.017276Z","shell.execute_reply.started":"2023-04-09T15:23:50.011716Z","shell.execute_reply":"2023-04-09T15:23:50.015741Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_ds","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:23:50.019161Z","iopub.execute_input":"2023-04-09T15:23:50.019530Z","iopub.status.idle":"2023-04-09T15:23:50.042066Z","shell.execute_reply.started":"2023-04-09T15:23:50.019501Z","shell.execute_reply":"2023-04-09T15:23:50.040818Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"c = train_ds.iloc[:,3]","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:23:50.043470Z","iopub.execute_input":"2023-04-09T15:23:50.043958Z","iopub.status.idle":"2023-04-09T15:23:50.053495Z","shell.execute_reply.started":"2023-04-09T15:23:50.043923Z","shell.execute_reply":"2023-04-09T15:23:50.052092Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"r = val_ds.loc[:,\"level\"]","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:23:50.055153Z","iopub.execute_input":"2023-04-09T15:23:50.056185Z","iopub.status.idle":"2023-04-09T15:23:50.065456Z","shell.execute_reply.started":"2023-04-09T15:23:50.056141Z","shell.execute_reply":"2023-04-09T15:23:50.064357Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tf.math.confusion_matrix(\n    train_ds.level,\n    val_ds.level,\n    num_classes=None,\n    weights=None,\n    dtype=tf.dtypes.int32,\n    name=None\n)","metadata":{"execution":{"iopub.status.busy":"2023-04-09T15:32:49.951090Z","iopub.execute_input":"2023-04-09T15:32:49.951453Z","iopub.status.idle":"2023-04-09T15:32:49.962172Z","shell.execute_reply.started":"2023-04-09T15:32:49.951423Z","shell.execute_reply":"2023-04-09T15:32:49.961035Z"},"trusted":true},"execution_count":null,"outputs":[]}]}