@@ -32,10 +32,8 @@ def main(sub_name_dicts, eval_params, intermediate=False, model_dir=None,
32
32
use_cpu = eval_params ['Use_CPU' ]
33
33
if use_cpu is True :
34
34
device = torch .device ("cpu" )
35
- print ('testfunction:device used:' + device )
36
35
else :
37
36
device = torch .device ("cuda" if torch .cuda .is_available () else "cpu" )
38
- print ('testfunction:device used:' + device )
39
37
nclass = eval_params ['Nclass' ]
40
38
num_channels = eval_params ['Numchannels' ]
41
39
@@ -82,72 +80,72 @@ def main(sub_name_dicts, eval_params, intermediate=False, model_dir=None,
82
80
for sub in range (len (sub_name_dicts )):
83
81
if verbose :
84
82
print ('Predicting output for subject ' + str (sub + 1 ) + '...' , flush = True )
85
-
83
+
86
84
test_sub_dict = [sub_name_dicts [sub ]]
87
85
basename = test_sub_dict [0 ]['basename' ]
88
-
86
+
89
87
probs_combined = []
90
88
flair_path = test_sub_dict [0 ]['flair_path' ]
91
89
flair_hdr = nib .load (flair_path ).header
92
- probs_axial = truenet_evaluate .evaluate_truenet (test_sub_dict , model_axial , eval_params , device ,
90
+ probs_axial = truenet_evaluate .evaluate_truenet (test_sub_dict , model_axial , eval_params , device ,
93
91
mode = 'axial' , verbose = verbose )
94
- probs_axial = truenet_data_postprocessing .resize_to_original_size (probs_axial , test_sub_dict ,
92
+ probs_axial = truenet_data_postprocessing .resize_to_original_size (probs_axial , test_sub_dict ,
95
93
plane = 'axial' )
96
94
probs_combined .append (probs_axial )
97
-
95
+
98
96
if intermediate :
99
97
save_path = os .path .join (output_dir ,'Predicted_probmap_truenet_' + basename + '_axial.nii.gz' )
100
98
preds_axial = truenet_data_postprocessing .get_final_3dvolumes (probs_axial , test_sub_dict )
101
99
if verbose :
102
100
print ('Saving the intermediate Axial prediction ...' , flush = True )
103
-
101
+
104
102
newhdr = flair_hdr .copy ()
105
103
newobj = nib .nifti1 .Nifti1Image (preds_axial , None , header = newhdr )
106
- nib .save (newobj , save_path )
107
-
108
- probs_sagittal = truenet_evaluate .evaluate_truenet (test_sub_dict , model_sagittal , eval_params , device ,
104
+ nib .save (newobj , save_path )
105
+
106
+ probs_sagittal = truenet_evaluate .evaluate_truenet (test_sub_dict , model_sagittal , eval_params , device ,
109
107
mode = 'sagittal' , verbose = verbose )
110
- probs_sagittal = truenet_data_postprocessing .resize_to_original_size (probs_sagittal , test_sub_dict ,
108
+ probs_sagittal = truenet_data_postprocessing .resize_to_original_size (probs_sagittal , test_sub_dict ,
111
109
plane = 'sagittal' )
112
110
probs_combined .append (probs_sagittal )
113
-
111
+
114
112
if intermediate :
115
113
save_path = os .path .join (output_dir ,'Predicted_probmap_truenet_' + basename + '_sagittal.nii.gz' )
116
114
preds_sagittal = truenet_data_postprocessing .get_final_3dvolumes (probs_sagittal , test_sub_dict )
117
115
if verbose :
118
116
print ('Saving the intermediate Sagittal prediction ...' , flush = True )
119
-
117
+
120
118
newhdr = flair_hdr .copy ()
121
119
newobj = nib .nifti1 .Nifti1Image (preds_sagittal , None , header = newhdr )
122
- nib .save (newobj , save_path )
123
-
124
- probs_coronal = truenet_evaluate .evaluate_truenet (test_sub_dict , model_coronal , eval_params , device ,
125
- mode = 'coronal' , verbose = verbose )
126
- probs_coronal = truenet_data_postprocessing .resize_to_original_size (probs_coronal , test_sub_dict ,
120
+ nib .save (newobj , save_path )
121
+
122
+ probs_coronal = truenet_evaluate .evaluate_truenet (test_sub_dict , model_coronal , eval_params , device ,
123
+ mode = 'coronal' , verbose = verbose )
124
+ probs_coronal = truenet_data_postprocessing .resize_to_original_size (probs_coronal , test_sub_dict ,
127
125
plane = 'coronal' )
128
126
probs_combined .append (probs_coronal )
129
-
127
+
130
128
if intermediate :
131
129
save_path = os .path .join (output_dir ,'Predicted_probmap_truenet_' + basename + '_coronal.nii.gz' )
132
130
preds_coronal = truenet_data_postprocessing .get_final_3dvolumes (probs_coronal , test_sub_dict )
133
131
if verbose :
134
132
print ('Saving the intermediate Coronal prediction ...' , flush = True )
135
-
133
+
136
134
newhdr = flair_hdr .copy ()
137
135
newobj = nib .nifti1 .Nifti1Image (preds_coronal , None , header = newhdr )
138
- nib .save (newobj , save_path )
139
-
136
+ nib .save (newobj , save_path )
137
+
140
138
probs_combined = np .array (probs_combined )
141
139
prob_mean = np .mean (probs_combined ,axis = 0 )
142
-
140
+
143
141
save_path = os .path .join (output_dir ,'Predicted_probmap_truenet_' + basename + '.nii.gz' )
144
142
pred_mean = truenet_data_postprocessing .get_final_3dvolumes (prob_mean , test_sub_dict )
145
143
if verbose :
146
144
print ('Saving the final prediction ...' , flush = True )
147
145
148
146
newhdr = flair_hdr .copy ()
149
147
newobj = nib .nifti1 .Nifti1Image (pred_mean , None , header = newhdr )
150
- nib .save (newobj , save_path )
151
-
148
+ nib .save (newobj , save_path )
149
+
152
150
if verbose :
153
151
print ('Testing complete for all subjects!' , flush = True )
0 commit comments