forked from soondubu137/Cytometry_PreGating
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataset.py
30 lines (25 loc) · 891 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
30
import os
import random
from PIL import Image
from torch.utils.data import Dataset
import numpy as np
class dataset(Dataset):
def __init__(self, data_dir, transform=None):
self.data_dir = data_dir
self.image_dir = data_dir.iloc[:,0].to_list()
self.mask_dir = data_dir.iloc[:,1].to_list()
self.transform = transform
def __len__(self):
return len(self.data_dir)
def __getitem__(self, index):
img_path = self.image_dir[index]
mask_path = self.mask_dir[index]
image = np.load(img_path,allow_pickle=True).astype('double')
image = image/image.max()
mask = np.load(mask_path,allow_pickle=True).astype('double')
# mask[mask==255] = 1.0
if self.transform is not None:
augmentations = self.transform(image=image, mask=mask)
image = augmentations["image"]
mask = augmentations["mask"]
return image, mask, img_path