Skip to content

Commit 47bad14

Browse files
committed
add kidney_cyst, breast, intervertebral_discs models
1 parent 4e71d8d commit 47bad14

File tree

7 files changed

+121
-28
lines changed

7 files changed

+121
-28
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Openly available for any usage:
6262
* **lung_vessels**: lung_vessels (cite [paper](https://www.sciencedirect.com/science/article/pii/S0720048X22001097)), lung_trachea_bronchia
6363
* **body**: body, body_trunc, body_extremities, skin
6464
* **body_mr**: body_trunc, body_extremities (for MR images)
65+
* **vertebrae_mr**: sacrum, vertebrae_L5, vertebrae_L4, vertebrae_L3, vertebrae_L2, vertebrae_L1, vertebrae_T12, vertebrae_T11, vertebrae_T10, vertebrae_T9, vertebrae_T8, vertebrae_T7, vertebrae_T6, vertebrae_T5, vertebrae_T4, vertebrae_T3, vertebrae_T2, vertebrae_T1, vertebrae_C7, vertebrae_C6, vertebrae_C5, vertebrae_C4, vertebrae_C3, vertebrae_C2, vertebrae_C1 (for CT this is part of the `total` task)
6566
* **cerebral_bleed**: intracerebral_hemorrhage (cite [paper](https://www.mdpi.com/2077-0383/12/7/2631))*
6667
* **hip_implant**: hip_implant*
6768
* **coronary_arteries**: coronary_arteries*
@@ -72,17 +73,20 @@ Openly available for any usage:
7273
* **headneck_muscles**: sternocleidomastoid_right, sternocleidomastoid_left, superior_pharyngeal_constrictor, middle_pharyngeal_constrictor, inferior_pharyngeal_constrictor, trapezius_right, trapezius_left, platysma_right, platysma_left, levator_scapulae_right, levator_scapulae_left, anterior_scalene_right, anterior_scalene_left, middle_scalene_right, middle_scalene_left, posterior_scalene_right, posterior_scalene_left, sterno_thyroid_right, sterno_thyroid_left, thyrohyoid_right, thyrohyoid_left, prevertebral_right, prevertebral_left (cite [paper](https://www.mdpi.com/2072-6694/16/2/415))
7374
* **liver_vessels**: liver_vessels, liver_tumor (cite [paper](https://arxiv.org/abs/1902.09063))*
7475
* **oculomotor_muscles**: skull, eyeball_right, lateral_rectus_muscle_right, superior_oblique_muscle_right, levator_palpebrae_superioris_right, superior_rectus_muscle_right, medial_rectus_muscle_left, inferior_oblique_muscle_right, inferior_rectus_muscle_right, optic_nerve_left, eyeball_left, lateral_rectus_muscle_left, superior_oblique_muscle_left, levator_palpebrae_superioris_left, superior_rectus_muscle_left, medial_rectus_muscle_right, inferior_oblique_muscle_left, inferior_rectus_muscle_left, optic_nerve_right*
76+
* **lung_nodules**: lung, lung_nodules (this model is kindly provided by [BLUEMIND AI](https://bluemind.co/))
77+
* **kidney_cysts**: kidney_cyst_left, kidney_cyst_right (strongly improved accuracy compared to kidney_cysts inside of `total` task)
78+
* **breasts**: breast
7579

7680
*: These models are not trained on the full totalsegmentator dataset but on some small other datasets. Therefore, expect them to work less robustly.
7781

7882
Available with a license (free licenses available for non-commercial usage [here](https://backend.totalsegmentator.com/license-academic/). For a commercial license contact jakob.wasserthal@usb.ch):
7983
* **heartchambers_highres**: myocardium, atrium_left, ventricle_left, atrium_right, ventricle_right, aorta, pulmonary_artery (trained on sub-millimeter resolution)
8084
* **appendicular_bones**: patella, tibia, fibula, tarsal, metatarsal, phalanges_feet, ulna, radius, carpal, metacarpal, phalanges_hand
81-
* **apendicular_bones_mr**: patella, tibia, fibula, tarsal, metatarsal, phalanges_feet, ulna, radius (for MR images)
85+
* **appendicular_bones_mr**: patella, tibia, fibula, tarsal, metatarsal, phalanges_feet, ulna, radius (for MR images)
8286
* **tissue_types**: subcutaneous_fat, torso_fat, skeletal_muscle
8387
* **tissue_types_mr**: subcutaneous_fat, torso_fat, skeletal_muscle (for MR images)
8488
* **brain_structures**: brainstem, subarachnoid_space, venous_sinuses, septum_pellucidum, cerebellum, caudate_nucleus, lentiform_nucleus, insular_cortex, internal_capsule, ventricle, central_sulcus, frontal_lobe, parietal_lobe, occipital_lobe, temporal_lobe, thalamus (NOTE: this is for CT) (cite [paper](https://doi.org/10.1148/ryai.2020190183) as our model is partly based on this)
85-
* **vertebrae_body**: vertebral body of all vertebrae (without the vertebral arch)
89+
* **vertebrae_discs**: vertebral body of all vertebrae (without the vertebral arch), intervertebral_discs (for MR this is part of the `total_mr` task)
8690
* **face**: face_region (for anonymization)
8791
* **face_mr**: face_region (for anonymization)
8892
* **thigh_shoulder_muscles**: thigh_posterior_compartment_left, thigh_posterior_compartment_right, sartorius_left, sartorius_right, pectoralis_minor, serratus_anterior, teres_major, triceps_brachii (WIP)

totalsegmentator/bin/TotalSegmentator.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,15 @@ def main():
5454

5555
# cerebral_bleed: Intracerebral hemorrhage
5656
# liver_vessels: hepatic vessels
57-
parser.add_argument("-ta", "--task", choices=["total", "body", "body_mr",
57+
parser.add_argument("-ta", "--task", choices=["total", "body", "body_mr", "vertebrae_mr",
5858
"lung_vessels", "cerebral_bleed", "hip_implant", "coronary_arteries",
5959
"pleural_pericard_effusion", "test",
6060
"appendicular_bones", "appendicular_bones_mr", "tissue_types", "heartchambers_highres",
61-
"face", "vertebrae_body", "total_mr", "tissue_types_mr", "face_mr",
61+
"face", "vertebrae_discs", "total_mr", "tissue_types_mr", "face_mr",
6262
"head_glands_cavities", "head_muscles", "headneck_bones_vessels", "headneck_muscles",
6363
"brain_structures", "liver_vessels", "oculomotor_muscles",
64-
"thigh_shoulder_muscles", "thigh_shoulder_muscles_mr", "lung_nodules"],
64+
"thigh_shoulder_muscles", "thigh_shoulder_muscles_mr", "lung_nodules", "kidney_cysts",
65+
"breasts"],
6566
help="Select which model to use. This determines what is predicted.",
6667
default="total")
6768

totalsegmentator/bin/totalseg_download_weights.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ def main():
2020
parser.add_argument("-t", "--task", choices=["total", "total_fast", "total_mr", "total_fast_mr",
2121
"lung_vessels", "cerebral_bleed",
2222
"hip_implant", "coronary_arteries", "pleural_pericard_effusion",
23-
"body", "body_fast", "body_mr", "body_mr_fast", "vertebrae_body",
23+
"body", "body_fast", "body_mr", "body_mr_fast", "vertebrae_mr",
24+
"vertebrae_discs",
2425
"heartchambers_highres", "appendicular_bones",
2526
"tissue_types", "tissue_types_mr", "face", "face_mr",
2627
"head_glands_cavities", "head_muscles", "headneck_bones_vessels",
27-
"headneck_muscles", "liver_vessels", "brain_structures"],
28+
"headneck_muscles", "liver_vessels", "brain_structures",
29+
"lung_nodules", "kidney_cysts", "breasts"],
2830
help="Task for which to download the weights", default="total")
2931

3032
args = parser.parse_args()
@@ -43,17 +45,21 @@ def main():
4345
"body_fast": [300],
4446
"body_mr": [597],
4547
"body_mr_fast": [598],
48+
"vertebrae_mr": [756],
4649
"head_glands_cavities": [775],
4750
"headneck_bones_vessels": [776],
4851
"head_muscles": [777],
4952
"headneck_muscles": [778, 779],
5053
"liver_vessels": [8],
54+
"lung_nodules": [913],
55+
"kidney_cysts": [789],
56+
"breasts": [527],
5157

5258
"heartchambers_highres": [301],
5359
"appendicular_bones": [304],
5460
"tissue_types": [481],
5561
"tissue_types_mr": [734],
56-
"vertebrae_body": [302],
62+
"vertebrae_discs": [305],
5763
"face": [303],
5864
"face_mr": [737],
5965
"brain_structures": [409]

totalsegmentator/libs.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,6 @@ def download_pretrained_weights(task_id):
136136

137137
config_dir = get_weights_dir()
138138
config_dir.mkdir(exist_ok=True, parents=True)
139-
# (config_dir / "3d_fullres").mkdir(exist_ok=True, parents=True)
140-
# (config_dir / "3d_lowres").mkdir(exist_ok=True, parents=True)
141-
# (config_dir / "2d").mkdir(exist_ok=True, parents=True)
142139

143140
old_weights = [
144141
"nnUNet/3d_fullres/Task251_TotalSegmentator_part1_organs_1139subj",
@@ -163,6 +160,7 @@ def download_pretrained_weights(task_id):
163160
# "Dataset297_TotalSegmentator_total_3mm_1559subj", # for >= v2.0.4
164161
"Dataset297_TotalSegmentator_total_3mm_1559subj_v204", # for >= v2.0.5
165162
# "Dataset298_TotalSegmentator_total_6mm_1559subj", # for >= v2.0.5
163+
"Dataset302_vertebrae_body_1559subj"
166164
]
167165

168166
# url = "http://backend.totalsegmentator.com"
@@ -233,6 +231,12 @@ def download_pretrained_weights(task_id):
233231
elif task_id == 351:
234232
weights_path = config_dir / "Dataset351_oculomotor_muscles_18subj"
235233
WEIGHTS_URL = url + "/v2.4.0-weights/Dataset351_oculomotor_muscles_18subj.zip"
234+
elif task_id == 789:
235+
weights_path = config_dir / "Dataset789_kidney_cyst_501subj"
236+
WEIGHTS_URL = url + "/v2.5.0-weights/Dataset789_kidney_cyst_501subj.zip"
237+
elif task_id == 527:
238+
weights_path = config_dir / "Dataset527_breasts_1559subj"
239+
WEIGHTS_URL = url + "/v2.5.0-weights/Dataset527_breasts_1559subj.zip"
236240

237241
# MR models
238242
elif task_id == 850:
@@ -248,11 +252,14 @@ def download_pretrained_weights(task_id):
248252
weights_path = config_dir / "Dataset853_TotalSegMRI_total_6mm_1088subj"
249253
WEIGHTS_URL = url + "/v2.5.0-weights/Dataset853_TotalSegMRI_total_6mm_1088subj.zip"
250254
elif task_id == 597:
251-
weights_path = config_dir / "Dataset597_body_mr_139subj"
252-
WEIGHTS_URL = url + "/v2.5.0-weights/Dataset597_body_mr_139subj.zip"
255+
weights_path = config_dir / "Dataset597_mri_body_139subj"
256+
WEIGHTS_URL = url + "/v2.5.0-weights/Dataset597_mri_body_139subj.zip"
253257
elif task_id == 598:
254-
weights_path = config_dir / "Dataset598_body_mr_6mm_139subj"
255-
WEIGHTS_URL = url + "/v2.5.0-weights/Dataset598_body_mr_6mm_139subj.zip"
258+
weights_path = config_dir / "Dataset598_mri_body_6mm_139subj"
259+
WEIGHTS_URL = url + "/v2.5.0-weights/Dataset598_mri_body_6mm_139subj.zip"
260+
elif task_id == 756:
261+
weights_path = config_dir / "Dataset756_mri_vertebrae_1076subj"
262+
WEIGHTS_URL = url + "/v2.5.0-weights/Dataset756_mri_vertebrae_1076subj.zip"
256263

257264
# Models from other projects
258265
elif task_id == 258:
@@ -307,8 +314,8 @@ def download_pretrained_weights(task_id):
307314
weights_path = config_dir / "Dataset303_face_1559subj"
308315
elif task_id == 481:
309316
weights_path = config_dir / "Dataset481_tissue_1559subj"
310-
elif task_id == 302:
311-
weights_path = config_dir / "Dataset302_vertebrae_body_1559subj"
317+
elif task_id == 305:
318+
weights_path = config_dir / "Dataset305_vertebrae_discs_1559subj"
312319
elif task_id == 854:
313320
weights_path = config_dir / "Dataset854_TotalSegMRI_tissue_1088subj"
314321
elif task_id == 856:

totalsegmentator/map_to_binary.py

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,33 @@
328328
1: "body_trunc",
329329
2: "body_extremities",
330330
},
331+
"vertebrae_mr": {
332+
1: "sacrum",
333+
2: "vertebrae_L5",
334+
3: "vertebrae_L4",
335+
4: "vertebrae_L3",
336+
5: "vertebrae_L2",
337+
6: "vertebrae_L1",
338+
7: "vertebrae_T12",
339+
8: "vertebrae_T11",
340+
9: "vertebrae_T10",
341+
10: "vertebrae_T9",
342+
11: "vertebrae_T8",
343+
12: "vertebrae_T7",
344+
13: "vertebrae_T6",
345+
14: "vertebrae_T5",
346+
15: "vertebrae_T4",
347+
16: "vertebrae_T3",
348+
17: "vertebrae_T2",
349+
18: "vertebrae_T1",
350+
19: "vertebrae_C7",
351+
20: "vertebrae_C6",
352+
21: "vertebrae_C5",
353+
22: "vertebrae_C4",
354+
23: "vertebrae_C3",
355+
24: "vertebrae_C2",
356+
25: "vertebrae_C1",
357+
},
331358
"pleural_pericard_effusion": {
332359
# 1: "lung_pleural",
333360
2: "pleural_effusion",
@@ -337,8 +364,9 @@
337364
1: "liver_vessels",
338365
2: "liver_tumor"
339366
},
340-
"vertebrae_body": {
341-
1: "vertebrae_body"
367+
"vertebrae_discs": {
368+
1: "vertebrae_body",
369+
2: "intervertebral_discs"
342370
},
343371
"heartchambers_highres": {
344372
1: "heart_myocardium",
@@ -539,6 +567,18 @@
539567
1: "lung",
540568
2: "lung_nodules"
541569
},
570+
"kidney_cysts": {
571+
1: "kidney_cyst_left",
572+
2: "kidney_cyst_right"
573+
},
574+
# those classes need to be removed
575+
"kidney_cysts_auxiliary": {
576+
3: "kidney_left",
577+
4: "kidney_right"
578+
},
579+
"breasts": {
580+
1: "breast"
581+
},
542582
"test": {
543583
1: "carpal"
544584
}
@@ -551,7 +591,7 @@
551591
"appendicular_bones_mr": 855,
552592
"tissue_types": 481,
553593
"tissue_types_mr": 854,
554-
"vertebrae_body": 302,
594+
"vertebrae_body": 305,
555595
"face": 303,
556596
"face_mr": 856,
557597
"brain_structures": 409,

totalsegmentator/preview.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,19 @@
9797
"body_mr": [
9898
["body_trunc", "body_extremities"]
9999
],
100+
"vertebrae_mr": [
101+
["sacrum", "vertebrae_L5", "vertebrae_L4", "vertebrae_L3", "vertebrae_L2", "vertebrae_L1", "vertebrae_T12", "vertebrae_T11", "vertebrae_T10",
102+
"vertebrae_T9", "vertebrae_T8", "vertebrae_T7", "vertebrae_T6", "vertebrae_T5", "vertebrae_T4", "vertebrae_T3", "vertebrae_T2", "vertebrae_T1",
103+
"vertebrae_C7", "vertebrae_C6", "vertebrae_C5", "vertebrae_C4", "vertebrae_C3", "vertebrae_C2", "vertebrae_C1"]
104+
],
100105
"pleural_pericard_effusion": [
101106
["pleural_effusion", "pericardial_effusion"]
102107
],
103108
"liver_vessels": [
104109
["liver_vessels", "liver_tumor"]
105110
],
106-
"vertebrae_body": [
107-
["vertebrae_body"]
111+
"vertebrae_discs": [
112+
["vertebrae_body", "intervertebral_discs"]
108113
],
109114
"heartchambers_highres": [
110115
["heart_myocardium"],
@@ -201,6 +206,12 @@
201206
"lung_nodules": [
202207
["lung_nodules"]
203208
],
209+
"kidney_cysts": [
210+
["kidney_cyst_left", "kidney_cyst_right"]
211+
],
212+
"breasts": [
213+
["breast"]
214+
],
204215
"test": [
205216
["ulna"]
206217
]

totalsegmentator/python_api.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,18 +245,25 @@ def totalsegmentator(input: Union[str, Path, Nifti1Image], output: Union[str, Pa
245245
if fast:
246246
task_id = 598 # todo: train
247247
resample = 6.0
248-
trainer = "nnUNetTrainer"
248+
trainer = "nnUNetTrainer_DASegOrd0"
249249
crop = None
250250
model = "3d_fullres"
251251
folds = [0]
252252
if not quiet: print("Using 'fast' option: resampling to lower resolution (6mm)")
253253
else:
254254
task_id = 597
255255
resample = 1.5
256-
trainer = "nnUNetTrainer"
256+
trainer = "nnUNetTrainer_DASegOrd0"
257257
crop = None
258258
model = "3d_fullres"
259259
folds = [0]
260+
elif task == "vertebrae_mr":
261+
task_id = 756
262+
resample = None
263+
trainer = "nnUNetTrainer_DASegOrd0_NoMirroring"
264+
crop = None
265+
model = "3d_fullres"
266+
folds = [0]
260267
elif task == "pleural_pericard_effusion":
261268
task_id = 315
262269
resample = None
@@ -335,17 +342,34 @@ def totalsegmentator(input: Union[str, Path, Nifti1Image], output: Union[str, Pa
335342
model = "3d_fullres"
336343
folds = [0]
337344
if fast: raise ValueError("task lung_nodules does not work with option --fast")
345+
elif task == "kidney_cysts":
346+
task_id = 789
347+
resample = [1.5, 1.5, 1.5]
348+
trainer = "nnUNetTrainer_DASegOrd0_NoMirroring"
349+
crop = ["kidney_left", "kidney_right", "liver", "spleen", "colon"]
350+
crop_addon = [10, 10, 10]
351+
model = "3d_fullres"
352+
folds = [0]
353+
if fast: raise ValueError("task kidney_cysts does not work with option --fast")
354+
elif task == "breasts":
355+
task_id = 527
356+
resample = [1.5, 1.5, 1.5]
357+
trainer = "nnUNetTrainer_DASegOrd0_NoMirroring"
358+
crop = None
359+
model = "3d_fullres"
360+
folds = [0]
361+
if fast: raise ValueError("task breasts does not work with option --fast")
338362

339363

340364
# Commercial models
341-
elif task == "vertebrae_body":
342-
task_id = 302
365+
elif task == "vertebrae_discs":
366+
task_id = 305
343367
resample = 1.5
344-
trainer = "nnUNetTrainer"
368+
trainer = "nnUNetTrainer_DASegOrd0"
345369
crop = None
346370
model = "3d_fullres"
347371
folds = [0]
348-
if fast: raise ValueError("task vertebrae_body does not work with option --fast")
372+
if fast: raise ValueError("task vertebrae_discs does not work with option --fast")
349373
show_license_info()
350374
elif task == "heartchambers_highres":
351375
task_id = 301

0 commit comments

Comments
 (0)