{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.12.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[],"dockerImageVersionId":28755,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"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\n\n# Use the kagglehub client library to attach Kaggle resources like competitions, datasets, and models to your session\n# Learn more about kagglehub: https://github.com/Kaggle/kagglehub/blob/main/README.md\n\nimport kagglehub\n# kagglehub.dataset_download('<owner>/<dataset-slug>')","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2026-10-02T01:47:08.387113Z","iopub.execute_input":"2026-10-02T01:47:08.387429Z","iopub.status.idle":"2026-10-02T01:47:10.811942Z","shell.execute_reply.started":"2026-10-02T01:47:08.387393Z","shell.execute_reply":"2026-10-02T01:47:10.810757Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import torch\nfrom pathlib import Path\n\nprint(\"=\" * 70)\nprint(\"DrishtiAI - Final DR Training\")\nprint(\"=\" * 70)\n\nprint(\"PyTorch:\", torch.__version__)\nprint(\"CUDA available:\", torch.cuda.is_available())\n\nif torch.cuda.is_available():\n    print(\"GPU:\", torch.cuda.get_device_name(0))\n\nDATA_ROOT = Path(\n    \"/kaggle/input/competitions/aptos2019-blindness-detection\"\n)\n\nCSV_PATH = DATA_ROOT / \"train.csv\"\nIMAGE_DIR = DATA_ROOT / \"train_images\"\n\nprint()\nprint(\"CSV exists:\", CSV_PATH.exists())\nprint(\"Image directory exists:\", IMAGE_DIR.exists())\n\nif IMAGE_DIR.exists():\n    print(\"Image count:\", len(list(IMAGE_DIR.glob(\"*.png\"))))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-10-02T01:48:17.766908Z","iopub.execute_input":"2026-10-02T01:48:17.767344Z","iopub.status.idle":"2026-10-02T01:48:26.849557Z","shell.execute_reply.started":"2026-10-02T01:48:17.767311Z","shell.execute_reply":"2026-10-02T01:48:26.848754Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!git clone 'https://github.com/Divesh455/DrishtiAI'","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-10-02T01:53:19.414549Z","iopub.execute_input":"2026-10-02T01:53:19.415547Z","iopub.status.idle":"2026-10-02T01:53:21.330532Z","shell.execute_reply.started":"2026-10-02T01:53:19.415513Z","shell.execute_reply":"2026-10-02T01:53:21.329744Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%cd /kaggle/working/DrishtiAI\n!pip install -r backend/requirements.txt","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-10-02T01:53:50.624026Z","iopub.execute_input":"2026-10-02T01:53:50.625091Z","iopub.status.idle":"2026-10-02T01:58:14.268279Z","shell.execute_reply.started":"2026-10-02T01:53:50.62504Z","shell.execute_reply":"2026-10-02T01:58:14.267111Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from pathlib import Path\nimport os\n\ndata = Path(\"/kaggle/input/competitions/aptos2019-blindness-detection\")\n\nprint(\"CSV:\", (data / \"train.csv\").exists())\nprint(\"Images:\", (data / \"train_images\").exists())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-10-02T02:00:21.139338Z","iopub.execute_input":"2026-10-02T02:00:21.140136Z","iopub.status.idle":"2026-10-02T02:00:21.150917Z","shell.execute_reply.started":"2026-10-02T02:00:21.140096Z","shell.execute_reply":"2026-10-02T02:00:21.150098Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"project_data = Path(\"/kaggle/working/DrishtiAI/data/raw\")\nproject_data.mkdir(parents=True, exist_ok=True)\n\nos.symlink(\n    data / \"train.csv\",\n    project_data / \"train.csv\"\n)\n\nos.symlink(\n    data / \"train_images\",\n    project_data / \"train_images\"\n)\n\nprint(\"Dataset connected\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-10-02T02:00:36.703387Z","iopub.execute_input":"2026-10-02T02:00:36.703917Z","iopub.status.idle":"2026-10-02T02:00:36.710467Z","shell.execute_reply.started":"2026-10-02T02:00:36.703881Z","shell.execute_reply":"2026-10-02T02:00:36.709698Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%cd /kaggle/working/DrishtiAI\n\n!python training/train.py","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-10-02T02:04:15.327608Z","iopub.execute_input":"2026-10-02T02:04:15.328119Z","iopub.status.idle":"2026-10-02T03:01:31.760273Z","shell.execute_reply.started":"2026-10-02T02:04:15.328089Z","shell.execute_reply":"2026-10-02T03:01:31.75909Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from pathlib import Path\nimport shutil\n\nsource = Path(\n    \"/kaggle/working/DrishtiAI/weights/dr_model_focal.pth\"\n)\n\noutput_dir = Path(\"/kaggle/working/output\")\n\nif output_dir.exists():\n    shutil.rmtree(output_dir)\n\noutput_dir.mkdir(parents=True)\n\ndestination = output_dir / \"dr_model_focal.pth\"\n\nshutil.copy2(source, destination)\n\nprint(\"Model copied successfully\")\nprint(\"Path:\", destination)\nprint(\"Size:\", round(destination.stat().st_size / (1024 * 1024), 2), \"MB\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-10-02T03:04:01.225084Z","iopub.execute_input":"2026-10-02T03:04:01.226029Z","iopub.status.idle":"2026-10-02T03:04:01.242099Z","shell.execute_reply.started":"2026-10-02T03:04:01.225978Z","shell.execute_reply":"2026-10-02T03:04:01.241359Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import torch\n\np = \"/kaggle/working/output/dr_model_focal.pth\"\n\ncheckpoint = torch.load(\n    p,\n    map_location=\"cpu\",\n    weights_only=False\n)\n\nprint(\"Epoch:\", checkpoint.get(\"epoch\"))\nprint(\"Best Macro-F1:\", checkpoint.get(\"best_val_macro_f1\"))\nprint(\"Best Accuracy:\", checkpoint.get(\"best_val_accuracy\"))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-10-02T03:04:22.073971Z","iopub.execute_input":"2026-10-02T03:04:22.07427Z","iopub.status.idle":"2026-10-02T03:04:22.136638Z","shell.execute_reply.started":"2026-10-02T03:04:22.074246Z","shell.execute_reply":"2026-10-02T03:04:22.135637Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from pathlib import Path\nimport shutil\n\nsource = Path(\"/kaggle/working/DrishtiAI/weights/dr_model_focal.pth\")\noutput_dir = Path(\"/kaggle/working/output\")\n\noutput_dir.mkdir(parents=True, exist_ok=True)\n\ndestination = output_dir / \"dr_model_focal.pth\"\n\nshutil.copy2(source, destination)\n\nprint(\"Model copied successfully\")\nprint(\"Path:\", destination)\nprint(\"Size:\", round(destination.stat().st_size / (1024 * 1024), 2), \"MB\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-10-02T03:08:12.838928Z","iopub.execute_input":"2026-10-02T03:08:12.839928Z","iopub.status.idle":"2026-10-02T03:08:12.859899Z","shell.execute_reply.started":"2026-10-02T03:08:12.839894Z","shell.execute_reply":"2026-10-02T03:08:12.859065Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import torch\n\np = \"/kaggle/working/output/dr_model_focal.pth\"\n\ncheckpoint = torch.load(\n    p,\n    map_location=\"cpu\",\n    weights_only=False\n)\n\nprint(\"Epoch:\", checkpoint.get(\"epoch\"))\nprint(\"Best Macro-F1:\", checkpoint.get(\"best_val_macro_f1\"))\nprint(\"Best Accuracy:\", checkpoint.get(\"best_val_accuracy\"))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-10-02T03:08:46.50918Z","iopub.execute_input":"2026-10-02T03:08:46.510022Z","iopub.status.idle":"2026-10-02T03:08:46.553111Z","shell.execute_reply.started":"2026-10-02T03:08:46.509981Z","shell.execute_reply":"2026-10-02T03:08:46.552411Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from pathlib import Path\nimport shutil\n\nsource = Path(\"/kaggle/working/DrishtiAI/weights/dr_model_focal.pth\")\noutput_dir = Path(\"/kaggle/working/output\")\n\noutput_dir.mkdir(parents=True, exist_ok=True)\n\ndestination = output_dir / \"dr_model_focal.pth\"\n\nshutil.copy2(source, destination)\n\nprint(\"========================================\")\nprint(\"MODEL EXPORT COMPLETE\")\nprint(\"========================================\")\nprint(\"Source:\", source)\nprint(\"Output:\", destination)\nprint(\"Size:\", round(destination.stat().st_size / (1024 * 1024), 2), \"MB\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-10-02T03:21:40.516156Z","iopub.execute_input":"2026-10-02T03:21:40.516669Z","iopub.status.idle":"2026-10-02T03:21:40.539562Z","shell.execute_reply.started":"2026-10-02T03:21:40.516638Z","shell.execute_reply":"2026-10-02T03:21:40.538683Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from IPython.display import FileLink\n\nFileLink(\"/kaggle/working/output/dr_model_focal.pth\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-10-02T03:28:03.357689Z","iopub.execute_input":"2026-10-02T03:28:03.358327Z","iopub.status.idle":"2026-10-02T03:28:03.365938Z","shell.execute_reply.started":"2026-10-02T03:28:03.358296Z","shell.execute_reply":"2026-10-02T03:28:03.364942Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import shutil\nfrom IPython.display import FileLink\n\nsource = \"/kaggle/working/output/dr_model_focal.pth\"\nzip_path = \"/kaggle/working/dr_model_focal\"\n\nshutil.make_archive(\n    zip_path,\n    \"zip\",\n    root_dir=\"/kaggle/working/output\",\n    base_dir=\"dr_model_focal.pth\"\n)\n\nFileLink(\"/kaggle/working/dr_model_focal.zip\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-10-02T03:28:36.36341Z","iopub.execute_input":"2026-10-02T03:28:36.364258Z","iopub.status.idle":"2026-10-02T03:28:37.263219Z","shell.execute_reply.started":"2026-10-02T03:28:36.364225Z","shell.execute_reply":"2026-10-02T03:28:37.262445Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}