complete the model package
Browse files- LICENSE +201 -0
- README.md +179 -0
- configs/evaluate.json +78 -0
- configs/inference.json +159 -0
- configs/logging.conf +21 -0
- configs/metadata.json +183 -0
- configs/multi_gpu_evaluate.json +28 -0
- configs/multi_gpu_train.json +39 -0
- configs/train.json +422 -0
- docs/README.md +172 -0
- docs/data_license.txt +6 -0
- docs/imgs/totalsegmentator_15mm_validation.png +0 -0
- docs/imgs/totalsegmentator_monailabel.png +0 -0
- docs/imgs/totalsegmentator_train_accuracy.png +0 -0
- models/model.pt +3 -0
- models/model_lowres.pt +3 -0
LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Apache License
|
2 |
+
Version 2.0, January 2004
|
3 |
+
http://www.apache.org/licenses/
|
4 |
+
|
5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6 |
+
|
7 |
+
1. Definitions.
|
8 |
+
|
9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
11 |
+
|
12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13 |
+
the copyright owner that is granting the License.
|
14 |
+
|
15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
16 |
+
other entities that control, are controlled by, or are under common
|
17 |
+
control with that entity. For the purposes of this definition,
|
18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
19 |
+
direction or management of such entity, whether by contract or
|
20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22 |
+
|
23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24 |
+
exercising permissions granted by this License.
|
25 |
+
|
26 |
+
"Source" form shall mean the preferred form for making modifications,
|
27 |
+
including but not limited to software source code, documentation
|
28 |
+
source, and configuration files.
|
29 |
+
|
30 |
+
"Object" form shall mean any form resulting from mechanical
|
31 |
+
transformation or translation of a Source form, including but
|
32 |
+
not limited to compiled object code, generated documentation,
|
33 |
+
and conversions to other media types.
|
34 |
+
|
35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
36 |
+
Object form, made available under the License, as indicated by a
|
37 |
+
copyright notice that is included in or attached to the work
|
38 |
+
(an example is provided in the Appendix below).
|
39 |
+
|
40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41 |
+
form, that is based on (or derived from) the Work and for which the
|
42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
44 |
+
of this License, Derivative Works shall not include works that remain
|
45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46 |
+
the Work and Derivative Works thereof.
|
47 |
+
|
48 |
+
"Contribution" shall mean any work of authorship, including
|
49 |
+
the original version of the Work and any modifications or additions
|
50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
54 |
+
means any form of electronic, verbal, or written communication sent
|
55 |
+
to the Licensor or its representatives, including but not limited to
|
56 |
+
communication on electronic mailing lists, source code control systems,
|
57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
59 |
+
excluding communication that is conspicuously marked or otherwise
|
60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
61 |
+
|
62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
64 |
+
subsequently incorporated within the Work.
|
65 |
+
|
66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
71 |
+
Work and such Derivative Works in Source or Object form.
|
72 |
+
|
73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76 |
+
(except as stated in this section) patent license to make, have made,
|
77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78 |
+
where such license applies only to those patent claims licensable
|
79 |
+
by such Contributor that are necessarily infringed by their
|
80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
82 |
+
institute patent litigation against any entity (including a
|
83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84 |
+
or a Contribution incorporated within the Work constitutes direct
|
85 |
+
or contributory patent infringement, then any patent licenses
|
86 |
+
granted to You under this License for that Work shall terminate
|
87 |
+
as of the date such litigation is filed.
|
88 |
+
|
89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
90 |
+
Work or Derivative Works thereof in any medium, with or without
|
91 |
+
modifications, and in Source or Object form, provided that You
|
92 |
+
meet the following conditions:
|
93 |
+
|
94 |
+
(a) You must give any other recipients of the Work or
|
95 |
+
Derivative Works a copy of this License; and
|
96 |
+
|
97 |
+
(b) You must cause any modified files to carry prominent notices
|
98 |
+
stating that You changed the files; and
|
99 |
+
|
100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
101 |
+
that You distribute, all copyright, patent, trademark, and
|
102 |
+
attribution notices from the Source form of the Work,
|
103 |
+
excluding those notices that do not pertain to any part of
|
104 |
+
the Derivative Works; and
|
105 |
+
|
106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107 |
+
distribution, then any Derivative Works that You distribute must
|
108 |
+
include a readable copy of the attribution notices contained
|
109 |
+
within such NOTICE file, excluding those notices that do not
|
110 |
+
pertain to any part of the Derivative Works, in at least one
|
111 |
+
of the following places: within a NOTICE text file distributed
|
112 |
+
as part of the Derivative Works; within the Source form or
|
113 |
+
documentation, if provided along with the Derivative Works; or,
|
114 |
+
within a display generated by the Derivative Works, if and
|
115 |
+
wherever such third-party notices normally appear. The contents
|
116 |
+
of the NOTICE file are for informational purposes only and
|
117 |
+
do not modify the License. You may add Your own attribution
|
118 |
+
notices within Derivative Works that You distribute, alongside
|
119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
120 |
+
that such additional attribution notices cannot be construed
|
121 |
+
as modifying the License.
|
122 |
+
|
123 |
+
You may add Your own copyright statement to Your modifications and
|
124 |
+
may provide additional or different license terms and conditions
|
125 |
+
for use, reproduction, or distribution of Your modifications, or
|
126 |
+
for any such Derivative Works as a whole, provided Your use,
|
127 |
+
reproduction, and distribution of the Work otherwise complies with
|
128 |
+
the conditions stated in this License.
|
129 |
+
|
130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
132 |
+
by You to the Licensor shall be under the terms and conditions of
|
133 |
+
this License, without any additional terms or conditions.
|
134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135 |
+
the terms of any separate license agreement you may have executed
|
136 |
+
with Licensor regarding such Contributions.
|
137 |
+
|
138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
140 |
+
except as required for reasonable and customary use in describing the
|
141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
142 |
+
|
143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144 |
+
agreed to in writing, Licensor provides the Work (and each
|
145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147 |
+
implied, including, without limitation, any warranties or conditions
|
148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150 |
+
appropriateness of using or redistributing the Work and assume any
|
151 |
+
risks associated with Your exercise of permissions under this License.
|
152 |
+
|
153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
154 |
+
whether in tort (including negligence), contract, or otherwise,
|
155 |
+
unless required by applicable law (such as deliberate and grossly
|
156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157 |
+
liable to You for damages, including any direct, indirect, special,
|
158 |
+
incidental, or consequential damages of any character arising as a
|
159 |
+
result of this License or out of the use or inability to use the
|
160 |
+
Work (including but not limited to damages for loss of goodwill,
|
161 |
+
work stoppage, computer failure or malfunction, or any and all
|
162 |
+
other commercial damages or losses), even if such Contributor
|
163 |
+
has been advised of the possibility of such damages.
|
164 |
+
|
165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168 |
+
or other liability obligations and/or rights consistent with this
|
169 |
+
License. However, in accepting such obligations, You may act only
|
170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171 |
+
of any other Contributor, and only if You agree to indemnify,
|
172 |
+
defend, and hold each Contributor harmless for any liability
|
173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
174 |
+
of your accepting any such warranty or additional liability.
|
175 |
+
|
176 |
+
END OF TERMS AND CONDITIONS
|
177 |
+
|
178 |
+
APPENDIX: How to apply the Apache License to your work.
|
179 |
+
|
180 |
+
To apply the Apache License to your work, attach the following
|
181 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182 |
+
replaced with your own identifying information. (Don't include
|
183 |
+
the brackets!) The text should be enclosed in the appropriate
|
184 |
+
comment syntax for the file format. We also recommend that a
|
185 |
+
file or class name and description of purpose be included on the
|
186 |
+
same "printed page" as the copyright notice for easier
|
187 |
+
identification within third-party archives.
|
188 |
+
|
189 |
+
Copyright [yyyy] [name of copyright owner]
|
190 |
+
|
191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192 |
+
you may not use this file except in compliance with the License.
|
193 |
+
You may obtain a copy of the License at
|
194 |
+
|
195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
196 |
+
|
197 |
+
Unless required by applicable law or agreed to in writing, software
|
198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200 |
+
See the License for the specific language governing permissions and
|
201 |
+
limitations under the License.
|
README.md
ADDED
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
tags:
|
3 |
+
- monai
|
4 |
+
- medical
|
5 |
+
library_name: monai
|
6 |
+
license: apache-2.0
|
7 |
+
---
|
8 |
+
# Model Overview
|
9 |
+
|
10 |
+
Body CT segmentation models are evolving. Starting from abdominal multi-organ segmentation model [1]. Now the community is developing hundreds of target anatomies. In this bundle, we provide re-trained models for (3D) segmentation of 104 whole-body segments.
|
11 |
+
|
12 |
+
This model is trained using the SegResNet [3] network. The model is trained using TotalSegmentator datasets [2].
|
13 |
+
|
14 |
+
![structures](https://github.com/wasserth/TotalSegmentator/blob/master/resources/imgs/overview_classes.png)
|
15 |
+
|
16 |
+
Figure source from the TotalSegmentator [2].
|
17 |
+
|
18 |
+
## MONAI Label Showcase
|
19 |
+
|
20 |
+
- We highlight the use of this bundle to use and visualize in MONAI Label + 3D Slicer integration.
|
21 |
+
|
22 |
+
![](./imgs/totalsegmentator_monailabel.png) <br>
|
23 |
+
|
24 |
+
## Data
|
25 |
+
|
26 |
+
The training set is the 104 whole-body structures from the TotalSegmentator released datasets. Users can find more details on the datasets at https://github.com/wasserth/TotalSegmentator. All rights and licenses are reserved to the original authors.
|
27 |
+
|
28 |
+
- Target: 104 structures
|
29 |
+
- Modality: CT
|
30 |
+
- Source: TotalSegmentator
|
31 |
+
- Challenge: Large volumes of structures in CT images
|
32 |
+
|
33 |
+
### Preprocessing
|
34 |
+
|
35 |
+
To use the bundle, users need to download the data and merge all annotated labels into one NIFTI file. Each file contains 0-104 values, each value represents one anatomy class. A sample set is provided with this [link](https://drive.google.com/file/d/1DtDmERVMjks1HooUhggOKAuDm0YIEunG/view?usp=share_link).
|
36 |
+
|
37 |
+
## Training Configuration
|
38 |
+
|
39 |
+
The segmentation of 104 tissues is formulated as voxel-wise multi-label segmentation. The model is optimized with the gradient descent method minimizing Dice + cross-entropy loss between the predicted mask and ground truth segmentation.
|
40 |
+
|
41 |
+
The training was performed with the following:
|
42 |
+
|
43 |
+
- GPU: 32 GB of GPU memory
|
44 |
+
- Actual Model Input: 96 x 96 x 96
|
45 |
+
- AMP: True
|
46 |
+
- Optimizer: AdamW
|
47 |
+
- Learning Rate: 1e-4
|
48 |
+
- Loss: DiceCELoss
|
49 |
+
|
50 |
+
### Input
|
51 |
+
|
52 |
+
One channel
|
53 |
+
- CT image
|
54 |
+
|
55 |
+
### Output
|
56 |
+
|
57 |
+
105 channels
|
58 |
+
- Label 0: Background (everything else)
|
59 |
+
- label 1-105: Foreground classes (104)
|
60 |
+
|
61 |
+
### High-Resolution and Low-Resolution Models
|
62 |
+
|
63 |
+
We retrained two versions of the totalSegmentator models, following the original paper and implementation.
|
64 |
+
To meet multiple demands according to computation resources and performance, we provide a 1.5 mm model and a 3.0 mm model, both models are trained with 104 foreground output channels.
|
65 |
+
|
66 |
+
In this bundle, we configured a parameter called `highres`, users can set it to `true` when using 1.5 mm model, and set it to `false` to use the 3.0 mm model. The high-resolution model is named `model.pt` by default, the low-resolution model is named `model_lowres.pt`.
|
67 |
+
|
68 |
+
In MONAI Label use case, users can set the parameter in 3D Slicer plugin to control which model to infer and train.
|
69 |
+
|
70 |
+
- Pretrained Checkpoints
|
71 |
+
- 1.5 mm model: [Download link](https://drive.google.com/file/d/1PHpFWboimEXmMSe2vBra6T8SaCMC2SHT/view?usp=share_link)
|
72 |
+
- 3.0 mm model: [Download link](https://drive.google.com/file/d/1c3osYscnr6710ObqZZS8GkZJQlWlc7rt/view?usp=share_link)
|
73 |
+
|
74 |
+
### Resource Requirements and Latency Benchmarks
|
75 |
+
|
76 |
+
Latencies and memory performance of using the bundle with MONAI Label:
|
77 |
+
|
78 |
+
Tested Image Dimension: **(512, 512, 397)**, the slice thickness is **1.5mm** in this case. After resample to **1.5** isotropic resolution, the dimension is **(287, 287, 397)**
|
79 |
+
|
80 |
+
## 1.5 mm (highres) model (Single Model with 104 foreground classes)
|
81 |
+
|
82 |
+
Benchmarking on GPU: Memory: **28.73G**
|
83 |
+
|
84 |
+
- `++ Latencies => Total: 6.0277; Pre: 1.6228; Inferer: 4.1153; Invert: 0.0000; Post: 0.0897; Write: 0.1995`
|
85 |
+
|
86 |
+
Benchmarking on CPU: Memory: **26G**
|
87 |
+
|
88 |
+
- `++ Latencies => Total: 38.3108; Pre: 1.6643; Inferer: 30.3018; Invert: 0.0000; Post: 6.1656; Write: 0.1786`
|
89 |
+
|
90 |
+
## 3.0 mm (lowres) model (single model with 104 foreground classes)
|
91 |
+
|
92 |
+
GPU: Memory: **5.89G**
|
93 |
+
|
94 |
+
- `++ Latencies => Total: 1.9993; Pre: 1.2363; Inferer: 0.5207; Invert: 0.0000; Post: 0.0358; Write: 0.2060`
|
95 |
+
|
96 |
+
CPU: Memory: **2.3G**
|
97 |
+
|
98 |
+
- `++ Latencies => Total: 6.6138; Pre: 1.3192; Inferer: 3.6746; Invert: 0.0000; Post: 1.4431; Write: 0.1760`
|
99 |
+
|
100 |
+
## Performance
|
101 |
+
|
102 |
+
- 1.5 mm Model Training
|
103 |
+
|
104 |
+
- Training Accuracy
|
105 |
+
|
106 |
+
![](./imgs/totalsegmentator_train_accuracy.png) <br>
|
107 |
+
|
108 |
+
- Validation Dice
|
109 |
+
|
110 |
+
![](./imgs/totalsegmentator_15mm_validation.png) <br>
|
111 |
+
|
112 |
+
## MONAI Bundle Commands
|
113 |
+
In addition to the Pythonic APIs, a few command line interfaces (CLI) are provided to interact with the bundle. The CLI supports flexible use cases, such as overriding configs at runtime and predefining arguments in a file.
|
114 |
+
|
115 |
+
For more details usage instructions, visit the [MONAI Bundle Configuration Page](https://docs.monai.io/en/latest/config_syntax.html).
|
116 |
+
|
117 |
+
#### Execute training
|
118 |
+
|
119 |
+
```
|
120 |
+
python -m monai.bundle run training --meta_file configs/metadata.json --config_file configs/train.json --logging_file configs/logging.conf
|
121 |
+
```
|
122 |
+
|
123 |
+
#### Override the `train` config to execute multi-GPU training
|
124 |
+
|
125 |
+
```
|
126 |
+
torchrun --standalone --nnodes=1 --nproc_per_node=2 -m monai.bundle run training --meta_file configs/metadata.json --config_file "['configs/train.json','configs/multi_gpu_train.json']" --logging_file configs/logging.conf
|
127 |
+
```
|
128 |
+
|
129 |
+
Please note that the distributed training-related options depend on the actual running environment; thus, users may need to remove `--standalone`, modify `--nnodes`, or do some other necessary changes according to the machine used. For more details, please refer to [pytorch's official tutorial](https://pytorch.org/tutorials/intermediate/ddp_tutorial.html).
|
130 |
+
|
131 |
+
#### Override the `train` config to execute evaluation with the trained model
|
132 |
+
|
133 |
+
```
|
134 |
+
python -m monai.bundle run evaluating --meta_file configs/metadata.json --config_file "['configs/train.json','configs/evaluate.json']" --logging_file configs/logging.conf
|
135 |
+
```
|
136 |
+
|
137 |
+
#### Override the `train` config and `evaluate` config to execute multi-GPU evaluation
|
138 |
+
|
139 |
+
```
|
140 |
+
torchrun --standalone --nnodes=1 --nproc_per_node=2 -m monai.bundle run evaluating --meta_file configs/metadata.json --config_file "['configs/train.json','configs/evaluate.json','configs/multi_gpu_evaluate.json']" --logging_file configs/logging.conf
|
141 |
+
```
|
142 |
+
|
143 |
+
#### Execute inference
|
144 |
+
|
145 |
+
```
|
146 |
+
python -m monai.bundle run evaluating --meta_file configs/metadata.json --config_file configs/inference.json --logging_file configs/logging.conf
|
147 |
+
```
|
148 |
+
#### Execute inference with Data Samples
|
149 |
+
|
150 |
+
```
|
151 |
+
python -m monai.bundle run evaluating --meta_file configs/metadata.json --config_file configs/inference.json --logging_file configs/logging.conf --datalist "['sampledata/imagesTr/s0037.nii.gz','sampledata/imagesTr/s0038.nii.gz']"
|
152 |
+
```
|
153 |
+
|
154 |
+
|
155 |
+
# References
|
156 |
+
|
157 |
+
[1] Tang, Y., Gao, R., Lee, H.H., Han, S., Chen, Y., Gao, D., Nath, V., Bermudez, C., Savona, M.R., Abramson, R.G. and Bao, S., 2021. High-resolution 3D abdominal segmentation with random patch network fusion. Medical image analysis, 69, p.101894.
|
158 |
+
|
159 |
+
[2] Wasserthal, J., Meyer, M., Breit, H.C., Cyriac, J., Yang, S. and Segeroth, M., 2022. TotalSegmentator: robust segmentation of 104 anatomical structures in CT images. arXiv preprint arXiv:2208.05868.
|
160 |
+
|
161 |
+
[3] Myronenko, A., Siddiquee, M.M.R., Yang, D., He, Y. and Xu, D., 2022. Automated head and neck tumor segmentation from 3D PET/CT. arXiv preprint arXiv:2209.10809.
|
162 |
+
|
163 |
+
|
164 |
+
|
165 |
+
# License
|
166 |
+
|
167 |
+
Copyright (c) MONAI Consortium
|
168 |
+
|
169 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
170 |
+
you may not use this file except in compliance with the License.
|
171 |
+
You may obtain a copy of the License at
|
172 |
+
|
173 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
174 |
+
|
175 |
+
Unless required by applicable law or agreed to in writing, software
|
176 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
177 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
178 |
+
See the License for the specific language governing permissions and
|
179 |
+
limitations under the License.
|
configs/evaluate.json
ADDED
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"validate#postprocessing": {
|
3 |
+
"_target_": "Compose",
|
4 |
+
"transforms": [
|
5 |
+
{
|
6 |
+
"_target_": "Activationsd",
|
7 |
+
"keys": "pred",
|
8 |
+
"softmax": true
|
9 |
+
},
|
10 |
+
{
|
11 |
+
"_target_": "AsDiscreted",
|
12 |
+
"keys": [
|
13 |
+
"pred",
|
14 |
+
"label"
|
15 |
+
],
|
16 |
+
"argmax": [
|
17 |
+
true,
|
18 |
+
false
|
19 |
+
],
|
20 |
+
"to_onehot": 105
|
21 |
+
},
|
22 |
+
{
|
23 |
+
"_target_": "Invertd",
|
24 |
+
"keys": [
|
25 |
+
"pred",
|
26 |
+
"label"
|
27 |
+
],
|
28 |
+
"transform": "@validate#preprocessing",
|
29 |
+
"orig_keys": "image",
|
30 |
+
"meta_key_postfix": "meta_dict",
|
31 |
+
"nearest_interp": [
|
32 |
+
true,
|
33 |
+
true
|
34 |
+
],
|
35 |
+
"to_tensor": true
|
36 |
+
},
|
37 |
+
{
|
38 |
+
"_target_": "SaveImaged",
|
39 |
+
"_disabled_": true,
|
40 |
+
"keys": "pred",
|
41 |
+
"meta_keys": "pred_meta_dict",
|
42 |
+
"output_dir": "@output_dir",
|
43 |
+
"resample": false,
|
44 |
+
"squeeze_end_dims": true
|
45 |
+
}
|
46 |
+
]
|
47 |
+
},
|
48 |
+
"validate#handlers": [
|
49 |
+
{
|
50 |
+
"_target_": "CheckpointLoader",
|
51 |
+
"load_path": "$@ckpt_dir + '/model.pt'",
|
52 |
+
"load_dict": {
|
53 |
+
"model": "@network"
|
54 |
+
}
|
55 |
+
},
|
56 |
+
{
|
57 |
+
"_target_": "StatsHandler",
|
58 |
+
"iteration_log": false
|
59 |
+
},
|
60 |
+
{
|
61 |
+
"_target_": "MetricsSaver",
|
62 |
+
"save_dir": "@output_dir",
|
63 |
+
"metrics": [
|
64 |
+
"val_mean_dice",
|
65 |
+
"val_acc"
|
66 |
+
],
|
67 |
+
"metric_details": [
|
68 |
+
"val_mean_dice"
|
69 |
+
],
|
70 |
+
"batch_transform": "$monai.handlers.from_engine(['image_meta_dict'])",
|
71 |
+
"summary_ops": "*"
|
72 |
+
}
|
73 |
+
],
|
74 |
+
"evaluating": [
|
75 |
+
"$setattr(torch.backends.cudnn, 'benchmark', True)",
|
76 |
+
"$@validate#evaluator.run()"
|
77 |
+
]
|
78 |
+
}
|
configs/inference.json
ADDED
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"displayable_configs": {
|
3 |
+
"highres": true,
|
4 |
+
"sw_overlap": 0.25,
|
5 |
+
"sw_batch_size": 1
|
6 |
+
},
|
7 |
+
"imports": [
|
8 |
+
"$import glob",
|
9 |
+
"$import os"
|
10 |
+
],
|
11 |
+
"bundle_root": ".",
|
12 |
+
"output_dir": "$@bundle_root + '/eval'",
|
13 |
+
"dataset_dir": "sampledata",
|
14 |
+
"datalist": "$list(sorted(glob.glob(@dataset_dir + '/imagesTs/*.nii.gz')))",
|
15 |
+
"device": "$torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')",
|
16 |
+
"pixdim": "$[1.5, 1.5, 1.5] if @displayable_configs#highres else [3.0, 3.0, 3.0]",
|
17 |
+
"modelname": "$'model.pt' if @displayable_configs#highres else 'model_lowres.pt'",
|
18 |
+
"network_def": {
|
19 |
+
"_target_": "SegResNet",
|
20 |
+
"spatial_dims": 3,
|
21 |
+
"in_channels": 1,
|
22 |
+
"out_channels": 105,
|
23 |
+
"init_filters": 32,
|
24 |
+
"blocks_down": [
|
25 |
+
1,
|
26 |
+
2,
|
27 |
+
2,
|
28 |
+
4
|
29 |
+
],
|
30 |
+
"blocks_up": [
|
31 |
+
1,
|
32 |
+
1,
|
33 |
+
1
|
34 |
+
],
|
35 |
+
"dropout_prob": 0.2
|
36 |
+
},
|
37 |
+
"network": "$@network_def.to(@device)",
|
38 |
+
"preprocessing": {
|
39 |
+
"_target_": "Compose",
|
40 |
+
"transforms": [
|
41 |
+
{
|
42 |
+
"_target_": "LoadImaged",
|
43 |
+
"keys": "image"
|
44 |
+
},
|
45 |
+
{
|
46 |
+
"_target_": "EnsureTyped",
|
47 |
+
"keys": "image"
|
48 |
+
},
|
49 |
+
{
|
50 |
+
"_target_": "EnsureChannelFirstd",
|
51 |
+
"keys": "image"
|
52 |
+
},
|
53 |
+
{
|
54 |
+
"_target_": "Orientationd",
|
55 |
+
"keys": "image",
|
56 |
+
"axcodes": "RAS"
|
57 |
+
},
|
58 |
+
{
|
59 |
+
"_target_": "Spacingd",
|
60 |
+
"keys": "image",
|
61 |
+
"pixdim": "@pixdim",
|
62 |
+
"mode": "bilinear"
|
63 |
+
},
|
64 |
+
{
|
65 |
+
"_target_": "NormalizeIntensityd",
|
66 |
+
"keys": "image",
|
67 |
+
"nonzero": true
|
68 |
+
},
|
69 |
+
{
|
70 |
+
"_target_": "ScaleIntensityd",
|
71 |
+
"keys": "image",
|
72 |
+
"minv": -1.0,
|
73 |
+
"maxv": 1.0
|
74 |
+
}
|
75 |
+
]
|
76 |
+
},
|
77 |
+
"dataset": {
|
78 |
+
"_target_": "Dataset",
|
79 |
+
"data": "$[{'image': i} for i in @datalist]",
|
80 |
+
"transform": "@preprocessing"
|
81 |
+
},
|
82 |
+
"dataloader": {
|
83 |
+
"_target_": "DataLoader",
|
84 |
+
"dataset": "@dataset",
|
85 |
+
"batch_size": 1,
|
86 |
+
"shuffle": false,
|
87 |
+
"num_workers": 1
|
88 |
+
},
|
89 |
+
"inferer": {
|
90 |
+
"_target_": "SlidingWindowInferer",
|
91 |
+
"roi_size": [
|
92 |
+
96,
|
93 |
+
96,
|
94 |
+
96
|
95 |
+
],
|
96 |
+
"sw_batch_size": "@displayable_configs#sw_batch_size",
|
97 |
+
"overlap": "@displayable_configs#sw_overlap",
|
98 |
+
"padding_mode": "replicate",
|
99 |
+
"mode": "gaussian",
|
100 |
+
"device": "$torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')"
|
101 |
+
},
|
102 |
+
"postprocessing": {
|
103 |
+
"_target_": "Compose",
|
104 |
+
"transforms": [
|
105 |
+
{
|
106 |
+
"_target_": "Activationsd",
|
107 |
+
"keys": "pred",
|
108 |
+
"softmax": true
|
109 |
+
},
|
110 |
+
{
|
111 |
+
"_target_": "AsDiscreted",
|
112 |
+
"keys": "pred",
|
113 |
+
"argmax": true
|
114 |
+
},
|
115 |
+
{
|
116 |
+
"_target_": "Invertd",
|
117 |
+
"keys": "pred",
|
118 |
+
"transform": "@preprocessing",
|
119 |
+
"orig_keys": "image",
|
120 |
+
"meta_key_postfix": "meta_dict",
|
121 |
+
"nearest_interp": true,
|
122 |
+
"to_tensor": true
|
123 |
+
},
|
124 |
+
{
|
125 |
+
"_target_": "SaveImaged",
|
126 |
+
"keys": "pred",
|
127 |
+
"meta_keys": "pred_meta_dict",
|
128 |
+
"output_dir": "@output_dir"
|
129 |
+
}
|
130 |
+
]
|
131 |
+
},
|
132 |
+
"handlers": [
|
133 |
+
{
|
134 |
+
"_target_": "CheckpointLoader",
|
135 |
+
"load_path": "$@bundle_root + '/models/' + @modelname",
|
136 |
+
"load_dict": {
|
137 |
+
"model": "@network"
|
138 |
+
}
|
139 |
+
},
|
140 |
+
{
|
141 |
+
"_target_": "StatsHandler",
|
142 |
+
"iteration_log": false
|
143 |
+
}
|
144 |
+
],
|
145 |
+
"evaluator": {
|
146 |
+
"_target_": "SupervisedEvaluator",
|
147 |
+
"device": "@device",
|
148 |
+
"val_data_loader": "@dataloader",
|
149 |
+
"network": "@network",
|
150 |
+
"inferer": "@inferer",
|
151 |
+
"postprocessing": "@postprocessing",
|
152 |
+
"val_handlers": "@handlers",
|
153 |
+
"amp": true
|
154 |
+
},
|
155 |
+
"evaluating": [
|
156 |
+
"$setattr(torch.backends.cudnn, 'benchmark', True)",
|
157 |
+
"$@evaluator.run()"
|
158 |
+
]
|
159 |
+
}
|
configs/logging.conf
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[loggers]
|
2 |
+
keys=root
|
3 |
+
|
4 |
+
[handlers]
|
5 |
+
keys=consoleHandler
|
6 |
+
|
7 |
+
[formatters]
|
8 |
+
keys=fullFormatter
|
9 |
+
|
10 |
+
[logger_root]
|
11 |
+
level=INFO
|
12 |
+
handlers=consoleHandler
|
13 |
+
|
14 |
+
[handler_consoleHandler]
|
15 |
+
class=StreamHandler
|
16 |
+
level=INFO
|
17 |
+
formatter=fullFormatter
|
18 |
+
args=(sys.stdout,)
|
19 |
+
|
20 |
+
[formatter_fullFormatter]
|
21 |
+
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
|
configs/metadata.json
ADDED
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"schema": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_20220324.json",
|
3 |
+
"version": "0.1.0",
|
4 |
+
"changelog": {
|
5 |
+
"0.1.0": "complete the model package",
|
6 |
+
"0.0.1": "initialize the model package structure"
|
7 |
+
},
|
8 |
+
"monai_version": "1.1.0",
|
9 |
+
"pytorch_version": "1.13.0",
|
10 |
+
"numpy_version": "1.21.2",
|
11 |
+
"optional_packages_version": {
|
12 |
+
"nibabel": "4.0.1",
|
13 |
+
"pytorch-ignite": "0.4.9"
|
14 |
+
},
|
15 |
+
"name": "Whole body CT segmentation",
|
16 |
+
"task": "TotalSegmentator Segmentation",
|
17 |
+
"description": "A pre-trained SegResNet model for volumetric (3D) segmentation of the 104 whole body segments",
|
18 |
+
"authors": "MONAI team",
|
19 |
+
"copyright": "Copyright (c) MONAI Consortium",
|
20 |
+
"data_source": "TotalSegmentator",
|
21 |
+
"data_type": "nibabel",
|
22 |
+
"image_classes": "104 foreground channels, 0 channel for the background, intensity scaled to [0, 1]",
|
23 |
+
"label_classes": "0 is the background, others are whole body segments",
|
24 |
+
"pred_classes": "0 is the background, 104 other chanels are whole body segments",
|
25 |
+
"eval_metrics": {
|
26 |
+
"mean_dice": 0.5
|
27 |
+
},
|
28 |
+
"intended_use": "This is an example, not to be used for diagnostic purposes",
|
29 |
+
"references": [
|
30 |
+
"Wasserthal, J., Meyer, M., Breit, H.C., Cyriac, J., Yang, S. and Segeroth, M., 2022. TotalSegmentator: robust segmentation of 104 anatomical structures in CT images. arXiv preprint arXiv:2208.05868.",
|
31 |
+
"Myronenko, A., Siddiquee, M.M.R., Yang, D., He, Y. and Xu, D., 2022. Automated head and neck tumor segmentation from 3D PET/CT. arXiv preprint arXiv:2209.10809.",
|
32 |
+
"Tang, Y., Gao, R., Lee, H.H., Han, S., Chen, Y., Gao, D., Nath, V., Bermudez, C., Savona, M.R., Abramson, R.G. and Bao, S., 2021. High-resolution 3D abdominal segmentation with random patch network fusion. Medical image analysis, 69, p.101894."
|
33 |
+
],
|
34 |
+
"network_data_format": {
|
35 |
+
"inputs": {
|
36 |
+
"image": {
|
37 |
+
"type": "image",
|
38 |
+
"format": "hounsfield",
|
39 |
+
"modality": "CT",
|
40 |
+
"num_channels": 1,
|
41 |
+
"spatial_shape": [
|
42 |
+
96,
|
43 |
+
96,
|
44 |
+
96
|
45 |
+
],
|
46 |
+
"dtype": "float32",
|
47 |
+
"value_range": [
|
48 |
+
0,
|
49 |
+
1
|
50 |
+
],
|
51 |
+
"is_patch_data": true,
|
52 |
+
"channel_def": {
|
53 |
+
"0": "image"
|
54 |
+
}
|
55 |
+
}
|
56 |
+
},
|
57 |
+
"outputs": {
|
58 |
+
"pred": {
|
59 |
+
"type": "image",
|
60 |
+
"format": "segmentation",
|
61 |
+
"num_channels": 105,
|
62 |
+
"spatial_shape": [
|
63 |
+
96,
|
64 |
+
96,
|
65 |
+
96
|
66 |
+
],
|
67 |
+
"dtype": "float32",
|
68 |
+
"value_range": [
|
69 |
+
0,
|
70 |
+
104
|
71 |
+
],
|
72 |
+
"is_patch_data": true,
|
73 |
+
"channel_def": {
|
74 |
+
"0": "background",
|
75 |
+
"1": "spleen",
|
76 |
+
"2": "kidney_right",
|
77 |
+
"3": "kidney_left",
|
78 |
+
"4": "gallbladder",
|
79 |
+
"5": "liver",
|
80 |
+
"6": "stomach",
|
81 |
+
"7": "aorta",
|
82 |
+
"8": "inferior_vena_cava",
|
83 |
+
"9": "portal_vein_and_splenic_vein",
|
84 |
+
"10": "pancreas",
|
85 |
+
"11": "adrenal_gland_right",
|
86 |
+
"12": "adrenal_gland_left",
|
87 |
+
"13": "lung_upper_lobe_left",
|
88 |
+
"14": "lung_lower_lobe_left",
|
89 |
+
"15": "lung_upper_lobe_right",
|
90 |
+
"16": "lung_middle_lobe_right",
|
91 |
+
"17": "lung_lower_lobe_right",
|
92 |
+
"18": "vertebrae_L5",
|
93 |
+
"19": "vertebrae_L4",
|
94 |
+
"20": "vertebrae_L3",
|
95 |
+
"21": "vertebrae_L2",
|
96 |
+
"22": "vertebrae_L1",
|
97 |
+
"23": "vertebrae_T12",
|
98 |
+
"24": "vertebrae_T11",
|
99 |
+
"25": "vertebrae_T10",
|
100 |
+
"26": "vertebrae_T9",
|
101 |
+
"27": "vertebrae_T8",
|
102 |
+
"28": "vertebrae_T7",
|
103 |
+
"29": "vertebrae_T6",
|
104 |
+
"30": "vertebrae_T5",
|
105 |
+
"31": "vertebrae_T4",
|
106 |
+
"32": "vertebrae_T3",
|
107 |
+
"33": "vertebrae_T2",
|
108 |
+
"34": "vertebrae_T1",
|
109 |
+
"35": "vertebrae_C7",
|
110 |
+
"36": "vertebrae_C6",
|
111 |
+
"37": "vertebrae_C5",
|
112 |
+
"38": "vertebrae_C4",
|
113 |
+
"39": "vertebrae_C3",
|
114 |
+
"40": "vertebrae_C2",
|
115 |
+
"41": "vertebrae_C1",
|
116 |
+
"42": "esophagus",
|
117 |
+
"43": "trachea",
|
118 |
+
"44": "heart_myocardium",
|
119 |
+
"45": "heart_atrium_left",
|
120 |
+
"46": "heart_ventricle_left",
|
121 |
+
"47": "heart_atrium_right",
|
122 |
+
"48": "heart_ventricle_right",
|
123 |
+
"49": "pulmonary_artery",
|
124 |
+
"50": "brain",
|
125 |
+
"51": "iliac_artery_left",
|
126 |
+
"52": "iliac_artery_right",
|
127 |
+
"53": "iliac_vena_left",
|
128 |
+
"54": "iliac_vena_right",
|
129 |
+
"55": "small_bowel",
|
130 |
+
"56": "duodenum",
|
131 |
+
"57": "colon",
|
132 |
+
"58": "rib_left_1",
|
133 |
+
"59": "rib_left_2",
|
134 |
+
"60": "rib_left_3",
|
135 |
+
"61": "rib_left_4",
|
136 |
+
"62": "rib_left_5",
|
137 |
+
"63": "rib_left_6",
|
138 |
+
"64": "rib_left_7",
|
139 |
+
"65": "rib_left_8",
|
140 |
+
"66": "rib_left_9",
|
141 |
+
"67": "rib_left_10",
|
142 |
+
"68": "rib_left_11",
|
143 |
+
"69": "rib_left_12",
|
144 |
+
"70": "rib_right_1",
|
145 |
+
"71": "rib_right_2",
|
146 |
+
"72": "rib_right_3",
|
147 |
+
"73": "rib_right_4",
|
148 |
+
"74": "rib_right_5",
|
149 |
+
"75": "rib_right_6",
|
150 |
+
"76": "rib_right_7",
|
151 |
+
"77": "rib_right_8",
|
152 |
+
"78": "rib_right_9",
|
153 |
+
"79": "rib_right_10",
|
154 |
+
"80": "rib_right_11",
|
155 |
+
"81": "rib_right_12",
|
156 |
+
"82": "humerus_left",
|
157 |
+
"83": "humerus_right",
|
158 |
+
"84": "scapula_left",
|
159 |
+
"85": "scapula_right",
|
160 |
+
"86": "clavicula_left",
|
161 |
+
"87": "clavicula_right",
|
162 |
+
"88": "femur_left",
|
163 |
+
"89": "femur_right",
|
164 |
+
"90": "hip_left",
|
165 |
+
"91": "hip_right",
|
166 |
+
"92": "sacrum",
|
167 |
+
"93": "face",
|
168 |
+
"94": "gluteus_maximus_left",
|
169 |
+
"95": "gluteus_maximus_right",
|
170 |
+
"96": "gluteus_medius_left",
|
171 |
+
"97": "gluteus_medius_right",
|
172 |
+
"98": "gluteus_minimus_left",
|
173 |
+
"99": "gluteus_minimus_right",
|
174 |
+
"100": "autochthon_left",
|
175 |
+
"101": "autochthon_right",
|
176 |
+
"102": "iliopsoas_left",
|
177 |
+
"103": "iliopsoas_right",
|
178 |
+
"104": "urinary_bladder"
|
179 |
+
}
|
180 |
+
}
|
181 |
+
}
|
182 |
+
}
|
183 |
+
}
|
configs/multi_gpu_evaluate.json
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"device": "$torch.device(f'cuda:{dist.get_rank()}')",
|
3 |
+
"network": {
|
4 |
+
"_target_": "torch.nn.parallel.DistributedDataParallel",
|
5 |
+
"module": "$@network_def.to(@device)",
|
6 |
+
"device_ids": [
|
7 |
+
"@device"
|
8 |
+
]
|
9 |
+
},
|
10 |
+
"validate#sampler": {
|
11 |
+
"_target_": "DistributedSampler",
|
12 |
+
"dataset": "@validate#dataset",
|
13 |
+
"even_divisible": false,
|
14 |
+
"shuffle": false
|
15 |
+
},
|
16 |
+
"validate#dataloader#sampler": "@validate#sampler",
|
17 |
+
"validate#handlers#1#_disabled_": "$dist.get_rank() > 0",
|
18 |
+
"evaluating": [
|
19 |
+
"$import torch.distributed as dist",
|
20 |
+
"$dist.init_process_group(backend='nccl')",
|
21 |
+
"$torch.cuda.set_device(@device)",
|
22 |
+
"$setattr(torch.backends.cudnn, 'benchmark', True)",
|
23 |
+
"$import logging",
|
24 |
+
"$@validate#evaluator.logger.setLevel(logging.WARNING if dist.get_rank() > 0 else logging.INFO)",
|
25 |
+
"$@validate#evaluator.run()",
|
26 |
+
"$dist.destroy_process_group()"
|
27 |
+
]
|
28 |
+
}
|
configs/multi_gpu_train.json
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"device": "$torch.device(f'cuda:{dist.get_rank()}')",
|
3 |
+
"network": {
|
4 |
+
"_target_": "torch.nn.parallel.DistributedDataParallel",
|
5 |
+
"module": "$@network_def.to(@device)",
|
6 |
+
"device_ids": [
|
7 |
+
"@device"
|
8 |
+
]
|
9 |
+
},
|
10 |
+
"train#sampler": {
|
11 |
+
"_target_": "DistributedSampler",
|
12 |
+
"dataset": "@train#dataset",
|
13 |
+
"even_divisible": true,
|
14 |
+
"shuffle": true
|
15 |
+
},
|
16 |
+
"train#dataloader#sampler": "@train#sampler",
|
17 |
+
"train#dataloader#shuffle": false,
|
18 |
+
"train#trainer#train_handlers": "$@train#handlers[: -2 if dist.get_rank() > 0 else None]",
|
19 |
+
"validate#sampler": {
|
20 |
+
"_target_": "DistributedSampler",
|
21 |
+
"dataset": "@validate#dataset",
|
22 |
+
"even_divisible": false,
|
23 |
+
"shuffle": false
|
24 |
+
},
|
25 |
+
"validate#dataloader#sampler": "@validate#sampler",
|
26 |
+
"validate#evaluator#val_handlers": "$None if dist.get_rank() > 0 else @validate#handlers",
|
27 |
+
"training": [
|
28 |
+
"$import torch.distributed as dist",
|
29 |
+
"$dist.init_process_group(backend='nccl')",
|
30 |
+
"$torch.cuda.set_device(@device)",
|
31 |
+
"$monai.utils.set_determinism(seed=123)",
|
32 |
+
"$setattr(torch.backends.cudnn, 'benchmark', True)",
|
33 |
+
"$import logging",
|
34 |
+
"$@train#trainer.logger.setLevel(logging.WARNING if dist.get_rank() > 0 else logging.INFO)",
|
35 |
+
"$@validate#evaluator.logger.setLevel(logging.WARNING if dist.get_rank() > 0 else logging.INFO)",
|
36 |
+
"$@train#trainer.run()",
|
37 |
+
"$dist.destroy_process_group()"
|
38 |
+
]
|
39 |
+
}
|
configs/train.json
ADDED
@@ -0,0 +1,422 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"displayable_configs": {
|
3 |
+
"highres": true,
|
4 |
+
"init_LR": 0.0001
|
5 |
+
},
|
6 |
+
"imports": [
|
7 |
+
"$import glob",
|
8 |
+
"$import os",
|
9 |
+
"$import ignite"
|
10 |
+
],
|
11 |
+
"bundle_root": ".",
|
12 |
+
"ckpt_dir": "$@bundle_root + '/models'",
|
13 |
+
"output_dir": "$@bundle_root + '/eval'",
|
14 |
+
"dataset_dir": "sampledata",
|
15 |
+
"images": "$list(sorted(glob.glob(@dataset_dir + '/imagesTr/*.nii.gz')))",
|
16 |
+
"labels": "$list(sorted(glob.glob(@dataset_dir + '/labelsTr/*.nii.gz')))",
|
17 |
+
"highres": true,
|
18 |
+
"val_interval": 20,
|
19 |
+
"init_LR": 0.0001,
|
20 |
+
"batch_size": 4,
|
21 |
+
"pixdim": "$[1.5, 1.5, 1.5] if @displayable_configs#highres else [3.0, 3.0, 3.0]",
|
22 |
+
"modelname": "$'model.pt' if @displayable_configs#highres else 'model_lowres.pt'",
|
23 |
+
"device": "$torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')",
|
24 |
+
"network_def": {
|
25 |
+
"_target_": "SegResNet",
|
26 |
+
"spatial_dims": 3,
|
27 |
+
"in_channels": 1,
|
28 |
+
"out_channels": 105,
|
29 |
+
"init_filters": 32,
|
30 |
+
"blocks_down": [
|
31 |
+
1,
|
32 |
+
2,
|
33 |
+
2,
|
34 |
+
4
|
35 |
+
],
|
36 |
+
"blocks_up": [
|
37 |
+
1,
|
38 |
+
1,
|
39 |
+
1
|
40 |
+
],
|
41 |
+
"dropout_prob": 0.2
|
42 |
+
},
|
43 |
+
"network": "$@network_def.to(@device)",
|
44 |
+
"loss": {
|
45 |
+
"_target_": "DiceCELoss",
|
46 |
+
"to_onehot_y": true,
|
47 |
+
"softmax": true
|
48 |
+
},
|
49 |
+
"optimizer": {
|
50 |
+
"_target_": "torch.optim.AdamW",
|
51 |
+
"params": "$@network.parameters()",
|
52 |
+
"lr": "@displayable_configs#init_LR",
|
53 |
+
"weight_decay": 1e-05
|
54 |
+
},
|
55 |
+
"train": {
|
56 |
+
"deterministic_transforms": [
|
57 |
+
{
|
58 |
+
"_target_": "LoadImaged",
|
59 |
+
"keys": [
|
60 |
+
"image",
|
61 |
+
"label"
|
62 |
+
]
|
63 |
+
},
|
64 |
+
{
|
65 |
+
"_target_": "EnsureChannelFirstd",
|
66 |
+
"keys": [
|
67 |
+
"image",
|
68 |
+
"label"
|
69 |
+
]
|
70 |
+
},
|
71 |
+
{
|
72 |
+
"_target_": "EnsureTyped",
|
73 |
+
"keys": [
|
74 |
+
"image",
|
75 |
+
"label"
|
76 |
+
]
|
77 |
+
},
|
78 |
+
{
|
79 |
+
"_target_": "Orientationd",
|
80 |
+
"keys": [
|
81 |
+
"image",
|
82 |
+
"label"
|
83 |
+
],
|
84 |
+
"axcodes": "RAS"
|
85 |
+
},
|
86 |
+
{
|
87 |
+
"_target_": "Spacingd",
|
88 |
+
"keys": [
|
89 |
+
"image",
|
90 |
+
"label"
|
91 |
+
],
|
92 |
+
"pixdim": "@pixdim",
|
93 |
+
"mode": [
|
94 |
+
"bilinear",
|
95 |
+
"nearest"
|
96 |
+
]
|
97 |
+
},
|
98 |
+
{
|
99 |
+
"_target_": "NormalizeIntensityd",
|
100 |
+
"keys": "image",
|
101 |
+
"nonzero": true
|
102 |
+
},
|
103 |
+
{
|
104 |
+
"_target_": "CropForegroundd",
|
105 |
+
"keys": [
|
106 |
+
"image",
|
107 |
+
"label"
|
108 |
+
],
|
109 |
+
"source_key": "image",
|
110 |
+
"margin": 10,
|
111 |
+
"k_divisible": [
|
112 |
+
96,
|
113 |
+
96,
|
114 |
+
96
|
115 |
+
]
|
116 |
+
},
|
117 |
+
{
|
118 |
+
"_target_": "GaussianSmoothd",
|
119 |
+
"keys": [
|
120 |
+
"image"
|
121 |
+
],
|
122 |
+
"sigma": 0.4
|
123 |
+
},
|
124 |
+
{
|
125 |
+
"_target_": "ScaleIntensityd",
|
126 |
+
"keys": "image",
|
127 |
+
"minv": -1.0,
|
128 |
+
"maxv": 1.0
|
129 |
+
},
|
130 |
+
{
|
131 |
+
"_target_": "EnsureTyped",
|
132 |
+
"keys": [
|
133 |
+
"image",
|
134 |
+
"label"
|
135 |
+
]
|
136 |
+
}
|
137 |
+
],
|
138 |
+
"random_transforms": [
|
139 |
+
{
|
140 |
+
"_target_": "RandSpatialCropd",
|
141 |
+
"keys": [
|
142 |
+
"image",
|
143 |
+
"label"
|
144 |
+
],
|
145 |
+
"roi_size": [
|
146 |
+
96,
|
147 |
+
96,
|
148 |
+
96
|
149 |
+
],
|
150 |
+
"random_size": false
|
151 |
+
}
|
152 |
+
],
|
153 |
+
"preprocessing": {
|
154 |
+
"_target_": "Compose",
|
155 |
+
"transforms": "$@train#deterministic_transforms + @train#random_transforms"
|
156 |
+
},
|
157 |
+
"dataset": {
|
158 |
+
"_target_": "CacheDataset",
|
159 |
+
"data": "$[{'image': i, 'label': l} for i, l in zip(@images[:-10], @labels[:-10])]",
|
160 |
+
"transform": "@train#preprocessing",
|
161 |
+
"cache_rate": 0.4,
|
162 |
+
"num_workers": 4
|
163 |
+
},
|
164 |
+
"dataloader": {
|
165 |
+
"_target_": "DataLoader",
|
166 |
+
"dataset": "@train#dataset",
|
167 |
+
"batch_size": "@batch_size",
|
168 |
+
"shuffle": true,
|
169 |
+
"num_workers": 4
|
170 |
+
},
|
171 |
+
"inferer": {
|
172 |
+
"_target_": "SimpleInferer"
|
173 |
+
},
|
174 |
+
"postprocessing": {
|
175 |
+
"_target_": "Compose",
|
176 |
+
"transforms": [
|
177 |
+
{
|
178 |
+
"_target_": "Activationsd",
|
179 |
+
"keys": "pred",
|
180 |
+
"softmax": true
|
181 |
+
},
|
182 |
+
{
|
183 |
+
"_target_": "AsDiscreted",
|
184 |
+
"keys": [
|
185 |
+
"pred",
|
186 |
+
"label"
|
187 |
+
],
|
188 |
+
"argmax": [
|
189 |
+
true,
|
190 |
+
false
|
191 |
+
],
|
192 |
+
"to_onehot": 105
|
193 |
+
}
|
194 |
+
]
|
195 |
+
},
|
196 |
+
"handlers": [
|
197 |
+
{
|
198 |
+
"_target_": "ValidationHandler",
|
199 |
+
"validator": "@validate#evaluator",
|
200 |
+
"epoch_level": true,
|
201 |
+
"interval": "@val_interval"
|
202 |
+
},
|
203 |
+
{
|
204 |
+
"_target_": "StatsHandler",
|
205 |
+
"tag_name": "train_loss",
|
206 |
+
"output_transform": "$monai.handlers.from_engine(['loss'], first=True)"
|
207 |
+
},
|
208 |
+
{
|
209 |
+
"_target_": "TensorBoardStatsHandler",
|
210 |
+
"log_dir": "@output_dir",
|
211 |
+
"tag_name": "train_loss",
|
212 |
+
"output_transform": "$monai.handlers.from_engine(['loss'], first=True)"
|
213 |
+
}
|
214 |
+
],
|
215 |
+
"key_metric": {
|
216 |
+
"train_accuracy": {
|
217 |
+
"_target_": "ignite.metrics.Accuracy",
|
218 |
+
"output_transform": "$monai.handlers.from_engine(['pred', 'label'])"
|
219 |
+
}
|
220 |
+
},
|
221 |
+
"trainer": {
|
222 |
+
"_target_": "SupervisedTrainer",
|
223 |
+
"max_epochs": 4000,
|
224 |
+
"device": "@device",
|
225 |
+
"train_data_loader": "@train#dataloader",
|
226 |
+
"network": "@network",
|
227 |
+
"loss_function": "@loss",
|
228 |
+
"optimizer": "@optimizer",
|
229 |
+
"inferer": "@train#inferer",
|
230 |
+
"postprocessing": "@train#postprocessing",
|
231 |
+
"key_train_metric": "@train#key_metric",
|
232 |
+
"train_handlers": "@train#handlers",
|
233 |
+
"amp": true
|
234 |
+
}
|
235 |
+
},
|
236 |
+
"validate": {
|
237 |
+
"preprocessing": {
|
238 |
+
"_target_": "Compose",
|
239 |
+
"transforms": [
|
240 |
+
{
|
241 |
+
"_target_": "LoadImaged",
|
242 |
+
"keys": [
|
243 |
+
"image",
|
244 |
+
"label"
|
245 |
+
]
|
246 |
+
},
|
247 |
+
{
|
248 |
+
"_target_": "EnsureChannelFirstd",
|
249 |
+
"keys": [
|
250 |
+
"image",
|
251 |
+
"label"
|
252 |
+
]
|
253 |
+
},
|
254 |
+
{
|
255 |
+
"_target_": "EnsureTyped",
|
256 |
+
"keys": [
|
257 |
+
"image",
|
258 |
+
"label"
|
259 |
+
]
|
260 |
+
},
|
261 |
+
{
|
262 |
+
"_target_": "Orientationd",
|
263 |
+
"keys": [
|
264 |
+
"image",
|
265 |
+
"label"
|
266 |
+
],
|
267 |
+
"axcodes": "RAS"
|
268 |
+
},
|
269 |
+
{
|
270 |
+
"_target_": "Spacingd",
|
271 |
+
"keys": [
|
272 |
+
"image",
|
273 |
+
"label"
|
274 |
+
],
|
275 |
+
"pixdim": "@pixdim",
|
276 |
+
"mode": [
|
277 |
+
"bilinear",
|
278 |
+
"nearest"
|
279 |
+
]
|
280 |
+
},
|
281 |
+
{
|
282 |
+
"_target_": "NormalizeIntensityd",
|
283 |
+
"keys": "image",
|
284 |
+
"nonzero": true
|
285 |
+
},
|
286 |
+
{
|
287 |
+
"_target_": "CropForegroundd",
|
288 |
+
"keys": [
|
289 |
+
"image",
|
290 |
+
"label"
|
291 |
+
],
|
292 |
+
"source_key": "image",
|
293 |
+
"margin": 10,
|
294 |
+
"k_divisible": [
|
295 |
+
96,
|
296 |
+
96,
|
297 |
+
96
|
298 |
+
]
|
299 |
+
},
|
300 |
+
{
|
301 |
+
"_target_": "GaussianSmoothd",
|
302 |
+
"keys": [
|
303 |
+
"image"
|
304 |
+
],
|
305 |
+
"sigma": 0.4
|
306 |
+
},
|
307 |
+
{
|
308 |
+
"_target_": "ScaleIntensityd",
|
309 |
+
"keys": "image",
|
310 |
+
"minv": -1.0,
|
311 |
+
"maxv": 1.0
|
312 |
+
},
|
313 |
+
{
|
314 |
+
"_target_": "CenterSpatialCropd",
|
315 |
+
"keys": [
|
316 |
+
"image",
|
317 |
+
"label"
|
318 |
+
],
|
319 |
+
"roi_size": [
|
320 |
+
160,
|
321 |
+
160,
|
322 |
+
160
|
323 |
+
]
|
324 |
+
}
|
325 |
+
]
|
326 |
+
},
|
327 |
+
"postprocessing": {
|
328 |
+
"_target_": "Compose",
|
329 |
+
"transforms": [
|
330 |
+
{
|
331 |
+
"_target_": "Activationsd",
|
332 |
+
"keys": "pred",
|
333 |
+
"softmax": true
|
334 |
+
},
|
335 |
+
{
|
336 |
+
"_target_": "AsDiscreted",
|
337 |
+
"keys": [
|
338 |
+
"pred",
|
339 |
+
"label"
|
340 |
+
],
|
341 |
+
"argmax": [
|
342 |
+
true,
|
343 |
+
false
|
344 |
+
],
|
345 |
+
"to_onehot": 105
|
346 |
+
}
|
347 |
+
]
|
348 |
+
},
|
349 |
+
"dataset": {
|
350 |
+
"_target_": "Dataset",
|
351 |
+
"data": "$[{'image': i, 'label': l} for i, l in zip(@images[-10:], @labels[-10:])]",
|
352 |
+
"transform": "@validate#preprocessing"
|
353 |
+
},
|
354 |
+
"dataloader": {
|
355 |
+
"_target_": "DataLoader",
|
356 |
+
"dataset": "@validate#dataset",
|
357 |
+
"batch_size": 1,
|
358 |
+
"shuffle": false,
|
359 |
+
"num_workers": 4
|
360 |
+
},
|
361 |
+
"inferer": {
|
362 |
+
"_target_": "SlidingWindowInferer",
|
363 |
+
"roi_size": [
|
364 |
+
96,
|
365 |
+
96,
|
366 |
+
96
|
367 |
+
],
|
368 |
+
"sw_batch_size": 1,
|
369 |
+
"overlap": 0.25
|
370 |
+
},
|
371 |
+
"handlers": [
|
372 |
+
{
|
373 |
+
"_target_": "StatsHandler",
|
374 |
+
"iteration_log": false
|
375 |
+
},
|
376 |
+
{
|
377 |
+
"_target_": "TensorBoardStatsHandler",
|
378 |
+
"log_dir": "@output_dir",
|
379 |
+
"iteration_log": false
|
380 |
+
},
|
381 |
+
{
|
382 |
+
"_target_": "CheckpointSaver",
|
383 |
+
"save_dir": "@ckpt_dir",
|
384 |
+
"save_dict": {
|
385 |
+
"model": "@network"
|
386 |
+
},
|
387 |
+
"save_key_metric": true,
|
388 |
+
"key_metric_filename": "@modelname"
|
389 |
+
}
|
390 |
+
],
|
391 |
+
"key_metric": {
|
392 |
+
"val_mean_dice": {
|
393 |
+
"_target_": "MeanDice",
|
394 |
+
"include_background": false,
|
395 |
+
"output_transform": "$monai.handlers.from_engine(['pred', 'label'])"
|
396 |
+
}
|
397 |
+
},
|
398 |
+
"additional_metrics": {
|
399 |
+
"val_accuracy": {
|
400 |
+
"_target_": "ignite.metrics.Accuracy",
|
401 |
+
"output_transform": "$monai.handlers.from_engine(['pred', 'label'])"
|
402 |
+
}
|
403 |
+
},
|
404 |
+
"evaluator": {
|
405 |
+
"_target_": "SupervisedEvaluator",
|
406 |
+
"device": "@device",
|
407 |
+
"val_data_loader": "@validate#dataloader",
|
408 |
+
"network": "@network",
|
409 |
+
"inferer": "@validate#inferer",
|
410 |
+
"postprocessing": "@validate#postprocessing",
|
411 |
+
"key_val_metric": "@validate#key_metric",
|
412 |
+
"additional_metrics": "@validate#additional_metrics",
|
413 |
+
"val_handlers": "@validate#handlers",
|
414 |
+
"amp": true
|
415 |
+
}
|
416 |
+
},
|
417 |
+
"training": [
|
418 |
+
"$monai.utils.set_determinism(seed=123)",
|
419 |
+
"$setattr(torch.backends.cudnn, 'benchmark', True)",
|
420 |
+
"$@train#trainer.run()"
|
421 |
+
]
|
422 |
+
}
|
docs/README.md
ADDED
@@ -0,0 +1,172 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Model Overview
|
2 |
+
|
3 |
+
Body CT segmentation models are evolving. Starting from abdominal multi-organ segmentation model [1]. Now the community is developing hundreds of target anatomies. In this bundle, we provide re-trained models for (3D) segmentation of 104 whole-body segments.
|
4 |
+
|
5 |
+
This model is trained using the SegResNet [3] network. The model is trained using TotalSegmentator datasets [2].
|
6 |
+
|
7 |
+
![structures](https://github.com/wasserth/TotalSegmentator/blob/master/resources/imgs/overview_classes.png)
|
8 |
+
|
9 |
+
Figure source from the TotalSegmentator [2].
|
10 |
+
|
11 |
+
## MONAI Label Showcase
|
12 |
+
|
13 |
+
- We highlight the use of this bundle to use and visualize in MONAI Label + 3D Slicer integration.
|
14 |
+
|
15 |
+
![](./imgs/totalsegmentator_monailabel.png) <br>
|
16 |
+
|
17 |
+
## Data
|
18 |
+
|
19 |
+
The training set is the 104 whole-body structures from the TotalSegmentator released datasets. Users can find more details on the datasets at https://github.com/wasserth/TotalSegmentator. All rights and licenses are reserved to the original authors.
|
20 |
+
|
21 |
+
- Target: 104 structures
|
22 |
+
- Modality: CT
|
23 |
+
- Source: TotalSegmentator
|
24 |
+
- Challenge: Large volumes of structures in CT images
|
25 |
+
|
26 |
+
### Preprocessing
|
27 |
+
|
28 |
+
To use the bundle, users need to download the data and merge all annotated labels into one NIFTI file. Each file contains 0-104 values, each value represents one anatomy class. A sample set is provided with this [link](https://drive.google.com/file/d/1DtDmERVMjks1HooUhggOKAuDm0YIEunG/view?usp=share_link).
|
29 |
+
|
30 |
+
## Training Configuration
|
31 |
+
|
32 |
+
The segmentation of 104 tissues is formulated as voxel-wise multi-label segmentation. The model is optimized with the gradient descent method minimizing Dice + cross-entropy loss between the predicted mask and ground truth segmentation.
|
33 |
+
|
34 |
+
The training was performed with the following:
|
35 |
+
|
36 |
+
- GPU: 32 GB of GPU memory
|
37 |
+
- Actual Model Input: 96 x 96 x 96
|
38 |
+
- AMP: True
|
39 |
+
- Optimizer: AdamW
|
40 |
+
- Learning Rate: 1e-4
|
41 |
+
- Loss: DiceCELoss
|
42 |
+
|
43 |
+
### Input
|
44 |
+
|
45 |
+
One channel
|
46 |
+
- CT image
|
47 |
+
|
48 |
+
### Output
|
49 |
+
|
50 |
+
105 channels
|
51 |
+
- Label 0: Background (everything else)
|
52 |
+
- label 1-105: Foreground classes (104)
|
53 |
+
|
54 |
+
### High-Resolution and Low-Resolution Models
|
55 |
+
|
56 |
+
We retrained two versions of the totalSegmentator models, following the original paper and implementation.
|
57 |
+
To meet multiple demands according to computation resources and performance, we provide a 1.5 mm model and a 3.0 mm model, both models are trained with 104 foreground output channels.
|
58 |
+
|
59 |
+
In this bundle, we configured a parameter called `highres`, users can set it to `true` when using 1.5 mm model, and set it to `false` to use the 3.0 mm model. The high-resolution model is named `model.pt` by default, the low-resolution model is named `model_lowres.pt`.
|
60 |
+
|
61 |
+
In MONAI Label use case, users can set the parameter in 3D Slicer plugin to control which model to infer and train.
|
62 |
+
|
63 |
+
- Pretrained Checkpoints
|
64 |
+
- 1.5 mm model: [Download link](https://drive.google.com/file/d/1PHpFWboimEXmMSe2vBra6T8SaCMC2SHT/view?usp=share_link)
|
65 |
+
- 3.0 mm model: [Download link](https://drive.google.com/file/d/1c3osYscnr6710ObqZZS8GkZJQlWlc7rt/view?usp=share_link)
|
66 |
+
|
67 |
+
### Resource Requirements and Latency Benchmarks
|
68 |
+
|
69 |
+
Latencies and memory performance of using the bundle with MONAI Label:
|
70 |
+
|
71 |
+
Tested Image Dimension: **(512, 512, 397)**, the slice thickness is **1.5mm** in this case. After resample to **1.5** isotropic resolution, the dimension is **(287, 287, 397)**
|
72 |
+
|
73 |
+
## 1.5 mm (highres) model (Single Model with 104 foreground classes)
|
74 |
+
|
75 |
+
Benchmarking on GPU: Memory: **28.73G**
|
76 |
+
|
77 |
+
- `++ Latencies => Total: 6.0277; Pre: 1.6228; Inferer: 4.1153; Invert: 0.0000; Post: 0.0897; Write: 0.1995`
|
78 |
+
|
79 |
+
Benchmarking on CPU: Memory: **26G**
|
80 |
+
|
81 |
+
- `++ Latencies => Total: 38.3108; Pre: 1.6643; Inferer: 30.3018; Invert: 0.0000; Post: 6.1656; Write: 0.1786`
|
82 |
+
|
83 |
+
## 3.0 mm (lowres) model (single model with 104 foreground classes)
|
84 |
+
|
85 |
+
GPU: Memory: **5.89G**
|
86 |
+
|
87 |
+
- `++ Latencies => Total: 1.9993; Pre: 1.2363; Inferer: 0.5207; Invert: 0.0000; Post: 0.0358; Write: 0.2060`
|
88 |
+
|
89 |
+
CPU: Memory: **2.3G**
|
90 |
+
|
91 |
+
- `++ Latencies => Total: 6.6138; Pre: 1.3192; Inferer: 3.6746; Invert: 0.0000; Post: 1.4431; Write: 0.1760`
|
92 |
+
|
93 |
+
## Performance
|
94 |
+
|
95 |
+
- 1.5 mm Model Training
|
96 |
+
|
97 |
+
- Training Accuracy
|
98 |
+
|
99 |
+
![](./imgs/totalsegmentator_train_accuracy.png) <br>
|
100 |
+
|
101 |
+
- Validation Dice
|
102 |
+
|
103 |
+
![](./imgs/totalsegmentator_15mm_validation.png) <br>
|
104 |
+
|
105 |
+
## MONAI Bundle Commands
|
106 |
+
In addition to the Pythonic APIs, a few command line interfaces (CLI) are provided to interact with the bundle. The CLI supports flexible use cases, such as overriding configs at runtime and predefining arguments in a file.
|
107 |
+
|
108 |
+
For more details usage instructions, visit the [MONAI Bundle Configuration Page](https://docs.monai.io/en/latest/config_syntax.html).
|
109 |
+
|
110 |
+
#### Execute training
|
111 |
+
|
112 |
+
```
|
113 |
+
python -m monai.bundle run training --meta_file configs/metadata.json --config_file configs/train.json --logging_file configs/logging.conf
|
114 |
+
```
|
115 |
+
|
116 |
+
#### Override the `train` config to execute multi-GPU training
|
117 |
+
|
118 |
+
```
|
119 |
+
torchrun --standalone --nnodes=1 --nproc_per_node=2 -m monai.bundle run training --meta_file configs/metadata.json --config_file "['configs/train.json','configs/multi_gpu_train.json']" --logging_file configs/logging.conf
|
120 |
+
```
|
121 |
+
|
122 |
+
Please note that the distributed training-related options depend on the actual running environment; thus, users may need to remove `--standalone`, modify `--nnodes`, or do some other necessary changes according to the machine used. For more details, please refer to [pytorch's official tutorial](https://pytorch.org/tutorials/intermediate/ddp_tutorial.html).
|
123 |
+
|
124 |
+
#### Override the `train` config to execute evaluation with the trained model
|
125 |
+
|
126 |
+
```
|
127 |
+
python -m monai.bundle run evaluating --meta_file configs/metadata.json --config_file "['configs/train.json','configs/evaluate.json']" --logging_file configs/logging.conf
|
128 |
+
```
|
129 |
+
|
130 |
+
#### Override the `train` config and `evaluate` config to execute multi-GPU evaluation
|
131 |
+
|
132 |
+
```
|
133 |
+
torchrun --standalone --nnodes=1 --nproc_per_node=2 -m monai.bundle run evaluating --meta_file configs/metadata.json --config_file "['configs/train.json','configs/evaluate.json','configs/multi_gpu_evaluate.json']" --logging_file configs/logging.conf
|
134 |
+
```
|
135 |
+
|
136 |
+
#### Execute inference
|
137 |
+
|
138 |
+
```
|
139 |
+
python -m monai.bundle run evaluating --meta_file configs/metadata.json --config_file configs/inference.json --logging_file configs/logging.conf
|
140 |
+
```
|
141 |
+
#### Execute inference with Data Samples
|
142 |
+
|
143 |
+
```
|
144 |
+
python -m monai.bundle run evaluating --meta_file configs/metadata.json --config_file configs/inference.json --logging_file configs/logging.conf --datalist "['sampledata/imagesTr/s0037.nii.gz','sampledata/imagesTr/s0038.nii.gz']"
|
145 |
+
```
|
146 |
+
|
147 |
+
|
148 |
+
# References
|
149 |
+
|
150 |
+
[1] Tang, Y., Gao, R., Lee, H.H., Han, S., Chen, Y., Gao, D., Nath, V., Bermudez, C., Savona, M.R., Abramson, R.G. and Bao, S., 2021. High-resolution 3D abdominal segmentation with random patch network fusion. Medical image analysis, 69, p.101894.
|
151 |
+
|
152 |
+
[2] Wasserthal, J., Meyer, M., Breit, H.C., Cyriac, J., Yang, S. and Segeroth, M., 2022. TotalSegmentator: robust segmentation of 104 anatomical structures in CT images. arXiv preprint arXiv:2208.05868.
|
153 |
+
|
154 |
+
[3] Myronenko, A., Siddiquee, M.M.R., Yang, D., He, Y. and Xu, D., 2022. Automated head and neck tumor segmentation from 3D PET/CT. arXiv preprint arXiv:2209.10809.
|
155 |
+
|
156 |
+
|
157 |
+
|
158 |
+
# License
|
159 |
+
|
160 |
+
Copyright (c) MONAI Consortium
|
161 |
+
|
162 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
163 |
+
you may not use this file except in compliance with the License.
|
164 |
+
You may obtain a copy of the License at
|
165 |
+
|
166 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
167 |
+
|
168 |
+
Unless required by applicable law or agreed to in writing, software
|
169 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
170 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
171 |
+
See the License for the specific language governing permissions and
|
172 |
+
limitations under the License.
|
docs/data_license.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Third Party Licenses
|
2 |
+
-----------------------------------------------------------------------
|
3 |
+
|
4 |
+
/*********************************************************************/
|
5 |
+
i. TotalSegmentator
|
6 |
+
https://zenodo.org/record/6802614#.Y9iTydLMJ6I
|
docs/imgs/totalsegmentator_15mm_validation.png
ADDED
docs/imgs/totalsegmentator_monailabel.png
ADDED
docs/imgs/totalsegmentator_train_accuracy.png
ADDED
models/model.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:80b429fb4b080df11c9ed0b0bdaa8a615ff083921bb213a512cf285afbc4e3fe
|
3 |
+
size 75225922
|
models/model_lowres.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c3ab55eb979785fdcb30690872c210bbeee73d79a170c32fdaa1eca117779f90
|
3 |
+
size 75225922
|