-
Notifications
You must be signed in to change notification settings - Fork 3
/
datasets.py
74 lines (62 loc) · 2.17 KB
/
datasets.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
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
import torch.utils.data as data
from PIL import Image
import numpy as np
import pandas as pd
import os
import torch
class OLIVES(data.Dataset):
def __init__(self,df, img_dir, transforms):
self.img_dir = img_dir
self.transforms = transforms
self.df = pd.read_csv(df)
def __len__(self):
return len(self.df)
def __getitem__(self, idx):
path = self.img_dir + self.df.iloc[idx,0]
image = Image.open(path).convert("L")
image = np.array(image)
image = Image.fromarray(image)
image = self.transforms(image)
b1 = self.df.iloc[idx,1]
b2 = self.df.iloc[idx,2]
b3 = self.df.iloc[idx,3]
b4 = self.df.iloc[idx, 4]
b5 = self.df.iloc[idx, 5]
b6 = self.df.iloc[idx, 6]
bio_tensor = torch.tensor([b1, b2, b3, b4, b5, b6])
return image, bio_tensor
class RECOVERY(data.Dataset):
def __init__(self,df, img_dir, transforms):
self.img_dir = img_dir
self.transforms = transforms
self.df = pd.read_csv(df)
def __len__(self):
return len(self.df)
def __getitem__(self, idx):
path = self.img_dir + self.df.iloc[idx,0]
image = Image.open(path).convert("L")
image = np.array(image)
image = Image.fromarray(image)
image = self.transforms(image)
return image
class RECOVERY_TEST(data.Dataset):
def __init__(self,df, img_dir, transforms):
self.img_dir = img_dir
self.transforms = transforms
self.df = pd.read_csv(df)
def __len__(self):
return len(self.df)
def __getitem__(self, idx):
path = self.img_dir + self.df.iloc[idx,0]
image = Image.open(path).convert("L")
image = np.array(image)
image = Image.fromarray(image)
image = self.transforms(image)
b1 = self.df.iloc[idx,1]
b2 = self.df.iloc[idx,2]
b3 = self.df.iloc[idx,3]
b4 = self.df.iloc[idx, 4]
b5 = self.df.iloc[idx, 5]
b6 = self.df.iloc[idx, 6]
bio_tensor = torch.tensor([b1, b2, b3, b4, b5, b6])
return image, bio_tensor