{"metadata":{"kernelspec":{"name":"python3","display_name":"Python 3","language":"python"},"language_info":{"name":"python","version":"3.11.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":14774,"databundleVersionId":875431,"isSourceIdPinned":false,"sourceType":"competition"},{"sourceId":14006687,"sourceType":"datasetVersion","datasetId":8924262}],"dockerImageVersionId":31090,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os \nos.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom sklearn.model_selection import train_test_split\nimport tensorflow as tf\nfrom tensorflow.keras.applications import EfficientNetB3\nfrom tensorflow.keras.layers import Dense, GlobalAveragePooling2D, GlobalMaxPooling2D, Concatenate, Dropout, BatchNormalization, Activation\nfrom tensorflow.keras.optimizers import Adam\nfrom tensorflow.keras.callbacks import EarlyStopping\nfrom tensorflow.keras.callbacks import ReduceLROnPlateau\nfrom tensorflow.keras.models import Model\nfrom sklearn.utils import class_weight","metadata":{"execution":{"iopub.status.busy":"2025-12-05T10:38:17.734162Z","iopub.execute_input":"2025-12-05T10:38:17.734746Z","iopub.status.idle":"2025-12-05T10:38:30.550386Z","shell.execute_reply.started":"2025-12-05T10:38:17.734716Z","shell.execute_reply":"2025-12-05T10:38:30.549794Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_df = pd.read_csv('/kaggle/input/aptos2019-blindness-detection/test.csv')\ntest_df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-05T10:38:32.171809Z","iopub.execute_input":"2025-12-05T10:38:32.172621Z","iopub.status.idle":"2025-12-05T10:38:32.203402Z","shell.execute_reply.started":"2025-12-05T10:38:32.172592Z","shell.execute_reply":"2025-12-05T10:38:32.202695Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model = tf.keras.models.load_model(\"/kaggle/input/aptos-blindness-detection-outputs/EfficientNetB5_Regression_UnFrozen.keras\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-05T10:39:52.013418Z","iopub.execute_input":"2025-12-05T10:39:52.013964Z","iopub.status.idle":"2025-12-05T10:39:58.244995Z","shell.execute_reply.started":"2025-12-05T10:39:52.013939Z","shell.execute_reply":"2025-12-05T10:39:58.244455Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_path = \"/kaggle/input/aptos2019-blindness-detection/test_images\"\ndef process_test_image(path):\n    image = tf.io.read_file(path)\n    image = tf.image.decode_png(image, channels=3)\n    image = tf.image.resize(image, [300, 300])\n    return image\n\ntest_paths = test_df['id_code'].apply(lambda x: os.path.join(test_path, x + \".png\")).values\n\ntest_ds = tf.data.Dataset.from_tensor_slices(test_paths)\ntest_ds = test_ds.map(process_test_image, num_parallel_calls=tf.data.AUTOTUNE)\ntest_ds = test_ds.batch(32)\ntest_ds = test_ds.prefetch(buffer_size=1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-05T10:40:03.019769Z","iopub.execute_input":"2025-12-05T10:40:03.020273Z","iopub.status.idle":"2025-12-05T10:40:03.081891Z","shell.execute_reply.started":"2025-12-05T10:40:03.020249Z","shell.execute_reply":"2025-12-05T10:40:03.081347Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(\"Predicting...\")\npredictions = model.predict(test_ds, verbose=1)\n\npredictions = predictions.flatten() * 4.0\n\nfinal_preds = np.clip(np.round(predictions), 0, 4).astype(int)\n\ntest_df['diagnosis'] = final_preds\ntest_df.to_csv('submission.csv', index=False)\n\nprint(\"Done! Submission saved.\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-05T10:40:05.074650Z","iopub.execute_input":"2025-12-05T10:40:05.074930Z","iopub.status.idle":"2025-12-05T10:40:50.906132Z","shell.execute_reply.started":"2025-12-05T10:40:05.074908Z","shell.execute_reply":"2025-12-05T10:40:50.905546Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_df.to_csv(\"test.csv\", index=False)\ntest_df.to_csv(\"sample_submission.csv\", index=False)\ntest_df.to_csv(\"submission.csv\", index=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-05T10:40:50.907324Z","iopub.execute_input":"2025-12-05T10:40:50.907908Z","iopub.status.idle":"2025-12-05T10:40:50.918188Z","shell.execute_reply.started":"2025-12-05T10:40:50.907888Z","shell.execute_reply":"2025-12-05T10:40:50.917618Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-05T10:40:50.918881Z","iopub.execute_input":"2025-12-05T10:40:50.919065Z","iopub.status.idle":"2025-12-05T10:40:50.930912Z","shell.execute_reply.started":"2025-12-05T10:40:50.919050Z","shell.execute_reply":"2025-12-05T10:40:50.930423Z"}},"outputs":[],"execution_count":null}]}