-
Notifications
You must be signed in to change notification settings - Fork 29
/
data_loader.py
59 lines (48 loc) · 1.92 KB
/
data_loader.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
from torch.utils.data.dataset import Dataset
from torchvision import transforms
from skimage import io, transform
from PIL import Image
import os
import numpy as np
class LungSeg(Dataset):
def __init__(self, path='Image/Train/Images', transforms=None):
self.path = path
self.list = os.listdir(self.path)
self.transforms = transforms
def __getitem__(self, index):
# stuff
image_path = 'Image/Train/Images/'
mask_path = 'Mask/Train/Images/'
image = Image.open(image_path+self.list[index])
image = image.convert('RGB')
mask = Image.open(mask_path+self.list[index])
mask = mask.convert('L')
if self.transforms is not None:
image = self.transforms(image)
mask = self.transforms(mask)
# If the transform variable is not empty
# then it applies the operations in the transforms with the order that it is created.
return (image, mask)
def __len__(self):
return len(self.list) # of how many data(images?) you have
class LungSegTest(Dataset):
def __init__(self, path='Image/Test/Images', transforms=None):
self.path = path
self.list = os.listdir(self.path)
self.transforms = transforms
def __getitem__(self, index):
# stuff
image_path = 'Image/Test/Images/'
mask_path = 'Mask/Test/Images/'
image = Image.open(image_path+self.list[index])
image = image.convert('RGB')
mask = Image.open(mask_path+self.list[index])
mask = mask.convert('L')
if self.transforms is not None:
image = self.transforms(image)
mask = self.transforms(mask)
# If the transform variable is not empty
# then it applies the operations in the transforms with the order that it is created.
return (image, mask)
def __len__(self):
return len(self.list)