-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_loading.py
82 lines (64 loc) · 2.24 KB
/
test_loading.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
import tensorflow as tf
import numpy as np
import pandas as pd
import nibabel as nib
def load_io1(path):
ct_path = os.path.join(path, 'CT')
gt_path = os.path.join(path, 'GT/GTV')
ct = np.zeros([512, 512, len(os.listdir(ct_path))])
gt = np.zeros([512, 512, len(os.listdir(ct_path))])
for i, content in enumerate(os.listdir(ct_path)):
slice = nib.load(os.path.join(ct_path, content)).get_fdata()
ct[:, :, i] = slice
for i, content in enumerate(os.listdir(gt_path)):
gt_slice = nib.load(os.path.join(gt_path, content)).get_fdata()
gt[:, :, i] = gt_slice
return ct, gt
def get_predictions():
patients_train = os.listdir('/home/leroy/app/data/Train/')
patients_validation = os.listdir('/home/leroy/app/data/Validation/')
patient_list = []
ct_shape = []
gt_shape = []
gt_max = []
for patient in patients_train:
print(patient)
ct, gt = load_io1(os.path.join('/home/leroy/app/data/Train', patient))
patient_list.append(patient)
ct_shape.append(np.shape(ct))
gt_shape.append(np.shape(gt))
gt_max.append(np.max(gt))
data = {
'Patient': patient_list,
'CT_Shape': ct_shape,
'GT_Shape': gt_shape,
'GT_Max': gt_max
}
df = pd.DataFrame(data=data)
df.to_csv(os.path.join(r'/home/leroy/app/data', 'train_shapes.csv'), index=False)
# Quick and dirty copy. Ugly but works for testing purposes.
patient_list = []
ct_shape = []
gt_shape = []
gt_max = []
for patient in patients_validation:
print(patient)
ct, gt = load_io1(os.path.join('/home/leroy/app/data/Validation', patient))
patient_list.append(patient)
ct_shape.append(np.shape(ct))
gt_shape.append(np.shape(gt))
gt_max.append(np.max(gt))
data = {
'Patient': patient_list,
'CT_Shape': ct_shape,
'GT_Shape': gt_shape,
'GT_Max': gt_max
}
df = pd.DataFrame(data=data)
df.to_csv(os.path.join(r'/home/leroy/app/data', 'validation_shapes.csv'), index=False)
if __name__ == '__main__':
# print(tf.test.gpu_device_name())
print('Starting loading and shapes check')
get_predictions()