-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataset.py
29 lines (21 loc) · 854 Bytes
/
dataset.py
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
import pandas as pd
import os
import torch
from torch.utils.data import Dataset
from PIL import Image
class GazeDataset(Dataset):
def __init__(self, csv_file, root_dir, transform=None):
self.annotations = pd.read_csv(csv_file)
self.root_dir = root_dir
self.transform = transform
def __len__(self):
return len(self.annotations)
def __getitem__(self, index):
img_path = os.path.join(self.root_dir, self.annotations.iloc[index, 0])
# image = Image.open(img_path).convert('L')
image = Image.open(img_path)
numeric_data = self.annotations.iloc[index, 4:6].values.astype(float)
y_label = torch.tensor(numeric_data, dtype=torch.float)
if self.transform:
image = self.transform(image)
return (image, y_label)