-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataloader.py
30 lines (23 loc) · 906 Bytes
/
dataloader.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
30
import torch
from torch.utils.data import Dataset
from skimage import io
import pandas as pd
import os
class SphereDataset(Dataset):
def __init__(self, csv_file, root_dir, transform=None):
self.root_dir = root_dir
self.labels = pd.read_csv(self.root_dir+csv_file)
self.transform = transform
def __len__(self):
return len(self.labels)
def __getitem__(self, idx):
if torch.is_tensor(idx):
idx = idx.tolist()
img_name = os.path.join(self.root_dir, self.labels.iloc[idx, 0])
image = io.imread(img_name)
# We are only interested in the center coordinates
center_coordinates = self.labels.iloc[idx, 1:3]
center_coordinates = torch.from_numpy(center_coordinates.to_numpy().astype('float32'))
if self.transform:
image = self.transform(image)
return image, center_coordinates