{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":1786261,"sourceType":"datasetVersion","datasetId":1061853},{"sourceId":10966806,"sourceType":"datasetVersion","datasetId":6811680}],"dockerImageVersionId":30918,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nimport torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nimport os\nimport nibabel as nib\nimport numpy as np\nfrom torch.utils.data import Dataset, DataLoader\nimport torchvision.transforms as transforms\nfrom tqdm import tqdm\nimport cv2 as cv","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-09T18:43:18.694647Z","iopub.execute_input":"2025-03-09T18:43:18.695203Z","iopub.status.idle":"2025-03-09T18:43:26.539568Z","shell.execute_reply.started":"2025-03-09T18:43:18.695148Z","shell.execute_reply":"2025-03-09T18:43:26.538414Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"label1=pd.read_csv(\"/kaggle/input/label-for-eyeq/Label_EyeQ_train (1).csv\").drop(columns='Unnamed: 0')\nlabel2=pd.read_csv(\"/kaggle/input/label-for-eyeq/Label_EyeQ_test (1).csv\").drop(columns='Unnamed: 0')\n\nlabel=pd.concat([label1, label2], ignore_index=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-09T18:43:26.540907Z","iopub.execute_input":"2025-03-09T18:43:26.541678Z","iopub.status.idle":"2025-03-09T18:43:26.638122Z","shell.execute_reply.started":"2025-03-09T18:43:26.541634Z","shell.execute_reply":"2025-03-09T18:43:26.636863Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"label.columns","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-09T18:43:26.640194Z","iopub.execute_input":"2025-03-09T18:43:26.640629Z","iopub.status.idle":"2025-03-09T18:43:26.647790Z","shell.execute_reply.started":"2025-03-09T18:43:26.640586Z","shell.execute_reply":"2025-03-09T18:43:26.646592Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"class loader(Dataset):\n    def __init__(self, df, root_path, transforms=None):\n        self.df = df\n        self.root_path = root_path\n        self.train_path = root_path+\"/train_images_768/train/\"\n        self.test_path = root_path+\"/test_images_768/test/\"\n        self.test_paths = os.listdir(self.test_path)\n        self.train_paths = os.listdir(self.train_path)\n        self.all_paths = self.train_paths+self.test_paths\n        self.transforms = transforms\n    def __len__(self):\n        return len(self.df)\n    def __getitem__(self, idx):\n        img_name, label, _ = self.df.iloc[idx]\n        if os.path.exists(self.train_path+img_name):\n            img_path = self.train_path+img_name\n        elif os.path.exists(self.test_path+img_name):\n            img_path = self.test_path+img_name\n        else:\n            print(\"no file exists for image_name\", img_name)\n            return img_name\n        # return 0\n        \n        image = cv.imread(img_path)\n        if self.transforms:\n            image = self.transforms(image)\n        return torch.tensor(image), torch.tensor(label)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-09T18:46:28.314543Z","iopub.execute_input":"2025-03-09T18:46:28.315066Z","iopub.status.idle":"2025-03-09T18:46:28.325842Z","shell.execute_reply.started":"2025-03-09T18:46:28.315019Z","shell.execute_reply":"2025-03-09T18:46:28.324400Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"transform = transforms.Compose([\n    transforms.ToTensor(),\n    transforms.Resize((768, 768), antialias=True)\n])\n\nroot_path = \"/kaggle/input/diabetic-retinopathy-blindness-detection-c-data\"\ndataset = loader(label, root_path, transform)\ndataloader = DataLoader(dataset, shuffle=False, batch_size=4)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-09T18:46:30.153702Z","iopub.execute_input":"2025-03-09T18:46:30.154060Z","iopub.status.idle":"2025-03-09T18:46:30.193115Z","shell.execute_reply.started":"2025-03-09T18:46:30.154033Z","shell.execute_reply":"2025-03-09T18:46:30.191799Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for i, j in dataloader:\n    print(i.shape)\n    break","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-09T18:46:37.520838Z","iopub.execute_input":"2025-03-09T18:46:37.521239Z","iopub.status.idle":"2025-03-09T18:46:38.383564Z","shell.execute_reply.started":"2025-03-09T18:46:37.521205Z","shell.execute_reply":"2025-03-09T18:46:38.382396Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}