Spaces:
Sleeping
Sleeping
File size: 3,339 Bytes
8bbb872 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | {
"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"
]
}
]
} |