Repository navigation
Expand file tree
/
Copy pathdataset.py
More file actions
39 lines (33 loc) · 1.51 KB
/
Copy pathdataset.py
File metadata and controls
39 lines (33 loc) · 1.51 KB
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
from torch.utils.data import Dataset
import numpy as np
import os
from PIL import Image
class NPY_datasets(Dataset):
def __init__(self, path_Data, config, train=True):
super(NPY_datasets, self)
if train:
images_list = os.listdir(path_Data+'train/images/')
masks_list = os.listdir(path_Data+'train/masks/')
self.data = []
for i in range(len(images_list)):
img_path = path_Data+'train/images/' + images_list[i]
mask_path = path_Data+'train/masks/' + masks_list[i]
self.data.append([img_path, mask_path])
self.transformer = config.train_transformer
else:
images_list = os.listdir(path_Data+'val/images/')
masks_list = os.listdir(path_Data+'val/masks/')
self.data = []
for i in range(len(images_list)):
img_path = path_Data+'val/images/' + images_list[i]
mask_path = path_Data+'val/masks/' + masks_list[i]
self.data.append([img_path, mask_path])
self.transformer = config.test_transformer
def __getitem__(self, indx):
img_path, msk_path = self.data[indx]
img = np.array(Image.open(img_path).convert('RGB'))
msk = np.expand_dims(np.array(Image.open(msk_path).convert('L')), axis=2) / 255
img, msk = self.transformer((img, msk))
return img, msk
def __len__(self):
return len(self.data)