{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\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","execution":{"iopub.status.busy":"2023-03-07T08:30:17.602122Z","iopub.execute_input":"2023-03-07T08:30:17.602592Z","iopub.status.idle":"2023-03-07T08:30:18.659913Z","shell.execute_reply.started":"2023-03-07T08:30:17.602532Z","shell.execute_reply":"2023-03-07T08:30:18.658888Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import zipfile\nimport os\nimport PIL\nimport glob\nimport pandas as pd\nimport numpy as np\nimport tensorflow as tf\nfrom tensorflow.keras.optimizers import RMSprop\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\nfrom tensorflow.keras.preprocessing import image\nimport keras.utils as image\nfrom PIL import Image, ImageOps\nfrom sklearn.model_selection import train_test_split\n\n\nfrom sklearn.metrics import confusion_matrix\nimport seaborn as sn; sn.set(font_scale=1.4)\nfrom sklearn.utils import shuffle                   \nfrom tqdm import tqdm\n\nfrom keras.applications.vgg16 import decode_predictions\nfrom keras.applications.vgg16 import preprocess_input\nfrom keras.preprocessing import image\nfrom IPython.display import Image, display\n\nimport cv2\nimport matplotlib.pyplot as plt\nimport matplotlib.image as mpimg\n%matplotlib inline","metadata":{"execution":{"iopub.status.busy":"2023-03-07T08:30:18.662009Z","iopub.execute_input":"2023-03-07T08:30:18.662672Z","iopub.status.idle":"2023-03-07T08:30:18.678631Z","shell.execute_reply.started":"2023-03-07T08:30:18.662633Z","shell.execute_reply":"2023-03-07T08:30:18.677012Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import json\nimport math\nimport os\n\nimport cv2\nfrom PIL import Image\nimport numpy as np\nfrom tensorflow.keras import layers\nfrom tensorflow.keras.applications import DenseNet121\nfrom tensorflow.keras.callbacks import Callback, ModelCheckpoint\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.optimizers import Adam\nimport matplotlib.pyplot as plt\nimport pandas as pd\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import cohen_kappa_score, accuracy_score\nimport scipy\nimport tensorflow as tf\nfrom tensorflow.keras.callbacks import EarlyStopping,ReduceLROnPlateau,LearningRateScheduler\nfrom tqdm import tqdm_notebook as tqdm\n\nimport timeit\n\ndevice_name = tf.test.gpu_device_name()\nprint(device_name)\n\n%matplotlib inline","metadata":{"execution":{"iopub.status.busy":"2023-03-07T08:30:18.680267Z","iopub.execute_input":"2023-03-07T08:30:18.680693Z","iopub.status.idle":"2023-03-07T08:30:18.696676Z","shell.execute_reply.started":"2023-03-07T08:30:18.680656Z","shell.execute_reply":"2023-03-07T08:30:18.694946Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"datasetsIMG_path = '../input/aptos2019-blindness-detection/train_images/'\ndataset_dir = pd.read_csv('../input/aptos2019-blindness-detection/train.csv', dtype='str')\ndataset_dir['image_dir'] = datasetsIMG_path + dataset_dir[\"id_code\"] + \".png\" \ndataset_dir.head()","metadata":{"execution":{"iopub.status.busy":"2023-03-07T08:30:18.698856Z","iopub.execute_input":"2023-03-07T08:30:18.699405Z","iopub.status.idle":"2023-03-07T08:30:18.733228Z","shell.execute_reply.started":"2023-03-07T08:30:18.699353Z","shell.execute_reply":"2023-03-07T08:30:18.73205Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv('../input/aptos2019-blindness-detection/train.csv')\ntrain_df.hist()","metadata":{"execution":{"iopub.status.busy":"2023-03-07T08:30:18.737398Z","iopub.execute_input":"2023-03-07T08:30:18.73837Z","iopub.status.idle":"2023-03-07T08:30:19.062183Z","shell.execute_reply.started":"2023-03-07T08:30:18.738328Z","shell.execute_reply":"2023-03-07T08:30:19.060891Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#new","metadata":{"execution":{"iopub.status.busy":"2023-03-07T08:30:19.063741Z","iopub.execute_input":"2023-03-07T08:30:19.064091Z","iopub.status.idle":"2023-03-07T08:30:19.069364Z","shell.execute_reply.started":"2023-03-07T08:30:19.064058Z","shell.execute_reply":"2023-03-07T08:30:19.068024Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport cv2\nimport random\nimport warnings\nimport numpy as np\nimport pandas as pd\nimport seaborn as sns\nimport matplotlib.pyplot as plt\nfrom sklearn.metrics import confusion_matrix, cohen_kappa_score\nfrom keras.models import Model\nfrom keras import optimizers, applications\nfrom keras.preprocessing.image import ImageDataGenerator\nfrom keras.callbacks import EarlyStopping, ReduceLROnPlateau\nfrom keras.layers import Dense, Dropout, GlobalAveragePooling2D, Input\nimport tensorflow as tf\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\nfrom tensorflow.keras.preprocessing import image_dataset_from_directory\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import InputLayer, BatchNormalization, Dropout, Flatten, Dense, Activation, MaxPool2D, Conv2D\nfrom tensorflow.keras.callbacks import EarlyStopping, ModelCheckpoint\nfrom tensorflow.keras.applications.resnet50 import ResNet50\nfrom tensorflow.keras.utils import to_categorical\nfrom keras import optimizers\nfrom tensorflow.keras.optimizers import Adam\nfrom keras.callbacks import Callback,ModelCheckpoint,ReduceLROnPlateau\nfrom keras.models import Sequential,load_model\nfrom keras.layers import Dense, Dropout\nfrom keras.wrappers.scikit_learn import KerasClassifier\nimport keras.backend as K\n#import tensorflow_addons as tfa\n#from tensorflow.keras.metrics import Metric\n#from tensorflow_addons.utils.types import AcceptableDTypes, FloatTensorLike\nfrom typeguard import typechecked\nfrom typing import Optional\n%matplotlib inline\nsns.set(style=\"whitegrid\")\nwarnings.filterwarnings(\"ignore\")","metadata":{"execution":{"iopub.status.busy":"2023-03-07T08:30:19.071436Z","iopub.execute_input":"2023-03-07T08:30:19.072358Z","iopub.status.idle":"2023-03-07T08:30:19.091375Z","shell.execute_reply.started":"2023-03-07T08:30:19.072302Z","shell.execute_reply":"2023-03-07T08:30:19.090123Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv('../input/aptos2019-blindness-detection/train.csv')\ntest = pd.read_csv('../input/aptos2019-blindness-detection/test.csv')\nsubmission= pd.read_csv('../input/aptos2019-blindness-detection/sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2023-03-07T08:30:19.093141Z","iopub.execute_input":"2023-03-07T08:30:19.093674Z","iopub.status.idle":"2023-03-07T08:30:19.114956Z","shell.execute_reply.started":"2023-03-07T08:30:19.093635Z","shell.execute_reply":"2023-03-07T08:30:19.11366Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Number of train samples: ', train.shape[0])\nprint('Number of test samples: ', test.shape[0])\ndisplay(train.head())","metadata":{"execution":{"iopub.status.busy":"2023-03-07T08:30:19.116642Z","iopub.execute_input":"2023-03-07T08:30:19.117137Z","iopub.status.idle":"2023-03-07T08:30:19.130324Z","shell.execute_reply.started":"2023-03-07T08:30:19.117098Z","shell.execute_reply":"2023-03-07T08:30:19.128646Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas_profiling as pp\npp.ProfileReport(train)","metadata":{"execution":{"iopub.status.busy":"2023-03-07T08:30:19.132188Z","iopub.execute_input":"2023-03-07T08:30:19.132547Z","iopub.status.idle":"2023-03-07T08:30:20.940006Z","shell.execute_reply.started":"2023-03-07T08:30:19.132514Z","shell.execute_reply":"2023-03-07T08:30:20.938709Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f, ax = plt.subplots(figsize=(10,6))\nax=sns.countplot(x=\"diagnosis\", data=train, palette=\"Set2\")\n\nsns.despine()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-03-07T08:30:20.941615Z","iopub.execute_input":"2023-03-07T08:30:20.941981Z","iopub.status.idle":"2023-03-07T08:30:21.198717Z","shell.execute_reply.started":"2023-03-07T08:30:20.941946Z","shell.execute_reply":"2023-03-07T08:30:21.19739Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"white\")\ncount = 1\nplt.figure(figsize=[10, 12])\nfor image_name in train['id_code'][:6]:\n    img = cv2.imread(\"../input/aptos2019-blindness-detection/train_images/%s.png\" %image_name)[...,[2,1,0]]\n    plt.subplot(3,3, count)\n    plt.imshow(img)\n    plt.title(\"Image Retina Diabetes %s\" % count)\n    count += 1\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-03-07T08:30:21.200213Z","iopub.execute_input":"2023-03-07T08:30:21.201107Z","iopub.status.idle":"2023-03-07T08:30:27.047052Z","shell.execute_reply.started":"2023-03-07T08:30:21.201061Z","shell.execute_reply":"2023-03-07T08:30:27.045459Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"n_classes = train[\"diagnosis\"].nunique()\nn_classes","metadata":{"execution":{"iopub.status.busy":"2023-03-07T08:30:27.048986Z","iopub.execute_input":"2023-03-07T08:30:27.04937Z","iopub.status.idle":"2023-03-07T08:30:27.057761Z","shell.execute_reply.started":"2023-03-07T08:30:27.049331Z","shell.execute_reply":"2023-03-07T08:30:27.056009Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train[\"id_code\"] = train[\"id_code\"].apply(lambda x: x + \".png\")\ntest[\"id_code\"] = test[\"id_code\"].apply(lambda x: x + \".png\")\ntrain['diagnosis'] = train['diagnosis'].astype('str')\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2023-03-07T08:30:27.06552Z","iopub.execute_input":"2023-03-07T08:30:27.066082Z","iopub.status.idle":"2023-03-07T08:30:27.089177Z","shell.execute_reply.started":"2023-03-07T08:30:27.066031Z","shell.execute_reply":"2023-03-07T08:30:27.087636Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_datagen=ImageDataGenerator(\n    rescale=1./255, \n    validation_split=0.2,\n    horizontal_flip=True\n)\n\ntrain_datagen=ImageDataGenerator(\n    rescale=1./255, \n    validation_split=0.2,\n    horizontal_flip=True\n)\n\n\ntest_datagen=ImageDataGenerator(\n    rescale=1./255, \n    validation_split=0.2,\n    horizontal_flip=True\n)","metadata":{"execution":{"iopub.status.busy":"2023-03-07T08:30:27.091411Z","iopub.execute_input":"2023-03-07T08:30:27.091806Z","iopub.status.idle":"2023-03-07T08:30:27.101104Z","shell.execute_reply.started":"2023-03-07T08:30:27.091768Z","shell.execute_reply":"2023-03-07T08:30:27.100027Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_generator=train_datagen.flow_from_dataframe(\n    dataframe=train,\n    directory=\"../input/aptos2019-blindness-detection/train_images/\",\n    x_col=\"id_code\",\n    y_col=\"diagnosis\",\n    batch_size=16,\n    class_mode=\"categorical\",\n    target_size=(224, 224),\n    subset='training')\n\n\nvalid_generator=train_datagen.flow_from_dataframe(\n    dataframe=train,\n    directory=\"../input/aptos2019-blindness-detection/train_images/\",\n    x_col=\"id_code\",\n    y_col=\"diagnosis\",\n    batch_size=16,\n    class_mode=\"categorical\",    \n    target_size=(224, 224),\n    subset='validation')\n\ntest_generator = test_datagen.flow_from_dataframe(\n    dataframe=test,\n    directory = \"../input/aptos2019-blindness-detection/test_images/\",\n    x_col=\"id_code\",\n    target_size=(224, 224),\n    batch_size=16,\n        shuffle=False,\n        class_mode=None\n)","metadata":{"execution":{"iopub.status.busy":"2023-03-07T08:30:27.102986Z","iopub.execute_input":"2023-03-07T08:30:27.103777Z","iopub.status.idle":"2023-03-07T08:30:28.065295Z","shell.execute_reply.started":"2023-03-07T08:30:27.103727Z","shell.execute_reply":"2023-03-07T08:30:28.06432Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_generator.class_indices","metadata":{"execution":{"iopub.status.busy":"2023-03-07T08:30:28.066764Z","iopub.execute_input":"2023-03-07T08:30:28.067134Z","iopub.status.idle":"2023-03-07T08:30:28.075968Z","shell.execute_reply.started":"2023-03-07T08:30:28.067098Z","shell.execute_reply":"2023-03-07T08:30:28.074314Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base_model = tf.keras.applications.ResNet152V2(input_shape=(224,224,3),include_top=False,weights=\"imagenet\")","metadata":{"execution":{"iopub.status.busy":"2023-03-07T08:30:28.07769Z","iopub.execute_input":"2023-03-07T08:30:28.078059Z","iopub.status.idle":"2023-03-07T08:30:34.053603Z","shell.execute_reply.started":"2023-03-07T08:30:28.078026Z","shell.execute_reply":"2023-03-07T08:30:34.052472Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for layer in base_model.layers[:-10]:\n    layer.trainable=False","metadata":{"execution":{"iopub.status.busy":"2023-03-07T08:30:34.055368Z","iopub.execute_input":"2023-03-07T08:30:34.056124Z","iopub.status.idle":"2023-03-07T08:30:34.080025Z","shell.execute_reply.started":"2023-03-07T08:30:34.056079Z","shell.execute_reply":"2023-03-07T08:30:34.078789Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model=Sequential()\nmodel.add(base_model)\nmodel.add(Dropout(0.5))\nmodel.add(Flatten())\nmodel.add(BatchNormalization())\nmodel.add(Dense(256,kernel_initializer='he_uniform'))\nmodel.add(BatchNormalization())\nmodel.add(Activation('relu'))\nmodel.add(Dropout(0.5))\nmodel.add(Dense(128,kernel_initializer='he_uniform'))\nmodel.add(BatchNormalization())\nmodel.add(Activation('relu'))\nmodel.add(Dropout(0.5))\nmodel.add(Dense(32,kernel_initializer='he_uniform'))\nmodel.add(BatchNormalization())\nmodel.add(Activation('relu'))\nmodel.add(Dense(5,activation='softmax'))","metadata":{"execution":{"iopub.status.busy":"2023-03-07T08:30:34.081482Z","iopub.execute_input":"2023-03-07T08:30:34.082184Z","iopub.status.idle":"2023-03-07T08:30:36.956432Z","shell.execute_reply.started":"2023-03-07T08:30:34.082144Z","shell.execute_reply":"2023-03-07T08:30:36.954881Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2023-03-07T08:30:36.9579Z","iopub.execute_input":"2023-03-07T08:30:36.958264Z","iopub.status.idle":"2023-03-07T08:30:37.046647Z","shell.execute_reply.started":"2023-03-07T08:30:36.958227Z","shell.execute_reply":"2023-03-07T08:30:37.045334Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.utils import plot_model\nfrom IPython.display import Image\nplot_model(model, to_file='convnet.png', show_shapes=True,show_layer_names=True)\nImage(filename='convnet.png')","metadata":{"execution":{"iopub.status.busy":"2023-03-07T08:30:37.048888Z","iopub.execute_input":"2023-03-07T08:30:37.049399Z","iopub.status.idle":"2023-03-07T08:30:37.45689Z","shell.execute_reply.started":"2023-03-07T08:30:37.049346Z","shell.execute_reply":"2023-03-07T08:30:37.45527Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# def f1_score(y_true, y_pred): #taken from old keras source code\n#     true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))\n#     possible_positives = K.sum(K.round(K.clip(y_true, 0, 1)))\n#     predicted_positives = K.sum(K.round(K.clip(y_pred, 0, 1)))\n#     precision = true_positives / (predicted_positives + K.epsilon())\n#     recall = true_positives / (possible_positives + K.epsilon())\n#     f1_val = 2*(precision*recall)/(precision+recall+K.epsilon())\n#     return f1_val\n\nMETRICS = [\n      tf.keras.metrics.BinaryAccuracy(name='accuracy'),\n      tf.keras.metrics.Precision(name='precision'),\n      tf.keras.metrics.Recall(name='recall'),  \n      tf.keras.metrics.AUC(name='auc'), \n    f1_score,\n]\n","metadata":{"execution":{"iopub.status.busy":"2023-03-07T08:30:37.459159Z","iopub.execute_input":"2023-03-07T08:30:37.459707Z","iopub.status.idle":"2023-03-07T08:30:37.466819Z","shell.execute_reply.started":"2023-03-07T08:30:37.459649Z","shell.execute_reply":"2023-03-07T08:30:37.465453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(\n    optimizer='Adam', \n    loss=\"categorical_crossentropy\", \n    metrics=METRICS\n)","metadata":{"execution":{"iopub.status.busy":"2023-03-07T08:30:37.468731Z","iopub.execute_input":"2023-03-07T08:30:37.469553Z","iopub.status.idle":"2023-03-07T08:30:37.504279Z","shell.execute_reply.started":"2023-03-07T08:30:37.469502Z","shell.execute_reply":"2023-03-07T08:30:37.503205Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"STEP_SIZE_TRAIN = train_generator.n//train_generator.batch_size\nSTEP_SIZE_VALID = valid_generator.n//valid_generator.batch_size","metadata":{"execution":{"iopub.status.busy":"2023-03-07T08:30:37.50582Z","iopub.execute_input":"2023-03-07T08:30:37.506205Z","iopub.status.idle":"2023-03-07T08:30:37.511075Z","shell.execute_reply.started":"2023-03-07T08:30:37.506166Z","shell.execute_reply":"2023-03-07T08:30:37.510212Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(STEP_SIZE_TRAIN)\nprint(STEP_SIZE_VALID)","metadata":{"execution":{"iopub.status.busy":"2023-03-07T08:30:37.512225Z","iopub.execute_input":"2023-03-07T08:30:37.513362Z","iopub.status.idle":"2023-03-07T08:30:37.526398Z","shell.execute_reply.started":"2023-03-07T08:30:37.513324Z","shell.execute_reply":"2023-03-07T08:30:37.524949Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history=model.fit(\n    train_generator,\n    steps_per_epoch=9,\n    epochs=25,\n    validation_data=valid_generator,\n    validation_steps=1,\n    verbose=1,\n)","metadata":{"execution":{"iopub.status.busy":"2023-03-07T08:30:37.528663Z","iopub.execute_input":"2023-03-07T08:30:37.529421Z","iopub.status.idle":"2023-03-07T08:59:55.222369Z","shell.execute_reply.started":"2023-03-07T08:30:37.52938Z","shell.execute_reply":"2023-03-07T08:59:55.221011Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"acc = history.history['accuracy']\nval_acc = history.history['val_accuracy']\nloss = history.history['loss']\nval_loss = history.history['val_loss']\n\nepochs = range(len(acc))\n\nplt.plot(epochs, acc, 'b', label='Training Accuracy')\nplt.plot(epochs, val_acc, 'r', label='Validation Accuracy')\nplt.legend(loc='best')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-03-07T08:59:55.224756Z","iopub.execute_input":"2023-03-07T08:59:55.225128Z","iopub.status.idle":"2023-03-07T08:59:55.519789Z","shell.execute_reply.started":"2023-03-07T08:59:55.225091Z","shell.execute_reply":"2023-03-07T08:59:55.518429Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(epochs, loss, 'b', label='Training Loss')\nplt.plot(epochs, val_loss, 'r', label='Validation Loss')\nplt.legend(loc = 'best')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-03-07T08:59:55.521696Z","iopub.execute_input":"2023-03-07T08:59:55.522754Z","iopub.status.idle":"2023-03-07T08:59:55.800602Z","shell.execute_reply.started":"2023-03-07T08:59:55.522703Z","shell.execute_reply":"2023-03-07T08:59:55.799369Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_save = ModelCheckpoint(\n    './Model5.h5',\n    save_best_only = True,\n    save_weights_only = False,\n    monitor = 'val_loss', \n    mode = 'min', \n    verbose = 1\n)","metadata":{"execution":{"iopub.status.busy":"2023-03-07T08:59:55.80247Z","iopub.execute_input":"2023-03-07T08:59:55.802953Z","iopub.status.idle":"2023-03-07T08:59:55.808763Z","shell.execute_reply.started":"2023-03-07T08:59:55.802851Z","shell.execute_reply":"2023-03-07T08:59:55.807449Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.callbacks import ModelCheckpoint,EarlyStopping,ReduceLROnPlateau\nfrom sklearn.metrics import classification_report,confusion_matrix\n\npredict_x = model.predict(test_generator)","metadata":{"execution":{"iopub.status.busy":"2023-03-07T08:59:55.810515Z","iopub.execute_input":"2023-03-07T08:59:55.810978Z","iopub.status.idle":"2023-03-07T09:07:41.800066Z","shell.execute_reply.started":"2023-03-07T08:59:55.81094Z","shell.execute_reply":"2023-03-07T09:07:41.798191Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_score = model.evaluate(train_generator, verbose= 1)\nvalid_score = model.evaluate(valid_generator, verbose= 1)\n\nprint(\"Train Loss: \", train_score[0])\nprint(\"Train Accuracy: \", train_score[1])\nprint('-' * 20)\nprint(\"Validation Loss: \", valid_score[0])\nprint(\"Validation Accuracy: \", valid_score[1])","metadata":{"execution":{"iopub.status.busy":"2023-03-07T09:07:41.803319Z","iopub.execute_input":"2023-03-07T09:07:41.804237Z","iopub.status.idle":"2023-03-07T09:23:58.329987Z","shell.execute_reply.started":"2023-03-07T09:07:41.804178Z","shell.execute_reply":"2023-03-07T09:23:58.328649Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}