{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.12.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceType":"competition","sourceId":14774,"databundleVersionId":875431}],"dockerImageVersionId":31329,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\n\n# This lists all available input files in Kaggle\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2026-03-26T20:58:22.118268Z","iopub.execute_input":"2026-03-26T20:58:22.118565Z","iopub.status.idle":"2026-03-26T20:58:28.734723Z","shell.execute_reply.started":"2026-03-26T20:58:22.118541Z","shell.execute_reply":"2026-03-26T20:58:28.733778Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport cv2\nimport os\nimport tensorflow as tf\n\n# Correct path\nBASE_PATH = '/kaggle/input/competitions/aptos2019-blindness-detection/'\n\n# Load CSV\ndf = pd.read_csv(BASE_PATH + 'train.csv')\n\n# Show first 5 rows\nprint(df.head())\n\n# Total images\nprint(\"\\nTotal images:\", len(df))\n\n# Images per grade\nprint(\"\\nGrade distribution:\")\nprint(df['diagnosis'].value_counts().sort_index())\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-26T21:06:19.268409Z","iopub.execute_input":"2026-03-26T21:06:19.269148Z","iopub.status.idle":"2026-03-26T21:06:19.329790Z","shell.execute_reply.started":"2026-03-26T21:06:19.269107Z","shell.execute_reply":"2026-03-26T21:06:19.328840Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Set path to images folder\nIMAGE_PATH = BASE_PATH + 'train_images/'\n\n# Create a grid to display 5 sample images\nfig, axes = plt.subplots(1, 5, figsize=(20, 4))\n\nfor i in range(5):\n    # Get image filename from CSV\n    img_name = df['id_code'][i] + '.png'\n    img_path = IMAGE_PATH + img_name\n\n    # Load image\n    img = cv2.imread(img_path)\n\n    # Convert BGR to RGB for correct colors\n    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n\n    # Display image\n    axes[i].imshow(img)\n\n    # Show grade as title\n    axes[i].set_title(f\"Grade: {df['diagnosis'][i]}\")\n    axes[i].axis('off')\n\nplt.suptitle('Fundus Image Samples', fontsize=16)\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-26T21:12:21.399998Z","iopub.execute_input":"2026-03-26T21:12:21.400971Z","iopub.status.idle":"2026-03-26T21:12:23.714465Z","shell.execute_reply.started":"2026-03-26T21:12:21.400928Z","shell.execute_reply":"2026-03-26T21:12:23.713626Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"IMG_SIZE = 224  # Standard size for our AI model\n\ndef preprocess_image(img_path):\n    # Load image from disk\n    img = cv2.imread(img_path)\n    # Convert BGR to RGB\n    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n    # Resize to 224x224\n    img = cv2.resize(img, (IMG_SIZE, IMG_SIZE))\n    # Normalize pixels from 0-255 to 0-1\n    img = img / 255.0\n    return img\n\n# Process ALL images\nimages = []\nlabels = []\n\nprint(\"Processing images... please wait!\")\n\nfor i, row in df.iterrows():\n    img_path = IMAGE_PATH + row['id_code'] + '.png'\n    if os.path.exists(img_path):\n        img = preprocess_image(img_path)\n        images.append(img)\n        labels.append(row['diagnosis'])\n\n# Convert to numpy arrays\nimages = np.array(images)\nlabels = np.array(labels)\n\nprint(f\"✅ Done! Total processed: {len(images)}\")\nprint(f\"Image shape: {images.shape}\")","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Check if images were processed correctly\nprint(\"Total images processed:\", len(images))\nprint(\"Total labels:\", len(labels))\nprint(\"Image array shape:\", images.shape)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Check if images were processed correctly\nprint(\"Total images processed:\", len(images))\nprint(\"Total labels:\", len(labels))\nprint(\"Image array shape:\", images.shape)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}