-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathdataset.py
25 lines (21 loc) · 843 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
from torch.utils.data import Dataset, DataLoader
import h5py
import numpy as np
import glob
class CTDataset(Dataset):
def __init__(self, datapath, transforms_):
self.datapath = datapath
self.transforms = transforms_
self.samples = ['../..'+x.split('.')[4] for x in glob.glob(self.datapath + '/*.im')]
def __len__(self):
return len(self.samples)
def __getitem__(self, idx):
# print(self.samples[idx])
image = h5py.File(self.samples[idx] + '.im', 'r').get('data')[()]
mask = h5py.File(self.samples[idx] + '.seg', 'r').get('data')[()]
# print(self.samples[idx])
# print(image.shape)
# print(mask.shape)
if self.transforms:
image, mask = self.transforms(image), self.transforms(mask)
return {"A": image, "B": mask}