forked from haozheng-sjtu/3d-airway-segmentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataload_val.py
43 lines (32 loc) · 1.13 KB
/
dataload_val.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Jul 2 11:11:20 2018
@author: zhenghao
"""
import numpy as np
import torch
from torch.utils.data import Dataset,DataLoader
import os
import scipy.ndimage as ndimage
import warnings
warnings.filterwarnings('ignore')
class AirwayData(Dataset):
def __init__(self, path, train = True):
self.path = path
self.path_list = os.listdir(self.path)
self.path_list.sort()
self.datalen = len(self.path_list)//3
self.train = train
def __len__(self):
return self.datalen
def __getitem__(self, idx):
img_path = os.path.join(self.path, self.path_list[3*idx])
label_path = os.path.join(self.path, self.path_list[3*idx+1])
patient = [self.path_list[3*idx].split('_')[0]]
img = np.load(img_path)
img = img[np.newaxis,:]
label = np.load(label_path)
label = label[np.newaxis,:]
return torch.from_numpy(img.astype(np.float32)), torch.from_numpy(label.astype(np.float32)), \
torch.from_numpy(img.astype(np.float32)), patient