-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_input_example.py
More file actions
129 lines (111 loc) · 4.64 KB
/
Copy pathdata_input_example.py
File metadata and controls
129 lines (111 loc) · 4.64 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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
###################################################################################################
### Med Phys: Medical Imaging Deep Learning for Predicting Patient Response to Treatment
### @Author: Laik Ruetten
### @git: https://github.com/ruetten/medphys_deep_learning
###################################################################################################
### Inputs: PET imaging (nifti file format)
### Outputs: progression free survival measured in months.
### alternatively, calssification problem of 'survivor' or 'regressor' past 25(?) months
### Victor is using what he calls hand-crafted features and predicts progression free survival.
### Brayden would like to attempt the same thing but use the raw Image data as input.
### We predict that hand-crafted will do better for smaller dataset
### while deep-learning will work better with more data
### I'm worried about the small size of the dataset being only 34 out of a total of 100
###################################################################################################
import logging
import sys
import os
import numpy as np
import torch
import monai
from monai.data import ImageDataset, DataLoader
import nibabel
# nibable - nifti to numpy
# monai
### Preprocess data
# - equal voxel spacing in all three cardinal directions
# - resample to an isotropic space
# - normalization
# - Brayden is doing this step externally
### Data Generator
# - loads training data with ground truth
# - determine splits between training and test
def main():
# monai.config.print_config()
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
data_path = os.sep.join(
["W:", "_Data", "NET_DL_Predict", "data", "dynamic", "processed_data", "baseline", "processed_PET",
"bodyCrop_vox4p5xy8p0z_Standardized"])
images = [
"NET01_2018_02_26_crop_rawVox.nii.gz",
"NET02_2018_04_05_crop_rawVox.nii.gz",
"NET03_2018_02_15_crop_rawVox.nii.gz",
"NET04_2017_10_03_crop_rawVox.nii.gz",
"NET05_2018_04_03_crop_rawVox.nii.gz",
"NET07_2018_07_16_crop_rawVox.nii.gz",
"NET08_2018_10_08_crop_rawVox.nii.gz",
"NET09_2017_08_01_crop_rawVox.nii.gz",
"NET11_2017_12_11_crop_rawVox.nii.gz",
"NET14_2018_02_08_crop_rawVox.nii.gz",
"NET15_2019_05_22_crop_rawVox.nii.gz",
"NET18_2018_05_16_crop_rawVox.nii.gz",
"NET19_2020_11_12_crop_rawVox.nii.gz",
"NET20_2018_09_20_crop_rawVox.nii.gz",
"NET23_2019_04_05_crop_rawVox.nii.gz",
"NET29_2017_10_10_crop_rawVox.nii.gz",
"NET30_2019_09_12_crop_rawVox.nii.gz",
"NET31_2019_11_01_crop_rawVox.nii.gz",
"NET41_2020_03_06_crop_rawVox.nii.gz",
"NET45_2019_04_17_crop_rawVox.nii.gz",
"NET47_2018_12_14_crop_rawVox.nii.gz",
"NET53_2018_10_02_crop_rawVox.nii.gz",
"NET54_2018_08_20_crop_rawVox.nii.gz",
"NET55_2019_10_18_crop_rawVox.nii.gz",
"NET70_2020_12_15_crop_rawVox.nii.gz",
"NET73_2021_01_26_crop_rawVox.nii.gz",
"NET74_2019_11_26_crop_rawVox.nii.gz",
"NET77_2021_02_23_crop_rawVox.nii.gz",
"NET78_2021_04_12_crop_rawVox.nii.gz",
"NET85_2021_12_02_crop_rawVox.nii.gz",
"NET86_2020_11_13_crop_rawVox.nii.gz",
"RP01_tp01_crop_rawVox.nii.gz",
"RP03_tp01_crop_rawVox.nii.gz",
"RP08_tp01_crop_rawVox.nii.gz",
"RP10_tp02_crop_rawVox.nii.gz",
"RP11_tp01_crop_rawVox.nii.gz"
]
images = [os.sep.join([data_path, f]) for f in images]
# TODO labels are not correct
labels = np.array([0, 0, 0,
0, 0, 0,
0, 0, 0,
0, 0, 0,
0, 0, 0,
0, 0, 0,
1, 1, 1,
1, 1, 1,
1, 1, 1,
1, 1, 1,
1, 1, 1,
1, 1, 1], dtype=np.int64)
# TODO hyperparameters
check_ds = ImageDataset(image_files=images, labels=labels)
check_loader = DataLoader(check_ds, batch_size=2, num_workers=2, pin_memory=torch.cuda.is_available())
im, label = monai.utils.misc.first(check_loader)
print(type(im), im.shape, label)
### Separate data generator for validation
### Set training parameters
# - Epochs and training iterations
### Create/Define/Load model
# monai has some popular models
# - ResNet
# - DenseNet
# - Inception - might not be in Monai
# - Some transformers
# - have some sort of master script, difference between is different architectures
### Train
# Good to save an ongoing plot for each epoch
### Validate
### Test
if __name__ == "__main__":
main()