-
Notifications
You must be signed in to change notification settings - Fork 22
/
make_submission.py
245 lines (231 loc) · 9.68 KB
/
make_submission.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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
import os
import nibabel as nib
import numpy as np
settings = {
'ensemble': {
'models': ['deepmedic_ce_50_50_c25_all', 'deepmedic_ce_50_50_c25_all_noaug', 'unet_dice_all', 'deepmedic_ce_all', 'unet_ce_hard_per_im', 'unet_ce_hard', 'deepmedic_ce_60_80_100_b50_mb50_all', 'deepmedic_ce_90_120_150_b50_mb50_all'],
'weights': [0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125],
'note': 'integrate all models',
},
'ensemble_9': {
'models': ['deepmedic_ce_50_50_c25_all', 'deepmedic_ce_50_50_c25_all_noaug', 'unet_dice_all', 'deepmedic_ce_all', 'unet_ce_hard_per_im', 'unet_ce_hard', 'deepmedic_ce_60_80_100_b50_mb50_all', 'deepmedic_ce_90_120_150_b50_mb50_all', 'deepmedic_ce_c25_60_80_100_b50_mb50_all'],
'weights': [1, 1, 1, 1, 1, 1, 1, 1, 1],
'note': 'integrate all 9 models',
},
'ensemble_26': {
'models': [
'deepmedic_ce_50_50_c25_all',
'deepmedic_ce_50_50_c25_all_noaug',
'unet_dice_all',
'deepmedic_ce_all',
'unet_ce_hard_per_im',
'unet_ce_hard',
'deepmedic_ce_60_80_100_b50_mb50_all',
'deepmedic_ce_90_120_150_b50_mb50_all',
'deepmedic_ce_c25_60_80_100_b50_mb50_all',
'deepmedic_ce_c25_90_120_150_b50_mb50_all',
'deepmedic_ce_c25_45_60_75_b50_mb50_all',
'deepmedic_ce_c25_75_100_125_b50_mb50_all',
'deepmedic_ce_all_aug',
'deepmedic_ce_50_50_all',
'deepmedic_ce_50_50_all_aug',
'deepmedic_ce_22x18x6_all_aug',
'deepmedic_ce_28x20x12_all_aug',
'deepmedic_ce_60_80_100_b50_mb50_all_aug',
'deepmedic_ce_90_120_150_b50_mb50_all_aug',
'deepmedic_ce_75_100_125_b50_mb50_all_aug',
'deepmedic_ce_75_100_125_b50_mb50_all',
'deepmedic_ce_45_60_75_b50_mb50_all',
'munet_dice_all',
'unet_dice_c25_all',
'unet_ce_hard_c25',
'unet_ce_hard_per_im_c25',
],
'weights': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
'note': 'integrate all 26 models',
},
'deepmedic_c25': { #6
'models': ['deepmedic_ce_50_50_c25_all'],
'weights': [1.0],
'note': 'deepmedic with all training datasets and Harvard Oxford Subcortical Atlas',
},
'deepmedic_c25_noaug': { #4
'models': ['deepmedic_ce_50_50_c25_all_noaug'],
'weights': [1.0],
'note': 'deepmedic with all training datasets and Harvard Oxford Subcortical Atlas without data augmentation',
},
'unet': { #21
'models': ['unet_dice_all'],
'weights': [1.0],
'note': 'unet',
},
'deepmedic_ce_all': { #1
'models' :['deepmedic_ce_all'],
'weights':[1.0],
'note': 'deepmedic with all training datasets',
},
'unet_ce_hard_per_im': { #25
'models': ['unet_ce_hard_per_im'],
'weights': [1.0],
'note': 'unet cross entropy loss hard mining per image',
},
'unet_ce_hard': { #23
'models': ['unet_ce_hard'],
'weights': [1.0],
'note': 'unet cross entropy loss hard mining',
},
'deepmedic_double': { #9
'models': ['deepmedic_ce_60_80_100_b50_mb50_all'],
'weights': [1.0],
'note': 'deepmedic with double convolutional kernels',
},
'deepmedic_triple': { #15
'models': ['deepmedic_ce_90_120_150_b50_mb50_all'],
'weights': [1.0],
'note': 'deepmedic with triple convolutional kernels',
} ,
'deepmedic_double_c25': { #11
'models': ['deepmedic_ce_c25_60_80_100_b50_mb50_all'],
'weights': [1.0],
'note': 'deepmedic with double convolutional kernels and 21 brain parcellatio channels',
} ,
'deepmedic_triple_c25_aug': { #17
'models': ['deepmedic_ce_c25_90_120_150_b50_mb50_all'],
'weights': [1.0],
'note': 'deepMedic Triple with 21 BPs and data augmentation',
} ,
'deepmedic_15_c25_aug': { #8
'models': ['deepmedic_ce_c25_45_60_75_b50_mb50_all'],
'weights': [1.0],
'note': 'Deepmedic with 1.5 kernels 21 BPs and data augment',
} ,
'deepmedic_25_c25_aug': { #14
'models': ['deepmedic_ce_c25_75_100_125_b50_mb50_all'],
'weights': [1.0],
'note': 'Deepmedic with 2.5 kernels 21 BPs and data augment',
} ,
'deepmedic_ce_all_aug': { #2
'models': ['deepmedic_ce_all_aug'],
'weights': [1.0],
'note': 'Deepmedic with data augment',
} ,
'deepmedic_ce_50_50_all': { #3
'models': ['deepmedic_ce_50_50_all'],
'weights': [1.0],
'note': 'Deepmedic mb50 b 50 without data augment',
} ,
'deepmedic_ce_50_50_all_aug': { #5
'models': ['deepmedic_ce_50_50_all_aug'],
'weights': [1.0],
'note': 'Deepmedic mb50 b 50 with data augment',
} ,
'deepmedic_ce_22x18x6_all_aug': { #18
'models': ['deepmedic_ce_22x18x6_all_aug'],
'weights': [1.0],
'note': 'deepmedic ce with 22x18x6 and data augment',
} ,
'deepmedic_ce_28x20x12_all_aug': { #19
'models': ['deepmedic_ce_28x20x12_all_aug'],
'weights': [1.0],
'note': 'deepmedic ce with 28x20x12 and data augment',
} ,
'deepmedic_ce_60_80_100_b50_mb50_all_aug': { #10
'models': ['deepmedic_ce_60_80_100_b50_mb50_all_aug'],
'weights': [1.0],
'note': 'deepmedic double with data aug',
} ,
'deepmedic_ce_90_120_150_b50_mb50_all_aug': { #16
'models': ['deepmedic_ce_90_120_150_b50_mb50_all_aug'],
'weights': [1.0],
'note': 'deepmedic triple with data aug',
} ,
'deepmedic_ce_75_100_125_b50_mb50_all_aug': { #13
'models': ['deepmedic_ce_75_100_125_b50_mb50_all_aug'],
'weights': [1.0],
'note': 'deepmedic 2.5 with data aug',
} ,
'deepmedic_ce_75_100_125_b50_mb50_all': { #12
'models': ['deepmedic_ce_75_100_125_b50_mb50_all'],
'weights': [1.0],
'note': 'deepmedic 2.5 without data aug',
} ,
'deepmedic_ce_45_60_75_b50_mb50_all': { #7
'models': ['deepmedic_ce_45_60_75_b50_mb50_all'],
'weights': [1.0],
'note': 'deepmedic 1.5 without data aug',
} ,
'munet_dice_all': { #20
'models': ['munet_dice_all'],
'weights': [1.0],
'note': 'modified 3D Unet with Dice loss',
} ,
'unet_dice_c25_all': { #22
'models': ['unet_dice_c25_all'],
'weights': [1.0],
'note': 'Unet with Dice Loss and BPs',
} ,
'unet_ce_hard_c25': { #24
'models': ['unet_ce_hard_c25'],
'weights': [1.0],
'note': 'Unet with ce and BPs',
} ,
'unet_ce_hard_per_im_c25': { #26
'models': ['unet_ce_hard_per_im_c25'],
'weights': [1.0],
'note': 'Unet with ce and BPs',
} ,
}
root = '/usr/data/pkao/brats2018/validation'
file_list = os.path.join(root, 'test.txt')
names = open(file_list).read().splitlines()
root = './output'
#submission_name = 'deepmedic'
#submission_name = 'deepmedic_unet'
#submission_name = 'deepmedic_c25_noaug'
#submission_name = 'deepmedic_ce_all'
#submission_name = 'unet'
#submission_name = 'unet_ce_hard_per_im'
#submission_name= 'unet_ce_hard'
#submission_name='deepmedic_double'
#submission_name='deepmedic_triple'
#submission_name='deepmedic_double_c25'
#submission_name= 'ensemble_9'
#submission_name = 'deepmedic_triple_c25_aug'
#submission_name = 'deepmedic_15_c25_aug'
#submission_name = 'deepmedic_25_c25_aug'
#submission_name ='deepmedic_ce_all_aug'
#submission_name = 'deepmedic_ce_50_50_all'
#submission_name = 'deepmedic_ce_50_50_all_aug'
#submission_name = 'deepmedic_ce_22x18x6_all_aug'
#submission_name = 'deepmedic_ce_28x20x12_all_aug'
#submission_name = 'deepmedic_ce_60_80_100_b50_mb50_all_aug'
#submission_name = 'deepmedic_ce_90_120_150_b50_mb50_all_aug'
#submission_name ='deepmedic_ce_75_100_125_b50_mb50_all_aug'
#submission_name ='deepmedic_ce_75_100_125_b50_mb50_all'
#submission_name = 'ensemble_21'
#submission_name = 'deepmedic_ce_45_60_75_b50_mb50_all'
#submission_name = 'ensemble_22'
#submission_name = 'munet_dice_all'
#submission_name = 'ensemble_23_geo'
#submission_name = 'unet_dice_c25_all'
#submission_name = 'unet_ce_hard_c25'
#submission_name = 'unet_ce_hard_per_im_c25'
submission_name = 'ensemble_26'
models = settings[submission_name]['models']
weights = settings[submission_name]['weights'] or [1.0] * len(models)
submission_dir = os.path.join('submissions', submission_name + '_uint8')
if not os.path.exists(submission_dir):
os.makedirs(submission_dir)
for name in names:
oname = os.path.join(submission_dir, name + '.nii.gz')
preds = 0
for k, model in enumerate(models):
fname = os.path.join(root, models[k], 'test', name + '_preds.npy')
# geometric mean
#preds += weights[k] * np.log(np.load(fname)+0.001)
# arithmetic mean
preds += weights[k] * np.load(fname)
##preds += weights[k] * (255*np.load(fname)).astype('uint8')
preds = preds.argmax(0).astype('uint8')
img = nib.Nifti1Image(preds, None)
nib.save(img, oname)