{"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\n\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-07-07T12:35:31.587315Z","iopub.execute_input":"2023-07-07T12:35:31.588120Z","iopub.status.idle":"2023-07-07T12:35:31.618860Z","shell.execute_reply.started":"2023-07-07T12:35:31.588085Z","shell.execute_reply":"2023-07-07T12:35:31.618025Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train1 = np.load('/kaggle/input/x-train/x_train1.npy')\ny_train1 = np.load('/kaggle/input/y-train/y_train1.npy')","metadata":{"execution":{"iopub.status.busy":"2023-07-07T12:35:31.620371Z","iopub.execute_input":"2023-07-07T12:35:31.620835Z","iopub.status.idle":"2023-07-07T12:35:36.661514Z","shell.execute_reply.started":"2023-07-07T12:35:31.620807Z","shell.execute_reply":"2023-07-07T12:35:36.660327Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train1","metadata":{"execution":{"iopub.status.busy":"2023-07-07T12:35:36.662684Z","iopub.execute_input":"2023-07-07T12:35:36.663362Z","iopub.status.idle":"2023-07-07T12:35:36.676128Z","shell.execute_reply.started":"2023-07-07T12:35:36.663330Z","shell.execute_reply":"2023-07-07T12:35:36.674624Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nx_sptrain, x_spval, y_sptrain, y_spval = train_test_split(\n    x_train1, y_train1, \n    random_state=42\n)\n","metadata":{"execution":{"iopub.status.busy":"2023-07-07T12:35:36.679179Z","iopub.execute_input":"2023-07-07T12:35:36.679843Z","iopub.status.idle":"2023-07-07T12:35:38.183643Z","shell.execute_reply.started":"2023-07-07T12:35:36.679803Z","shell.execute_reply":"2023-07-07T12:35:38.182639Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nfrom matplotlib import pyplot as plt\nimport cv2\nimport gc\nimport tensorflow as tf\nfrom tqdm import tqdm\nfrom keras.models import Sequential\nfrom keras import layers\nfrom keras.optimizers import Adam\nfrom keras.applications import DenseNet121,DenseNet169,DenseNet201","metadata":{"execution":{"iopub.status.busy":"2023-07-07T12:35:38.185043Z","iopub.execute_input":"2023-07-07T12:35:38.186075Z","iopub.status.idle":"2023-07-07T12:35:46.635280Z","shell.execute_reply.started":"2023-07-07T12:35:38.186031Z","shell.execute_reply":"2023-07-07T12:35:46.634178Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# del x_train1,y_train1\n# gc.collect()","metadata":{"execution":{"iopub.status.busy":"2023-07-07T12:35:46.636662Z","iopub.execute_input":"2023-07-07T12:35:46.637380Z","iopub.status.idle":"2023-07-07T12:35:46.641612Z","shell.execute_reply.started":"2023-07-07T12:35:46.637340Z","shell.execute_reply":"2023-07-07T12:35:46.640373Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.preprocessing.image import ImageDataGenerator\ndef create_datagen():\n    return ImageDataGenerator(\n        horizontal_flip=True,   # randomly flip images\n        vertical_flip=True,     # randomly flip images\n        rotation_range=20 ,      # Degree range for random rotations\n        zoom_range=0.1\n    )\n\n# Using original generator\ndata_generator = create_datagen().flow(x_sptrain, y_sptrain,batch_size=16,seed=42)\nprint(\"Image data augmentated ...\")","metadata":{"execution":{"iopub.status.busy":"2023-07-07T12:35:46.643223Z","iopub.execute_input":"2023-07-07T12:35:46.643571Z","iopub.status.idle":"2023-07-07T12:35:47.405453Z","shell.execute_reply.started":"2023-07-07T12:35:46.643542Z","shell.execute_reply":"2023-07-07T12:35:47.404399Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import tensorflow as tf\n# import keras.backend as K\n# def f1(y_true, y_pred):\n#     y_pred = K.round(y_pred)\n#     tp = K.sum(K.cast(y_true*y_pred, 'float'), axis=0)\n#     tn = K.sum(K.cast((1-y_true)*(1-y_pred), 'float'), axis=0)\n#     fp = K.sum(K.cast((1-y_true)*y_pred, 'float'), axis=0)\n#     fn = K.sum(K.cast(y_true*(1-y_pred), 'float'), axis=0)\n\n#     p = tp / (tp + fp + K.epsilon())\n#     r = tp / (tp + fn + K.epsilon())\n\n#     f1 = 2*p*r / (p+r+K.epsilon())\n#     f1 = tf.where(tf.is_nan(f1), tf.zeros_like(f1), f1)\n#     return K.mean(f1)","metadata":{"execution":{"iopub.status.busy":"2023-07-07T12:35:47.406784Z","iopub.execute_input":"2023-07-07T12:35:47.407113Z","iopub.status.idle":"2023-07-07T12:35:47.412170Z","shell.execute_reply.started":"2023-07-07T12:35:47.407086Z","shell.execute_reply":"2023-07-07T12:35:47.410923Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nimport keras.backend as K\n\ndef f1(y_true, y_pred):\n    y_pred = K.round(y_pred)\n    tp = K.sum(K.cast(y_true * y_pred, 'float'), axis=0)\n    tn = K.sum(K.cast((1 - y_true) * (1 - y_pred), 'float'), axis=0)\n    fp = K.sum(K.cast((1 - y_true) * y_pred, 'float'), axis=0)\n    fn = K.sum(K.cast(y_true * (1 - y_pred), 'float'), axis=0)\n\n    p = tp / (tp + fp + K.epsilon())\n    r = tp / (tp + fn + K.epsilon())\n\n    f1 = 2 * p * r / (p + r + K.epsilon())\n    f1 = tf.where(tf.math.is_nan(f1), tf.zeros_like(f1), f1)\n    return K.mean(f1)\n","metadata":{"execution":{"iopub.status.busy":"2023-07-07T12:35:47.413251Z","iopub.execute_input":"2023-07-07T12:35:47.413547Z","iopub.status.idle":"2023-07-07T12:35:47.431807Z","shell.execute_reply.started":"2023-07-07T12:35:47.413522Z","shell.execute_reply":"2023-07-07T12:35:47.430695Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"effnet = DenseNet121(\n        weights='imagenet',\n        include_top=False,\n        input_shape=(256,256,3)\n)","metadata":{"execution":{"iopub.status.busy":"2023-07-07T12:35:47.435223Z","iopub.execute_input":"2023-07-07T12:35:47.436214Z","iopub.status.idle":"2023-07-07T12:35:52.666960Z","shell.execute_reply.started":"2023-07-07T12:35:47.436177Z","shell.execute_reply":"2023-07-07T12:35:52.666005Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"effnet = DenseNet121(\n        weights='imagenet',\n        include_top=False,\n        input_shape=(256,256,3)\n)","metadata":{"execution":{"iopub.status.busy":"2023-07-07T12:35:52.668131Z","iopub.execute_input":"2023-07-07T12:35:52.669000Z","iopub.status.idle":"2023-07-07T12:35:56.295589Z","shell.execute_reply.started":"2023-07-07T12:35:52.668959Z","shell.execute_reply":"2023-07-07T12:35:56.294455Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = Sequential()\nmodel.add(effnet)\nmodel.add(layers.GlobalAveragePooling2D())\nmodel.add(layers.Dropout(0.5))\nmodel.add(layers.Dense(1024,activation='relu'))\nmodel.add(layers.Dense(5, activation='sigmoid'))\n\nmodel.compile(\n        loss='binary_crossentropy',\n        optimizer=Adam(lr=0.00005),\n        metrics=['accuracy'],\n)","metadata":{"execution":{"iopub.status.busy":"2023-07-07T12:35:56.297132Z","iopub.execute_input":"2023-07-07T12:35:56.297477Z","iopub.status.idle":"2023-07-07T12:35:57.513547Z","shell.execute_reply.started":"2023-07-07T12:35:56.297445Z","shell.execute_reply":"2023-07-07T12:35:57.512133Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# from keras.callbacks import Callback,ModelCheckpoint\n# from sklearn.metrics import cohen_kappa_score\n# import json\n# class KappaMetrics(Callback):\n#     i=0\n#     def _init_(self, val_data, batch_size = 16):\n#         super()._init_()\n#         self.validation_data = val_data\n#         self.batch_size = batch_size\n\n#     def on_train_begin(self, logs={}):\n#         self.val_kappas = []\n        \n#     def on_epoch_end(self, epoch, logs={}):\n#         X_val, y_val = self.validation_data[:2]\n#         y_val = y_val.sum(axis=1) - 1\n        \n#         y_pred = self.model.predict(X_val) > 0.5\n#         y_pred = y_pred.astype(int).sum(axis=1) - 1\n\n#         _val_kappa = cohen_kappa_score(\n#             y_val,\n#             y_pred, \n#             weights='quadratic'\n#         )\n\n#         self.val_kappas.append(_val_kappa)\n\n#         print(f\"Epoch: {epoch+1} val_kappa: {_val_kappa:.4f}\")\n        \n#         if _val_kappa == max(self.val_kappas):\n#             print(\"Validation Kappa has improved. Saving model. - \"+str(KappaMetrics.i))\n#             model_json = self.model.to_json()\n#             with open(\"model_in_json\"+str(KappaMetrics.i)+\".json\", \"w\") as json_file:\n#                 json.dump(model_json, json_file)\n#             self.model.save_weights(\"model_weights\"+str(KappaMetrics.i)+\".h5\")\n#             KappaMetrics.i+=1\n#         return\n    \n# kappa_score = KappaMetrics()","metadata":{"execution":{"iopub.status.busy":"2023-07-07T12:35:57.514729Z","iopub.execute_input":"2023-07-07T12:35:57.515051Z","iopub.status.idle":"2023-07-07T12:35:57.521225Z","shell.execute_reply.started":"2023-07-07T12:35:57.515024Z","shell.execute_reply":"2023-07-07T12:35:57.519866Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install --upgrade tensorflow\n","metadata":{"execution":{"iopub.status.busy":"2023-07-07T12:35:57.522843Z","iopub.execute_input":"2023-07-07T12:35:57.523247Z","iopub.status.idle":"2023-07-07T12:37:06.854437Z","shell.execute_reply.started":"2023-07-07T12:35:57.523201Z","shell.execute_reply":"2023-07-07T12:37:06.853241Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\n\nprint(tf.__version__)\n","metadata":{"execution":{"iopub.status.busy":"2023-07-07T12:37:06.856188Z","iopub.execute_input":"2023-07-07T12:37:06.856532Z","iopub.status.idle":"2023-07-07T12:37:06.862020Z","shell.execute_reply.started":"2023-07-07T12:37:06.856502Z","shell.execute_reply":"2023-07-07T12:37:06.860974Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(data_generator)","metadata":{"execution":{"iopub.status.busy":"2023-07-07T12:37:06.863706Z","iopub.execute_input":"2023-07-07T12:37:06.864441Z","iopub.status.idle":"2023-07-07T12:37:08.472850Z","shell.execute_reply.started":"2023-07-07T12:37:06.864404Z","shell.execute_reply":"2023-07-07T12:37:08.472045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"x_spval shape:\", x_spval.shape)\nprint(\"y_spval shape:\", y_spval.shape)\nprint(\"x_spval dtype:\", x_spval.dtype)\nprint(\"y_spval dtype:\", y_spval.dtype)\n","metadata":{"execution":{"iopub.status.busy":"2023-07-07T12:37:08.474169Z","iopub.execute_input":"2023-07-07T12:37:08.474498Z","iopub.status.idle":"2023-07-07T12:37:08.487490Z","shell.execute_reply.started":"2023-07-07T12:37:08.474470Z","shell.execute_reply":"2023-07-07T12:37:08.486448Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(x_spval)","metadata":{"execution":{"iopub.status.busy":"2023-07-07T12:37:08.488726Z","iopub.execute_input":"2023-07-07T12:37:08.489077Z","iopub.status.idle":"2023-07-07T12:37:08.504644Z","shell.execute_reply.started":"2023-07-07T12:37:08.489048Z","shell.execute_reply":"2023-07-07T12:37:08.503606Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.callbacks import Callback,ModelCheckpoint\nfrom sklearn.metrics import cohen_kappa_score\nimport json\n\nclass KappaMetrics(Callback):\n    i=0\n    def _init_(self, val_data, batch_size = 8):\n        super()._init_()\n        self.validation_data = val_data\n        self.batch_size = batch_size\n        \n    def on_train_begin(self, logs={}):\n        self.val_kappas = []\n        \n    def on_epoch_end(self, epoch, logs={}):\n        batches = len(self.validation_data)\n        val_pred = np.zeros((batches * self.batch_size, 1))\n        val_true = np.zeros((batches * self.batch_size))\n\n        for batch in range(batches):\n            x_val_batch, y_val_batch = self.validation_data[batch]\n            start_idx = batch * self.batch_size\n            end_idx = (batch + 1) * self.batch_size\n\n            val_pred[start_idx:end_idx] = np.argmax(self.model.predict(x_val_batch), axis=1, keepdims=True)\n            val_true[start_idx:end_idx] = y_val_batch.sum(axis = 1) - 1\n\n        _val_kappa = cohen_kappa_score(val_true, val_pred, weights='quadratic')\n        self.val_kappas.append(_val_kappa)\n\n        print(f\"Epoch: {epoch+1} val_kappa: {_val_kappa:.4f}\")\n\n        if _val_kappa == max(self.val_kappas):\n            print(\"Validation Kappa has improved. Saving model. - \" + str(KappaMetrics.i))\n            model_json = self.model.to_json()\n            with open(\"model_in_json\" + str(KappaMetrics.i) + \".json\", \"w\") as json_file:\n                json.dump(model_json, json_file)\n            self.model.save_weights(\"model_weights\" + str(KappaMetrics.i) + \".h5\")\n            KappaMetrics.i += 1\n        return","metadata":{"execution":{"iopub.status.busy":"2023-07-07T12:43:26.975432Z","iopub.execute_input":"2023-07-07T12:43:26.977854Z","iopub.status.idle":"2023-07-07T12:43:26.995896Z","shell.execute_reply.started":"2023-07-07T12:43:26.977778Z","shell.execute_reply":"2023-07-07T12:43:26.994337Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.callbacks import Callback\nfrom sklearn.metrics import cohen_kappa_score\nimport json\n\nclass KappaMetrics(Callback):\n    i = 0\n\n    def __init__(self, val_data, batch_size=8):\n        super().__init__()\n        self.validation_data = val_data\n        self.batch_size = batch_size\n\n    def on_train_begin(self, logs=None):\n        self.val_kappas = []\n\n    def on_epoch_end(self, epoch, logs=None):\n        batches = len(self.validation_data)\n        val_pred = np.zeros((batches * self.batch_size, 1))\n        val_true = np.zeros((batches * self.batch_size))\n\n        for batch in range(batches):\n            \n            x_val_batch, y_val_batch = next(self.validation_data)\n            start_idx = batch * self.batch_size\n            end_idx = start_idx + len(x_val_batch)\n\n#             x_val_batch, y_val_batch = self.validation_data[batch]\n#             start_idx = batch * self.batch_size\n#             end_idx = (batch + 1) * self.batch_size\n\n            val_pred[start_idx:end_idx] = np.argmax(self.model.predict(x_val_batch), axis=1, keepdims=True)\n            val_true[start_idx:end_idx] = y_val_batch.sum(axis=1) - 1\n\n        _val_kappa = cohen_kappa_score(val_true, val_pred, weights='quadratic')\n        self.val_kappas.append(_val_kappa)\n\n        print(f\"Epoch: {epoch+1} val_kappa: {_val_kappa:.4f}\")\n\n        if _val_kappa == max(self.val_kappas):\n            print(\"Validation Kappa has improved. Saving model. - \" + str(KappaMetrics.i))\n            model_json = self.model.to_json()\n            with open(\"model_in_json\" + str(KappaMetrics.i) + \".json\", \"w\") as json_file:\n                json.dump(model_json, json_file)\n            self.model.save_weights(\"model_weights\" + str(KappaMetrics.i) + \".h5\")\n            KappaMetrics.i += 1\n","metadata":{"execution":{"iopub.status.busy":"2023-07-07T13:20:52.674170Z","iopub.execute_input":"2023-07-07T13:20:52.674619Z","iopub.status.idle":"2023-07-07T13:20:52.687300Z","shell.execute_reply.started":"2023-07-07T13:20:52.674591Z","shell.execute_reply":"2023-07-07T13:20:52.686105Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_datagen = ImageDataGenerator(rescale = 1/255.0)\nval_data_generator = val_datagen.flow(x_spval, y_spval, batch_size=8, seed=42)\n#print(val_data_generator._getitem_(1)[1].shape)","metadata":{"execution":{"iopub.status.busy":"2023-07-07T13:20:53.053961Z","iopub.execute_input":"2023-07-07T13:20:53.054338Z","iopub.status.idle":"2023-07-07T13:20:53.448180Z","shell.execute_reply.started":"2023-07-07T13:20:53.054309Z","shell.execute_reply":"2023-07-07T13:20:53.447120Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"kappa_score = KappaMetrics(val_data=val_data_generator)\nhistory = model.fit(\n    data_generator,\n    steps_per_epoch=10,\n    epochs=8,\n    validation_data=val_data_generator,  # Use the validation data generator\n    callbacks=[kappa_score]\n)","metadata":{"execution":{"iopub.status.busy":"2023-07-07T13:20:53.493263Z","iopub.execute_input":"2023-07-07T13:20:53.493638Z","iopub.status.idle":"2023-07-07T13:54:40.766649Z","shell.execute_reply.started":"2023-07-07T13:20:53.493611Z","shell.execute_reply":"2023-07-07T13:54:40.765503Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(y_spval)","metadata":{"execution":{"iopub.status.busy":"2023-07-07T13:54:40.769764Z","iopub.execute_input":"2023-07-07T13:54:40.770953Z","iopub.status.idle":"2023-07-07T13:54:40.778308Z","shell.execute_reply.started":"2023-07-07T13:54:40.770886Z","shell.execute_reply":"2023-07-07T13:54:40.777025Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history = model.fit(\n    data_generator,\n    steps_per_epoch=20,  # Use integer division instead of floating-point division\n    epochs=8,\n    validation_data=(x_spval, y_spval),\n    callbacks=[kappa_score],\n)\n","metadata":{"execution":{"iopub.status.busy":"2023-07-07T13:54:40.779689Z","iopub.execute_input":"2023-07-07T13:54:40.780240Z","iopub.status.idle":"2023-07-07T14:45:52.078364Z","shell.execute_reply.started":"2023-07-07T13:54:40.780203Z","shell.execute_reply":"2023-07-07T14:45:52.077372Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# history = model.fit_generator(\n#     data_generator,\n#     steps_per_epoch= 3362/16,\n#     epochs=8,\n#     validation_data=(x_spval, y_spval),\n#     callbacks=[kappa_score],\n# )","metadata":{"execution":{"iopub.status.busy":"2023-07-07T12:37:09.723447Z","iopub.status.idle":"2023-07-07T12:37:09.723969Z","shell.execute_reply.started":"2023-07-07T12:37:09.723693Z","shell.execute_reply":"2023-07-07T12:37:09.723717Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y=pd.read_csv('/kaggle/input/aptos2019-blindness-detection/test.csv')","metadata":{"execution":{"iopub.status.busy":"2023-07-07T14:47:32.864727Z","iopub.execute_input":"2023-07-07T14:47:32.865892Z","iopub.status.idle":"2023-07-07T14:47:32.891750Z","shell.execute_reply.started":"2023-07-07T14:47:32.865850Z","shell.execute_reply":"2023-07-07T14:47:32.890802Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y.head()","metadata":{"execution":{"iopub.status.busy":"2023-07-07T14:47:40.441999Z","iopub.execute_input":"2023-07-07T14:47:40.442519Z","iopub.status.idle":"2023-07-07T14:47:40.463390Z","shell.execute_reply.started":"2023-07-07T14:47:40.442490Z","shell.execute_reply":"2023-07-07T14:47:40.462581Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.preprocessing import image","metadata":{"execution":{"iopub.status.busy":"2023-07-07T14:49:39.185211Z","iopub.execute_input":"2023-07-07T14:49:39.185698Z","iopub.status.idle":"2023-07-07T14:49:39.191197Z","shell.execute_reply.started":"2023-07-07T14:49:39.185661Z","shell.execute_reply":"2023-07-07T14:49:39.190088Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"size = (256,256)","metadata":{"execution":{"iopub.status.busy":"2023-07-07T15:00:17.881173Z","iopub.execute_input":"2023-07-07T15:00:17.882028Z","iopub.status.idle":"2023-07-07T15:00:17.887090Z","shell.execute_reply.started":"2023-07-07T15:00:17.881987Z","shell.execute_reply":"2023-07-07T15:00:17.885990Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred1 = []","metadata":{"execution":{"iopub.status.busy":"2023-07-07T15:04:47.540979Z","iopub.execute_input":"2023-07-07T15:04:47.541692Z","iopub.status.idle":"2023-07-07T15:04:47.547070Z","shell.execute_reply.started":"2023-07-07T15:04:47.541653Z","shell.execute_reply":"2023-07-07T15:04:47.546016Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from PIL import Image\n\nfor i in y['id_code']:\n    img = Image.open('/kaggle/input/aptos2019-blindness-detection/test_images/' + i + '.png')\n    img = img.resize(size)\n    img = np.array(img)\n    img = img.reshape(1, 256, 256, 3)\n    output = model.predict(img)\n    pred1 = np.append(pred1, np.argmax(output[0]))\n","metadata":{"execution":{"iopub.status.busy":"2023-07-07T15:04:47.904174Z","iopub.execute_input":"2023-07-07T15:04:47.904718Z","iopub.status.idle":"2023-07-07T15:13:20.823943Z","shell.execute_reply.started":"2023-07-07T15:04:47.904681Z","shell.execute_reply":"2023-07-07T15:13:20.823051Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred = []\nfor j in pred1:\n    pred.append(int(j))\nprint(pred)\n","metadata":{"execution":{"iopub.status.busy":"2023-07-07T15:14:12.826005Z","iopub.execute_input":"2023-07-07T15:14:12.826413Z","iopub.status.idle":"2023-07-07T15:14:12.834353Z","shell.execute_reply.started":"2023-07-07T15:14:12.826380Z","shell.execute_reply":"2023-07-07T15:14:12.833421Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# for i in y['id_code']:\n#     img=image.load_img(('/kaggle/input/aptos2019-blindness-detection/test_images'+i+\".png\"),target_size=size)\n#     img=image.img_to_array(img)\n#     img=img.reshape(1,128,128,3)\n#     output=model.predict(img)\n#     pred1=np.append(pred1,(np.argmax(output[0])))","metadata":{"execution":{"iopub.status.busy":"2023-07-07T14:50:02.228413Z","iopub.execute_input":"2023-07-07T14:50:02.229390Z","iopub.status.idle":"2023-07-07T14:50:02.271800Z","shell.execute_reply.started":"2023-07-07T14:50:02.229349Z","shell.execute_reply":"2023-07-07T14:50:02.270160Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x = pd.DataFrame({'id_code':y['id_code'],'diagnosis': pred })\nprint(x)","metadata":{"execution":{"iopub.status.busy":"2023-07-07T15:16:31.902458Z","iopub.execute_input":"2023-07-07T15:16:31.902969Z","iopub.status.idle":"2023-07-07T15:16:31.914160Z","shell.execute_reply.started":"2023-07-07T15:16:31.902932Z","shell.execute_reply":"2023-07-07T15:16:31.912980Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub = x.to_csv('submission.csv')","metadata":{"execution":{"iopub.status.busy":"2023-07-07T15:16:35.207894Z","iopub.execute_input":"2023-07-07T15:16:35.210254Z","iopub.status.idle":"2023-07-07T15:16:35.227514Z","shell.execute_reply.started":"2023-07-07T15:16:35.210204Z","shell.execute_reply":"2023-07-07T15:16:35.226404Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}