{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [], "gpuType": "T4" }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" }, "accelerator": "GPU" }, "cells": [ { "cell_type": "code", "source": [ "import os\n", "import torch\n", "import torch.nn as nn\n", "import torch.optim as optim\n", "from torch.utils.data import DataLoader\n", "from torchvision import datasets, transforms\n", "\n", "from google.colab import drive\n", "drive.mount('/content/drive')\n", "!cp -r /content/drive/MyDrive/Dataset_clean /content/\n", "\n", "#Verify structure\n", "for split in ['train', 'val', 'test']:\n", " path = f'/content/Dataset_clean/{split}'\n", " classes = os.listdir(path)\n", " total = sum(len(os.listdir(os.path.join(path, c))) for c in classes)\n", " print(f'{split}: {total} images | classes: {classes}')" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "sE1F3em-V5go", "outputId": "2c73a9a6-a198-468c-a2cc-253b2de7cc3f" }, "execution_count": null, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount(\"/content/drive\", force_remount=True).\n" ] } ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "nG2bh66rQ56G" }, "outputs": [], "source": [ "class EyeCNN(nn.Module):\n", " def __init__(self, num_classes=2):\n", " super(EyeCNN, self).__init__()\n", " self.conv_layers = nn.Sequential(\n", " nn.Conv2d(3, 32, 3, 1, 1),\n", " nn.BatchNorm2d(32),\n", " nn.ReLU(),\n", " nn.MaxPool2d(2, 2),\n", "\n", " nn.Conv2d(32, 64, 3, 1, 1),\n", " nn.BatchNorm2d(64),\n", " nn.ReLU(),\n", " nn.MaxPool2d(2, 2),\n", "\n", " nn.Conv2d(64, 128, 3, 1, 1),\n", " nn.BatchNorm2d(128),\n", " nn.ReLU(),\n", " nn.MaxPool2d(2, 2),\n", "\n", " nn.Conv2d(128, 256, 3, 1, 1),\n", " nn.BatchNorm2d(256),\n", " nn.ReLU(),\n", " nn.MaxPool2d(2, 2)\n", " )\n", "\n", " self.fc_layers = nn.Sequential(\n", " nn.AdaptiveAvgPool2d((1, 1)),\n", " nn.Flatten(),\n", " nn.Linear(256, 512),\n", " nn.ReLU(),\n", " nn.Dropout(0.35),\n", " nn.Linear(512, num_classes)\n", " )\n", "\n", " def forward(self, x):\n", " x = self.conv_layers(x)\n", " x = self.fc_layers(x)\n", " return x" ] } ] }