Skip to content

Commit d896dd5

Browse files
Add Lung & Tumor datasets
1 parent 0e30f5a commit d896dd5

32 files changed

+5193
-66
lines changed

eval_synapse.sh

-15
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/bin/sh
22

3-
DATASET_PATH=DATASET
4-
CHECKPOINT_PATH=unetr_pp/evaluation/unetr_pp_acdc_checkpoint
3+
DATASET_PATH=../DATASET_Acdc
4+
CHECKPOINT_PATH=../unetr_pp/evaluation/unetr_pp_acdc_checkpoint
55

6-
export PYTHONPATH=./
6+
export PYTHONPATH=.././
77
export RESULTS_FOLDER="$CHECKPOINT_PATH"
88
export unetr_pp_preprocessed="$DATASET_PATH"/unetr_pp_raw/unetr_pp_raw_data/Task01_ACDC
99
export unetr_pp_raw_data_base="$DATASET_PATH"/unetr_pp_raw
1010

11-
python unetr_pp/run/run_training.py 3d_fullres unetr_pp_trainer_acdc 1 0 -val
11+
python ../unetr_pp/run/run_training.py 3d_fullres unetr_pp_trainer_acdc 1 0 -val
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
DATASET_PATH=../DATASET_Lungs
4+
CHECKPOINT_PATH=../unetr_pp/evaluation/unetr_pp_lung_checkpoint
5+
6+
export PYTHONPATH=.././
7+
export RESULTS_FOLDER="$CHECKPOINT_PATH"
8+
export unetr_pp_preprocessed="$DATASET_PATH"/unetr_pp_raw/unetr_pp_raw_data/Task06_Lung
9+
export unetr_pp_raw_data_base="$DATASET_PATH"/unetr_pp_raw
10+
11+
python ../unetr_pp/run/run_training.py 3d_fullres unetr_pp_trainer_lung 6 0 -val
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
DATASET_PATH=../DATASET_Synapse
4+
CHECKPOINT_PATH=../unetr_pp/evaluation/unetr_pp_synapse_checkpoint
5+
6+
export PYTHONPATH=.././
7+
export RESULTS_FOLDER="$CHECKPOINT_PATH"
8+
export unetr_pp_preprocessed="$DATASET_PATH"/unetr_pp_raw/unetr_pp_raw_data/Task02_Synapse
9+
export unetr_pp_raw_data_base="$DATASET_PATH"/unetr_pp_raw
10+
11+
python ../unetr_pp/run/run_training.py 3d_fullres unetr_pp_trainer_synapse 2 0 -val
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
3+
DATASET_PATH=../DATASET_Tumor
4+
5+
export PYTHONPATH=.././
6+
export RESULTS_FOLDER=../unetr_pp/evaluation/unetr_pp_tumor_checkpoint
7+
export unetr_pp_preprocessed="$DATASET_PATH"/unetr_pp_raw/unetr_pp_raw_data/Task03_tumor
8+
export unetr_pp_raw_data_base="$DATASET_PATH"/unetr_pp_raw
9+
10+
11+
# Only for Tumor, it is recommended to train unetr_plus_plus first, and then use the provided checkpoint to evaluate. It might raise issues regarding the pickle files if you evaluated without training
12+
13+
python ../unetr_pp/inference/predict_simple.py -i ../unetr_plus_plus/DATASET_Tumor/unetr_pp_raw/unetr_pp_raw_data/Task003_tumor/imagesTs -o ../unetr_plus_plus/unetr_pp/evaluation/unetr_pp_tumor_checkpoint/inferTs -m 3d_fullres -t 3 -f 0 -chk model_final_checkpoint -tr unetr_pp_trainer_tumor
14+
15+
16+
python ../unetr_pp/inference_tumor.py 0
17+

run_evaluation_synapse.sh

-11
This file was deleted.

run_training_acdc.sh

-10
This file was deleted.

run_training_synapse.sh

-10
This file was deleted.

training_scripts/run_training_acdc.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
DATASET_PATH=../DATASET_Acdc
4+
5+
export PYTHONPATH=.././
6+
export RESULTS_FOLDER=../output_acdc
7+
export unetr_pp_preprocessed="$DATASET_PATH"/unetr_pp_raw/unetr_pp_raw_data/Task01_ACDC
8+
export unetr_pp_raw_data_base="$DATASET_PATH"/unetr_pp_raw
9+
10+
python ../unetr_pp/run/run_training.py 3d_fullres unetr_pp_trainer_acdc 1 0

training_scripts/run_training_lung.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
DATASET_PATH=../DATASET_Lungs
4+
5+
export PYTHONPATH=.././
6+
export RESULTS_FOLDER=../output_lung
7+
export unetr_pp_preprocessed="$DATASET_PATH"/unetr_pp_raw/unetr_pp_raw_data/Task06_Lung
8+
export unetr_pp_raw_data_base="$DATASET_PATH"/unetr_pp_raw
9+
10+
python ../unetr_pp/run/run_training.py 3d_fullres unetr_pp_trainer_lung 6 0
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
DATASET_PATH=../DATASET_Synapse
4+
5+
export PYTHONPATH=.././
6+
export RESULTS_FOLDER=../output_synapse
7+
export unetr_pp_preprocessed="$DATASET_PATH"/unetr_pp_raw/unetr_pp_raw_data/Task02_Synapse
8+
export unetr_pp_raw_data_base="$DATASET_PATH"/unetr_pp_raw
9+
10+
python ../unetr_pp/run/run_training.py 3d_fullres unetr_pp_trainer_synapse 2 0
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
DATASET_PATH=../DATASET_Tumor
4+
5+
export PYTHONPATH=.././
6+
export RESULTS_FOLDER=../output_tumor
7+
export unetr_pp_preprocessed="$DATASET_PATH"/unetr_pp_raw/unetr_pp_raw_data/Task03_tumor
8+
export unetr_pp_raw_data_base="$DATASET_PATH"/unetr_pp_raw
9+
10+
python ../unetr_pp/run/run_training.py 3d_fullres unetr_pp_trainer_tumor 3 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Ignore everything in this directory
2+
*
3+
# Except this file
4+
!.gitignore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Ignore everything in this directory
2+
*
3+
# Except this file
4+
!.gitignore

unetr_pp/inference/predict_simple.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import torch
1818

1919
from unetr_pp.inference.predict import predict_from_folder
20-
from unetr_pp.paths import default_plans_identifier, network_training_output_dir, default_cascade_trainer, default_trainer
20+
from unetr_pp.paths import default_plans_identifier, network_training_output_dir, default_trainer
2121
from batchgenerators.utilities.file_and_folder_operations import join, isdir
2222
from unetr_pp.utilities.task_name_id_conversion import convert_id_to_task_name
2323
from unetr_pp.paths import network_training_output_dir, preprocessing_output_dir, default_plans_identifier
@@ -46,8 +46,8 @@ def main():
4646
default=default_trainer)
4747
parser.add_argument('-ctr', '--cascade_trainer_class_name',
4848
help="Trainer class name used for predicting the 3D full resolution U-Net part of the cascade."
49-
"Default is %s" % default_cascade_trainer, required=False,
50-
default=default_cascade_trainer)
49+
"Default is %s" % default_trainer, required=False,
50+
default=default_trainer)
5151

5252
parser.add_argument('-m', '--model', help="2d, 3d_lowres, 3d_fullres or 3d_cascade_fullres. Default: 3d_fullres",
5353
default="3d_fullres", required=False)

unetr_pp/inference_synapse.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ def process_label(label):
3232

3333
return spleen,right_kidney,left_kidney,gallbladder,liver,stomach,aorta,pancreas
3434

35-
def test(fold):
36-
path=None #Task002_Synapse path
37-
label_list=sorted(glob.glob(os.path.join(path,'labelsTs','*nii.gz')))
38-
infer_list=sorted(glob.glob(os.path.join(path,'inferTs','nnformer_synapse','*nii.gz')))
35+
def test(fold):
36+
label_path= None # Replace None by full path of "DATASET/unetr_pp_raw/unetr_pp_raw_data/Task002_Synapse/"
37+
infer_path = None # Replace None by full path of "output_synapse"
38+
39+
label_list=sorted(glob.glob(os.path.join(label_path,'labelsTs','*nii.gz')))
40+
infer_list=sorted(glob.glob(os.path.join(infer_path,'inferTs','*nii.gz')))
3941
print("loading success...")
4042
print(label_list)
4143
print(infer_list)
@@ -57,7 +59,7 @@ def test(fold):
5759
hd_aorta=[]
5860
hd_pancreas=[]
5961

60-
file=path + 'inferTs/'+fold
62+
file=infer_path + 'inferTs/'+fold
6163
if not os.path.exists(file):
6264
os.makedirs(file)
6365
fw = open(file+'/dice_pre.txt', 'a')

unetr_pp/inference_tumor.py

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
import glob
2+
import os
3+
import SimpleITK as sitk
4+
import numpy as np
5+
import argparse
6+
from medpy.metric import binary
7+
8+
def read_nii(path):
9+
return sitk.GetArrayFromImage(sitk.ReadImage(path))
10+
11+
def new_dice(pred,label):
12+
tp_hard = np.sum((pred == 1).astype(np.float) * (label == 1).astype(np.float))
13+
fp_hard = np.sum((pred == 1).astype(np.float) * (label != 1).astype(np.float))
14+
fn_hard = np.sum((pred != 1).astype(np.float) * (label == 1).astype(np.float))
15+
return 2*tp_hard/(2*tp_hard+fp_hard+fn_hard)
16+
17+
def dice(pred, label):
18+
if (pred.sum() + label.sum()) == 0:
19+
return 1
20+
else:
21+
return 2. * np.logical_and(pred, label).sum() / (pred.sum() + label.sum())
22+
23+
def hd(pred,gt):
24+
if pred.sum() > 0 and gt.sum()>0:
25+
hd95 = binary.hd95(pred, gt)
26+
return hd95
27+
else:
28+
return 0
29+
30+
def process_label(label):
31+
net = label == 2
32+
ed = label == 1
33+
et = label == 3
34+
ET=et
35+
TC=net+et
36+
WT=net+et+ed
37+
ED= ed
38+
NET=net
39+
return ET,TC,WT,ED,NET
40+
41+
def test(fold):
42+
#path='./'
43+
44+
path = None # Replace None by the full path of : unetr_plus_plus/DATASET_Tumor/unetr_pp_raw/unetr_pp_raw_data/Task03_tumor/"
45+
46+
label_list=sorted(glob.glob(os.path.join(path,'labelsTs','*nii.gz')))
47+
48+
infer_path = None # Replace None by the full path of : unetr_plus_plus/unetr_pp/evaluation/unetr_pp_tumor_checkpoint/"
49+
50+
infer_list=sorted(glob.glob(os.path.join(infer_path,'inferTs','*nii.gz')))
51+
print("loading success...")
52+
Dice_et=[]
53+
Dice_tc=[]
54+
Dice_wt=[]
55+
Dice_ed=[]
56+
Dice_net=[]
57+
58+
HD_et=[]
59+
HD_tc=[]
60+
HD_wt=[]
61+
HD_ed=[]
62+
HD_net=[]
63+
file=infer_path + 'inferTs/'+fold
64+
if not os.path.exists(file):
65+
os.makedirs(file)
66+
fw = open(file+'/dice_five.txt', 'w')
67+
68+
for label_path,infer_path in zip(label_list,infer_list):
69+
print(label_path.split('/')[-1])
70+
print(infer_path.split('/')[-1])
71+
label,infer = read_nii(label_path),read_nii(infer_path)
72+
label_et,label_tc,label_wt,label_ed,label_net=process_label(label)
73+
infer_et,infer_tc,infer_wt,infer_ed,infer_net=process_label(infer)
74+
Dice_et.append(dice(infer_et,label_et))
75+
Dice_tc.append(dice(infer_tc,label_tc))
76+
Dice_wt.append(dice(infer_wt,label_wt))
77+
Dice_ed.append(dice(infer_ed,label_ed))
78+
Dice_net.append(dice(infer_net,label_net))
79+
80+
HD_et.append(hd(infer_et,label_et))
81+
HD_tc.append(hd(infer_tc,label_tc))
82+
HD_wt.append(hd(infer_wt,label_wt))
83+
HD_ed.append(hd(infer_ed,label_ed))
84+
HD_net.append(hd(infer_net,label_net))
85+
86+
87+
fw.write('*'*20+'\n',)
88+
fw.write(infer_path.split('/')[-1]+'\n')
89+
fw.write('hd_et: {:.4f}\n'.format(HD_et[-1]))
90+
fw.write('hd_tc: {:.4f}\n'.format(HD_tc[-1]))
91+
fw.write('hd_wt: {:.4f}\n'.format(HD_wt[-1]))
92+
fw.write('hd_ed: {:.4f}\n'.format(HD_ed[-1]))
93+
fw.write('hd_net: {:.4f}\n'.format(HD_net[-1]))
94+
fw.write('*'*20+'\n',)
95+
fw.write('Dice_et: {:.4f}\n'.format(Dice_et[-1]))
96+
fw.write('Dice_tc: {:.4f}\n'.format(Dice_tc[-1]))
97+
fw.write('Dice_wt: {:.4f}\n'.format(Dice_wt[-1]))
98+
fw.write('Dice_ed: {:.4f}\n'.format(Dice_ed[-1]))
99+
fw.write('Dice_net: {:.4f}\n'.format(Dice_net[-1]))
100+
101+
#print('dice_et: {:.4f}'.format(np.mean(Dice_et)))
102+
#print('dice_tc: {:.4f}'.format(np.mean(Dice_tc)))
103+
#print('dice_wt: {:.4f}'.format(np.mean(Dice_wt)))
104+
dsc=[]
105+
avg_hd=[]
106+
dsc.append(np.mean(Dice_et))
107+
dsc.append(np.mean(Dice_tc))
108+
dsc.append(np.mean(Dice_wt))
109+
dsc.append(np.mean(Dice_ed))
110+
dsc.append(np.mean(Dice_net))
111+
112+
113+
avg_hd.append(np.mean(HD_et))
114+
avg_hd.append(np.mean(HD_tc))
115+
avg_hd.append(np.mean(HD_wt))
116+
avg_hd.append(np.mean(HD_ed))
117+
avg_hd.append(np.mean(HD_net))
118+
119+
fw.write('Dice_et'+str(np.mean(Dice_et))+' '+'\n')
120+
fw.write('Dice_tc'+str(np.mean(Dice_tc))+' '+'\n')
121+
fw.write('Dice_wt'+str(np.mean(Dice_wt))+' '+'\n')
122+
fw.write('Dice_ed'+str(np.mean(Dice_ed))+' '+'\n')
123+
fw.write('Dice_net'+str(np.mean(Dice_net))+' '+'\n')
124+
125+
fw.write('HD_et'+str(np.mean(HD_et))+' '+'\n')
126+
fw.write('HD_tc'+str(np.mean(HD_tc))+' '+'\n')
127+
fw.write('HD_wt'+str(np.mean(HD_wt))+' '+'\n')
128+
fw.write('HD_ed'+str(np.mean(HD_ed))+' '+'\n')
129+
fw.write('HD_net'+str(np.mean(HD_net))+' '+'\n')
130+
131+
fw.write('Dice'+str(np.mean(dsc))+' '+'\n')
132+
fw.write('HD'+str(np.mean(avg_hd))+' '+'\n')
133+
#print('Dice'+str(np.mean(dsc))+' '+'\n')
134+
#print('HD'+str(np.mean(avg_hd))+' '+'\n')
135+
136+
137+
138+
if __name__ == '__main__':
139+
parser = argparse.ArgumentParser()
140+
parser.add_argument("fold", help="fold name")
141+
args = parser.parse_args()
142+
fold=args.fold
143+
test(fold)

unetr_pp/network_architecture/lung/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)