Skip to content

Commit 38a4e86

Browse files
committed
Update README.md
Signed-off-by: myron <[email protected]>
1 parent 6932ca6 commit 38a4e86

File tree

1 file changed

+59
-15
lines changed

1 file changed

+59
-15
lines changed

auto3dseg/tasks/kits23/README.md

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ Andriy Myronenko, Dong Yang, Yufan He and Daguang Xu: "Automated 3D Segmentation
1111

1212
## Task overview
1313

14-
The task is to segment kidneys, tumors and cysts from 3D CTs. The dataset contains 489 cases with resolutions rangingn between 0.39x0.39x0.5 and 1x1x5 mm.
14+
The task is to segment kidneys, tumors and cysts from 3D CTs. The dataset contains 489 cases with resolutions ranging between 0.39x0.39x0.5 and 1x1x5 mm.
1515
Please download the KiTS23 [dataset](https://kits-challenge.org/kits23/#) and place it in the "/data/kits23" folder to follow this tutorial.
1616

1717
## Auto3DSeg
1818

19-
With Auto3DSeg most segmentation parameters are automatically determined. In this tutorial, we start from a basic automated example, then show how different options can be adjusted if necessary. We use only the **SegResNet** algo here for simplicity, which is a training recepie based on the [segresnet] (https://docs.monai.io/en/latest/networks.html#segresnetds).
19+
With Auto3DSeg most segmentation parameters are automatically determined. In this tutorial, we start from a basic automated example, then show how different options can be adjusted if necessary. We use only the **SegResNet** algo here for simplicity, which is a training recipe based on the [segresnet](https://docs.monai.io/en/latest/networks.html#segresnetds).
2020

2121

2222
### Running based on the input config (one-liner)
@@ -28,14 +28,14 @@ python -m monai.apps.auto3dseg AutoRunner run --input=./input.yaml --algos=segre
2828
```
2929

3030
This one line of code will run the full training workflow, including data analysis, multi-fold training, ensembling. The system will adjust parameters based on the data and your available GPU (or multi-GPU) hardware configuration.
31-
Here we explicitely specified to use only segresnet algo, for other possible parameters of the AutoRunner please see the [monai docs](https://github.com/Project-MONAI/MONAI/blob/main/monai/apps/auto3dseg/auto_runner.py).
31+
Here we explicitly specified to use only segresnet algo, for other possible parameters of the AutoRunner please see the [monai docs](https://github.com/Project-MONAI/MONAI/blob/main/monai/apps/auto3dseg/auto_runner.py).
3232

33-
The [input.yaml](./input.yaml) describes the dataset (KiTS23) task, and must include at least 3 mandatory fields: mondality (CT), dataset location (here it's /data/kits23) and the dataset manifest json file [kits23_folds.json](./kits23_folds.json).
34-
Other parameters can optionally be also added to the input.yaml config. For KiTS23 dataset specifically, we include the "class_names" key that show the label grouping for the 3 output classes that KiTS23 challenge asks (which is something specific for the KiTS task)
33+
The [input.yaml](./input.yaml) describes the dataset (KiTS23) task, and must include at least 3 mandatory fields: modality (CT), dataset location (here it's /data/kits23) and the dataset manifest json file [kits23_folds.json](./kits23_folds.json).
34+
Other parameters can be also added to the input.yaml config. For KiTS23 dataset specifically, we include the "class_names" key to indicate label grouping for the 3 output classes that KiTS23 challenge requires (which is something specific for the KiTS task)
3535

3636
### Running from the code
3737

38-
If you prefer to run the same thing from code (which will allow more customizations), once can create a python file "example.py" and simply run it as
38+
If you prefer running from the code (which will allow more customizations), you can create a python file "example.py" and simply run it as
3939
```bash
4040
python example.py
4141
```
@@ -51,6 +51,7 @@ def main():
5151
if __name__ == '__main__':
5252
main()
5353
```
54+
this is exactly equivalent to the one-liner command line call.
5455

5556
### Running from the code (more options)
5657

@@ -85,11 +86,11 @@ if __name__ == '__main__':
8586
main()
8687
```
8788

88-
The dictonary form of the input config is equivalent to the input.yaml. Notice, here we also added "runner.set_num_fold(1)" to train only 1 fold. By default the system determines number of fold based on the datalist.json file, which is 5 folds in this case, and train 5 models using cross-validation. However one can train only 1 model (fold0), which is much faster if only 1 output model is sufficient.
89+
The dictionary form of the input config is equivalent to the input.yaml. Notice, here we also added "runner.set_num_fold(1)" to train only 1 fold. By default the system determines the number of folds based on the datalist.json file, which is 5 folds in this case, and trains 5 models using cross-validation. However, one can opt to train only 1 model (fold 0), which is much faster if only 1 output model is sufficient.
8990

9091
### Input.yaml options
9192

92-
Regardless if you prefer to use the yaml file form or an exmplicit dictionary config form, you can add many options manually to override the automatic defaults. For example consider the following input.yaml file.
93+
Regardless if you prefer to use the yaml file or a dictionary config form, you can add many options to override the automatic defaults. For example consider the following input.yaml file.
9394
```yaml
9495
# input2.yaml file content example with more options
9596

@@ -107,19 +108,19 @@ sigmoid: true
107108
# additional options (OPTIONAL)
108109
auto_scale_allowed: false # disable auto scaling of some parameters to your GPU
109110
num_epochs: 600 # manually set number of training epochs to 600 (otherwise it's determined automatically)
110-
resample: true # explicitelly set to resample images to the resample_resolution (for KiTS it's already auto-detected to resample)
111+
resample: true # explicitly set to resample images to the resample_resolution (for KiTS it's already auto-detected to resample)
111112
resample_resolution: [0.78125, 0.78125, 0.78125] #set the resample resolution manually (the automated default here is 0.78x0.78x1)
112113
roi_size: [336, 336, 336] # set the cropping ROI size (for this large ROI, you may need a GPU with >40GB capacity), try smaller for your GPU
113114
loss: {_target_: DiceLoss} # change loss to be pure Dice (default is DiceCELoss)
114115
batch_size: 1 # batch size is automatically determined according to your GPU, but you can manually set it
115116
augment_mode: ct_ax_1 # change the default augmentation transform sequence to an alternative (with only inplane/axial spatial rotations and scaling)
116117

117118
```
118-
Here we added more optional options to manually fine-tune the performance. The full list of the available options to manually set can be observed [here](https://github.com/Project-MONAI/research-contributions/blob/main/auto3dseg/algorithm_templates/segresnet/configs/hyper_parameters.yaml)
119+
Here we added more optional options to manually fine-tune the performance. The full list of the available "self-explanatory" options can be found [here](https://github.com/Project-MONAI/research-contributions/blob/main/auto3dseg/algorithm_templates/segresnet/configs/hyper_parameters.yaml).
119120
120121
### Input.yaml options and AutoRunner options combined
121122
122-
In the previous sections, we showed how to manually provide various input config options related to **training**. In the same file, once can also add AutoRunner related options, consider the following input3.yaml config
123+
In the previous sections, we showed how to manually provide various input config options related to **training**. In the same file, one can also add AutoRunner related options, consider the following input3.yaml config
123124
```yaml
124125
# input2.yaml file content example with more options
125126

@@ -158,14 +159,57 @@ python -m monai.apps.auto3dseg AutoRunner run --input=./input3.yaml --work_dir=t
158159
```
159160
here the "work_dir", "dataroot", "num_epochs" options will override any defaults or any input.yaml provided options.
160161

162+
### KiTS 2023 specific options
163+
164+
All the configurations here include some KiTS 2023 specific options below
165+
```yaml
166+
class_names:
167+
- { name: kidney_and_mass, index: [1,2,3] }
168+
- { name: mass, index: [2,3] }
169+
- { name: tumor, index: [2] }
170+
sigmoid: true
171+
172+
```
173+
In KiTS 2023 challenge, the task is to segment 3 specific subregions: a) the first one must include all labels (kidneys, tumors, cysts) b) the second one is a union of tumors and cysts b) the third one is a tumor only region.
174+
Thus the "class_names" options indicates which label indices to merge together to create these 3 subregions. The "name" keys are used in Tensorboard for convenience (you can use your own names).
175+
Since, the 3 sub-regions are overlapping the segmentation task is a multi-label task, where each voxel can potentially be assigned to several regions. A common formulation of such task is to use the final network activation a "sigmoid", instead of the default "softmax" for mutually exclusive label classes. The config options "sigmoid: true" explicitly indicates that we are going to use the final sigmoid activation (for the multi-label segmentation). Strictly speaking it's not necessary to add this option here, the system will automatically figure it out after inspecting "class_names" having the overlapping indices.
176+
177+
Experimentally, you can remove these configs (class_names and sigmoid) completely to try a traditional segmentation (multi-class), to segment 3 mutually exclusive regions: a) kidneys without tumors or cysts b) tumors c) cysts. Generally, this is the default workflow for multi-organ segmentation (with non-overlaping classes). This sub-region grouping is just something specific for the KiTS 2023 challenge.
178+
179+
### Auto3DSeg code location
180+
181+
Advanced users may want to further build up upon Auto3DSeg code. Currently the codebase is split in 2 repos: The high level AutoRunner related code is a part of [MONAI core](https://github.com/Project-MONAI/MONAI) and the algo specific code (including segresnet algo code) is part of the [MONAI research contributions](https://github.com/Project-MONAI/research-contributions/tree/main/auto3dseg/algorithm_templates/). Generally, if you would like to use your own network or different augmentation transforms, you would want to modify the segresnet algo code. Currently, the easiest way to do it is to
182+
- clone the github repo of MONAI research contributions https://github.com/Project-MONAI/research-contributions or just download the [algorithm_templates folder](https://github.com/Project-MONAI/research-contributions/tree/main/auto3dseg/algorithm_templates)
183+
- modify the algo related code, e.g. segmenter.py under segresnet algo
184+
- point AutoRunner to use your own algorithm_templates folder by setting the "templates_path_or_url" config option
185+
186+
```python
187+
# example.py file content with custom algo templates code
188+
189+
from monai.apps.auto3dseg import AutoRunner
190+
191+
def main():
192+
runner = AutoRunner(input='./input.yaml', algos = 'segresnet', templates_path_or_url='/your/location/algorithm_templates')
193+
runner.run()
194+
195+
if __name__ == '__main__':
196+
main()
197+
```
198+
or
199+
```bash
200+
python -m monai.apps.auto3dseg AutoRunner run --input=./input.yaml --algos=segresnet --templates_path_or_url=/your/location/algorithm_templates
201+
```
202+
203+
204+
161205
## Validation performance: NVIDIA DGX-1 (8x V100 32G)
162206

163-
Training on on 8 GPU V100 32GB DGX machine, one can expect to get an average Dice of 0.87-0.88 (for fold 0). The higher end accuracy is obrained if you set the ROI size to larger (e.g. roi_size: [336, 336, 336]), but
164-
this requires a large memory GPU device (such as A10 or A100). Alternatively you can experiment with training longer, e.g. by setting num_epochs=1200 (which will take longer).
207+
Training this KiTS 2023 example on on 8 GPU V100 32GB DGX machine, one can expect to get an average Dice of 0.87-0.88 (for fold 0). The higher end of the accuracy range is obtained if you set the ROI size to larger (e.g. roi_size: [336, 336, 336]), but
208+
this requires a large memory GPU device (such as A10 or A100). Alternatively you can experiment with training longer, e.g. by setting num_epochs=1200.
165209

166-
## Difference with 1st place KiTS23 solution
210+
## Differences with 1st place KiTS23 solution
167211

168-
The example here is based on the 1st place KiTS23 solution [1], with the main differences beeing in [1] the training was done in 2 stages: first the apriximate Kidney region was detected (by training a model to segment the foreground), second an enseble of models were trained to segment the 3 KiTS subregions using the "Kidney subregion". In this tutorial, we train to segment KiTS subregions directly on the full image for simplicity (which gives a slightly lower average dice, ~1\%). Another difference is that in [1] and ensemble of several models were trained which included both segresnet and dints models, where as in this tutorial we focus only on segresnet.
212+
The example here is based on the 1st place KiTS23 solution [1], with the main differences being in [1] the training was done in 2 stages: first the approximate Kidney region was detected (by training a model to segment the foreground), second an ensemble of models were trained to segment the 3 KiTS subregions using the "Kidney subregion" cropped CTs. In this tutorial, we train to segment KiTS subregions directly on the full CT for simplicity (which gives a slightly lower average dice, ~1\%). Another difference is that in [1], the ensemble of several models were trained which included both segresnet and dints models, whereas in this tutorial we focus only on segresnet.
169213

170214
## Data
171215

0 commit comments

Comments
 (0)