{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":14774,"databundleVersionId":875431,"sourceType":"competition"},{"sourceId":9900,"sourceType":"datasetVersion","datasetId":6209}],"dockerImageVersionId":30665,"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","execution":{"iopub.status.busy":"2024-02-28T07:36:44.083422Z","iopub.execute_input":"2024-02-28T07:36:44.083794Z","iopub.status.idle":"2024-02-28T07:36:45.212695Z","shell.execute_reply.started":"2024-02-28T07:36:44.083762Z","shell.execute_reply":"2024-02-28T07:36:45.211736Z"},"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 tensorflow.keras.preprocessing.image import ImageDataGenerator\nfrom keras.callbacks import EarlyStopping, ReduceLROnPlateau\nfrom keras.layers import Dense, Dropout, GlobalAveragePooling2D, Input\n\n# Set seeds to make the experiment more reproducible.\nfrom tensorflow.random import set_seed\ndef seed_everything(seed=0):\n    random.seed(seed)\n    os.environ['PYTHONHASHSEED'] = str(seed)\n    np.random.seed(seed)\n    set_seed(0)\nseed_everything()\n\n%matplotlib inline\nsns.set(style=\"whitegrid\")\nwarnings.filterwarnings(\"ignore\")","metadata":{"execution":{"iopub.status.busy":"2024-02-28T07:39:21.823147Z","iopub.execute_input":"2024-02-28T07:39:21.823773Z","iopub.status.idle":"2024-02-28T07:39:21.846930Z","shell.execute_reply.started":"2024-02-28T07:39:21.823744Z","shell.execute_reply":"2024-02-28T07:39:21.845973Z"},"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')","metadata":{"execution":{"iopub.status.busy":"2024-02-28T07:40:44.521278Z","iopub.execute_input":"2024-02-28T07:40:44.521612Z","iopub.status.idle":"2024-02-28T07:40:44.547122Z","shell.execute_reply.started":"2024-02-28T07:40:44.521587Z","shell.execute_reply":"2024-02-28T07:40:44.546141Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# EDA Part and Data Overview\nprint('Number of train samples: ', train.shape[0])\nprint('Number of test samples: ', test.shape[0])\ndisplay(train.head())","metadata":{"execution":{"iopub.status.busy":"2024-02-28T07:41:13.766394Z","iopub.execute_input":"2024-02-28T07:41:13.766768Z","iopub.status.idle":"2024-02-28T07:41:13.786540Z","shell.execute_reply.started":"2024-02-28T07:41:13.766737Z","shell.execute_reply":"2024-02-28T07:41:13.785193Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Label Class Distribution\nf, ax = plt.subplots(figsize=(14, 8.7))\nax = sns.countplot(x=\"diagnosis\", data=train, palette=\"GnBu_d\")\nsns.despine()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-02-28T07:41:35.867077Z","iopub.execute_input":"2024-02-28T07:41:35.867447Z","iopub.status.idle":"2024-02-28T07:41:36.179470Z","shell.execute_reply.started":"2024-02-28T07:41:35.867418Z","shell.execute_reply":"2024-02-28T07:41:36.178472Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"white\")\ncount = 1\nplt.figure(figsize=[20, 20])\nfor img_name in train['id_code'][:15]:\n    img = cv2.imread(\"../input/aptos2019-blindness-detection/train_images/%s.png\" % img_name)[...,[2, 1, 0]]\n    plt.subplot(5, 5, count)\n    plt.imshow(img)\n    plt.title(\"Image %s\" % count)\n    count += 1\n    \nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-02-28T07:41:54.501718Z","iopub.execute_input":"2024-02-28T07:41:54.502120Z","iopub.status.idle":"2024-02-28T07:42:08.205031Z","shell.execute_reply.started":"2024-02-28T07:41:54.502079Z","shell.execute_reply":"2024-02-28T07:42:08.203878Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Setting the model parameters\nBATCH_SIZE = 8\nEPOCHS = 20\nWARMUP_EPOCHS = 2\nLEARNING_RATE = 1e-4\nWARMUP_LEARNING_RATE = 1e-3\nHEIGHT = 512\nWIDTH = 512\nCANAL = 3\nN_CLASSES = train['diagnosis'].nunique()\nES_PATIENCE = 5\nRLROP_PATIENCE = 3\nDECAY_DROP = 0.5","metadata":{"execution":{"iopub.status.busy":"2024-02-28T07:42:20.174374Z","iopub.execute_input":"2024-02-28T07:42:20.174713Z","iopub.status.idle":"2024-02-28T07:42:20.180730Z","shell.execute_reply.started":"2024-02-28T07:42:20.174687Z","shell.execute_reply":"2024-02-28T07:42:20.179567Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Preprocecss data\ntrain[\"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":"2024-02-28T07:42:27.314315Z","iopub.execute_input":"2024-02-28T07:42:27.315023Z","iopub.status.idle":"2024-02-28T07:42:27.330532Z","shell.execute_reply.started":"2024-02-28T07:42:27.314992Z","shell.execute_reply":"2024-02-28T07:42:27.329498Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Data Generator for train, test and validation\ntrain_datagen=ImageDataGenerator(rescale=1./255, \n                                 validation_split=0.2,\n                                 horizontal_flip=True)\n\ntrain_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=BATCH_SIZE,\n    class_mode=\"categorical\",\n    target_size=(HEIGHT, WIDTH),\n    subset='training')\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=BATCH_SIZE,\n    class_mode=\"categorical\",    \n    target_size=(HEIGHT, WIDTH),\n    subset='validation')\n\ntest_datagen = ImageDataGenerator(rescale=1./255)\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=(HEIGHT, WIDTH),\n        batch_size=1,\n        shuffle=False,\n        class_mode=None)","metadata":{"execution":{"iopub.status.busy":"2024-02-28T07:43:11.987310Z","iopub.execute_input":"2024-02-28T07:43:11.988018Z","iopub.status.idle":"2024-02-28T07:43:24.449392Z","shell.execute_reply.started":"2024-02-28T07:43:11.987987Z","shell.execute_reply":"2024-02-28T07:43:24.448477Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras import applications, optimizers\nfrom tensorflow.keras.layers import Input, GlobalAveragePooling2D, Dense, Dropout\nfrom tensorflow.keras.models import Model\n\ndef create_model(input_shape, n_out):\n    input_tensor = Input(shape=input_shape)\n    base_model = applications.ResNet50(weights='imagenet', \n                                       include_top=False,\n                                       input_tensor=input_tensor)\n\n    x = GlobalAveragePooling2D()(base_model.output)\n    x = Dropout(0.5)(x)\n    x = Dense(2048, activation='relu')(x)\n    x = Dropout(0.5)(x)\n    final_output = Dense(n_out, activation='softmax', name='final_output')(x)\n    model = Model(input_tensor, final_output)\n    \n    return model","metadata":{"execution":{"iopub.status.busy":"2024-02-28T07:47:36.605679Z","iopub.execute_input":"2024-02-28T07:47:36.606104Z","iopub.status.idle":"2024-02-28T07:47:36.618044Z","shell.execute_reply.started":"2024-02-28T07:47:36.606063Z","shell.execute_reply":"2024-02-28T07:47:36.616947Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = create_model(input_shape=(HEIGHT, WIDTH, CANAL), n_out=N_CLASSES)\n\n# Freeze all layers and then unfreeze the last 5\nfor layer in model.layers:\n    layer.trainable = False\n\nfor i in range(-5, 0):\n    model.layers[i].trainable = True\n\n# Learning rate warm-up\nmetric_list = [\"accuracy\"]\nWARMUP_LEARNING_RATE = 1e-4\noptimizer = optimizers.Adam(learning_rate=WARMUP_LEARNING_RATE)\nmodel.compile(optimizer=optimizer, loss=\"categorical_crossentropy\", metrics=metric_list)\n\nmodel.summary()","metadata":{"execution":{"iopub.status.busy":"2024-02-28T07:49:20.167883Z","iopub.execute_input":"2024-02-28T07:49:20.168795Z","iopub.status.idle":"2024-02-28T07:49:21.591529Z","shell.execute_reply.started":"2024-02-28T07:49:20.168747Z","shell.execute_reply":"2024-02-28T07:49:21.590680Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\n\nos.environ['TF_XLA_FLAGS'] = '--tf_xla_auto_jit=2'","metadata":{"execution":{"iopub.status.busy":"2024-02-28T08:03:18.640515Z","iopub.execute_input":"2024-02-28T08:03:18.641018Z","iopub.status.idle":"2024-02-28T08:03:18.645564Z","shell.execute_reply.started":"2024-02-28T08:03:18.640987Z","shell.execute_reply":"2024-02-28T08:03:18.644566Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Train the top layers of the model\nSTEP_SIZE_TRAIN = train_generator.n//train_generator.batch_size\nSTEP_SIZE_VALID = valid_generator.n//valid_generator.batch_size\n\nhistory_warmup = model.fit(\n    train_generator,\n    steps_per_epoch=STEP_SIZE_TRAIN,\n    validation_data=valid_generator,\n    validation_steps=STEP_SIZE_VALID,\n    epochs=WARMUP_EPOCHS,\n    verbose=1\n).history","metadata":{"execution":{"iopub.status.busy":"2024-02-28T08:03:23.338090Z","iopub.execute_input":"2024-02-28T08:03:23.338775Z","iopub.status.idle":"2024-02-28T08:09:56.992423Z","shell.execute_reply.started":"2024-02-28T08:03:23.338744Z","shell.execute_reply":"2024-02-28T08:09:56.991532Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Finetune the complete model\nfor layer in model.layers:\n    layer.trainable = True\n\nes = EarlyStopping(monitor='val_loss', mode='min', patience=ES_PATIENCE, restore_best_weights=True, verbose=1)\nrlrop = ReduceLROnPlateau(monitor='val_loss', mode='min', patience=RLROP_PATIENCE, factor=DECAY_DROP, min_lr=1e-6, verbose=1)\n\ncallback_list = [es, rlrop]\noptimizer = optimizers.Adam(learning_rate=LEARNING_RATE)\nmodel.compile(optimizer=optimizer, loss=\"binary_crossentropy\",  metrics=metric_list)\nmodel.summary()","metadata":{"execution":{"iopub.status.busy":"2024-02-28T08:13:32.858632Z","iopub.execute_input":"2024-02-28T08:13:32.859024Z","iopub.status.idle":"2024-02-28T08:13:33.117240Z","shell.execute_reply.started":"2024-02-28T08:13:32.858994Z","shell.execute_reply":"2024-02-28T08:13:33.116199Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history_finetuning = model.fit(\n    train_generator,\n    steps_per_epoch=STEP_SIZE_TRAIN,\n    validation_data=valid_generator,\n    validation_steps=STEP_SIZE_VALID,\n    epochs=EPOCHS,\n    callbacks=callback_list,\n    verbose=1\n).history","metadata":{"execution":{"iopub.status.busy":"2024-02-28T08:14:30.327022Z","iopub.execute_input":"2024-02-28T08:14:30.327416Z","iopub.status.idle":"2024-02-28T09:08:46.354914Z","shell.execute_reply.started":"2024-02-28T08:14:30.327386Z","shell.execute_reply":"2024-02-28T09:08:46.353879Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Model loss graph\nhistory = {\n    'loss': history_warmup['loss'] + history_finetuning['loss'],\n    'val_loss': history_warmup['val_loss'] + history_finetuning['val_loss'],\n    'accuracy': history_warmup['accuracy'] + history_finetuning['accuracy'],\n    'val_accuracy': history_warmup['val_accuracy'] + history_finetuning['val_accuracy']\n}\n\nsns.set_style(\"whitegrid\")\nfig, (ax1, ax2) = plt.subplots(2, 1, sharex='col', figsize=(20, 14))\n\nax1.plot(history['loss'], label='Train loss')\nax1.plot(history['val_loss'], label='Validation loss')\nax1.legend(loc='best')\nax1.set_title('Loss')\n\nax2.plot(history['accuracy'], label='Train Accuracy')\nax2.plot(history['val_accuracy'], label='Validation accuracy')\nax2.legend(loc='best')\nax2.set_title('Accuracy')\n\nplt.xlabel('Epochs')\nsns.despine()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-02-28T09:11:51.555511Z","iopub.execute_input":"2024-02-28T09:11:51.556383Z","iopub.status.idle":"2024-02-28T09:11:52.352765Z","shell.execute_reply.started":"2024-02-28T09:11:51.556339Z","shell.execute_reply":"2024-02-28T09:11:52.351797Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Model Evaluation\ncomplete_datagen = ImageDataGenerator(rescale=1./255)\ncomplete_generator = complete_datagen.flow_from_dataframe(  \n        dataframe=train,\n        directory = \"../input/aptos2019-blindness-detection/train_images/\",\n        x_col=\"id_code\",\n        target_size=(HEIGHT, WIDTH),\n        batch_size=1,\n        shuffle=False,\n        class_mode=None)\n\nSTEP_SIZE_COMPLETE = complete_generator.n//complete_generator.batch_size\ntrain_preds = model.predict(complete_generator, steps=STEP_SIZE_COMPLETE)\ntrain_preds = [np.argmax(pred) for pred in train_preds]","metadata":{"execution":{"iopub.status.busy":"2024-02-28T09:13:10.763013Z","iopub.execute_input":"2024-02-28T09:13:10.763678Z","iopub.status.idle":"2024-02-28T09:19:47.956409Z","shell.execute_reply.started":"2024-02-28T09:13:10.763642Z","shell.execute_reply":"2024-02-28T09:19:47.955206Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Confusion Matrix\nlabels = ['0 - No DR', '1 - Mild', '2 - Moderate', '3 - Severe', '4 - Proliferative DR']\ncnf_matrix = confusion_matrix(train['diagnosis'].astype('int'), train_preds)\ncnf_matrix_norm = cnf_matrix.astype('float') / cnf_matrix.sum(axis=1)[:, np.newaxis]\ndf_cm = pd.DataFrame(cnf_matrix_norm, index=labels, columns=labels)\nplt.figure(figsize=(16, 7))\nsns.heatmap(df_cm, annot=True, fmt='.2f', cmap=\"Blues\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-02-28T09:20:36.272998Z","iopub.execute_input":"2024-02-28T09:20:36.273389Z","iopub.status.idle":"2024-02-28T09:20:36.723878Z","shell.execute_reply.started":"2024-02-28T09:20:36.273357Z","shell.execute_reply":"2024-02-28T09:20:36.722858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Finding the Quadratic Kappa Score\nprint(\"Train Cohen Kappa score: %.3f\" % cohen_kappa_score(train_preds, train['diagnosis'].astype('int'), weights='quadratic'))","metadata":{"execution":{"iopub.status.busy":"2024-02-28T09:21:09.215743Z","iopub.execute_input":"2024-02-28T09:21:09.216126Z","iopub.status.idle":"2024-02-28T09:21:09.225921Z","shell.execute_reply.started":"2024-02-28T09:21:09.216097Z","shell.execute_reply":"2024-02-28T09:21:09.225070Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Apply the model to test set and output predictions\ntest_generator.reset()\nSTEP_SIZE_TEST = test_generator.n//test_generator.batch_size\npreds = model.predict(test_generator, steps=STEP_SIZE_TEST)\npredictions = [np.argmax(pred) for pred in preds]","metadata":{"execution":{"iopub.status.busy":"2024-02-28T09:21:51.162006Z","iopub.execute_input":"2024-02-28T09:21:51.162921Z","iopub.status.idle":"2024-02-28T09:23:37.968895Z","shell.execute_reply.started":"2024-02-28T09:21:51.162884Z","shell.execute_reply":"2024-02-28T09:23:37.968045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"filenames = test_generator.filenames\nresults = pd.DataFrame({'id_code':filenames, 'diagnosis':predictions})\nresults['id_code'] = results['id_code'].map(lambda x: str(x)[:-4])\nresults.to_csv('submission.csv',index=False)\nresults.head(10)","metadata":{"execution":{"iopub.status.busy":"2024-02-28T09:46:40.120634Z","iopub.execute_input":"2024-02-28T09:46:40.121048Z","iopub.status.idle":"2024-02-28T09:46:40.153254Z","shell.execute_reply.started":"2024-02-28T09:46:40.121016Z","shell.execute_reply":"2024-02-28T09:46:40.152302Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Predictions class distribution\nf, ax = plt.subplots(figsize=(14, 8.7))\nax = sns.countplot(x=\"diagnosis\", data=results, palette=\"GnBu_d\")\nsns.despine()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-02-28T09:48:20.233830Z","iopub.execute_input":"2024-02-28T09:48:20.234246Z","iopub.status.idle":"2024-02-28T09:48:21.092835Z","shell.execute_reply.started":"2024-02-28T09:48:20.234216Z","shell.execute_reply":"2024-02-28T09:48:21.091839Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Save the model\nmodel.save('diabetic_retinopathy_model.h5')","metadata":{"execution":{"iopub.status.busy":"2024-02-28T09:54:53.447255Z","iopub.execute_input":"2024-02-28T09:54:53.447955Z","iopub.status.idle":"2024-02-28T09:54:54.394835Z","shell.execute_reply.started":"2024-02-28T09:54:53.447923Z","shell.execute_reply":"2024-02-28T09:54:54.393730Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.models import load_model\nfrom keras.preprocessing import image\nimport numpy as np","metadata":{"execution":{"iopub.status.busy":"2024-02-28T09:55:46.402207Z","iopub.execute_input":"2024-02-28T09:55:46.402597Z","iopub.status.idle":"2024-02-28T09:55:46.407383Z","shell.execute_reply.started":"2024-02-28T09:55:46.402566Z","shell.execute_reply":"2024-02-28T09:55:46.406175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Load the saved model\nloaded_model = load_model('diabetic_retinopathy_model.h5')","metadata":{"execution":{"iopub.status.busy":"2024-02-28T09:55:55.159008Z","iopub.execute_input":"2024-02-28T09:55:55.159739Z","iopub.status.idle":"2024-02-28T09:55:56.247440Z","shell.execute_reply.started":"2024-02-28T09:55:55.159705Z","shell.execute_reply":"2024-02-28T09:55:56.246449Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Path to the test image you want to predict\ntest_image_path = \"/kaggle/input/aptos2019-blindness-detection/train_images/000c1434d8d7.png\"","metadata":{"execution":{"iopub.status.busy":"2024-02-28T09:58:39.227158Z","iopub.execute_input":"2024-02-28T09:58:39.227526Z","iopub.status.idle":"2024-02-28T09:58:39.231718Z","shell.execute_reply.started":"2024-02-28T09:58:39.227496Z","shell.execute_reply":"2024-02-28T09:58:39.230841Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Load and preprocess the test image\nimg = image.load_img(test_image_path, target_size=(HEIGHT, WIDTH))\nimg_array = image.img_to_array(img)\nimg_array = np.expand_dims(img_array, axis=0)\nimg_array /= 255.0","metadata":{"execution":{"iopub.status.busy":"2024-02-28T09:57:56.849105Z","iopub.execute_input":"2024-02-28T09:57:56.849521Z","iopub.status.idle":"2024-02-28T09:57:57.094976Z","shell.execute_reply.started":"2024-02-28T09:57:56.849491Z","shell.execute_reply":"2024-02-28T09:57:57.093979Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Make predictions\npredictions = loaded_model.predict(img_array)","metadata":{"execution":{"iopub.status.busy":"2024-02-28T09:58:05.116219Z","iopub.execute_input":"2024-02-28T09:58:05.117157Z","iopub.status.idle":"2024-02-28T09:58:08.489739Z","shell.execute_reply.started":"2024-02-28T09:58:05.117110Z","shell.execute_reply":"2024-02-28T09:58:08.488958Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Convert predictions to the corresponding class\npredicted_class = np.argmax(predictions)\nprint(\"Predicted Diabetic Retinopathy Stage:\", predicted_class)","metadata":{"execution":{"iopub.status.busy":"2024-02-28T09:58:59.815319Z","iopub.execute_input":"2024-02-28T09:58:59.815738Z","iopub.status.idle":"2024-02-28T09:58:59.820562Z","shell.execute_reply.started":"2024-02-28T09:58:59.815706Z","shell.execute_reply":"2024-02-28T09:58:59.819632Z"},"trusted":true},"execution_count":null,"outputs":[]}]}