monai
medical
katielink commited on
Commit
194860f
1 Parent(s): 362a1dc

Add training support for whole brain segmentation, users can use active learning in the MONAI Label

Browse files
README.md CHANGED
@@ -7,7 +7,8 @@ license: unknown
7
  ---
8
  # Description
9
  Detailed whole brain segmentation is an essential quantitative technique in medical image analysis, which provides a non-invasive way of measuring brain regions from a clinical acquired structural magnetic resonance imaging (MRI).
10
- We provide the pre-trained model for inferencing whole brain segmentation with 133 structures.
 
11
 
12
  A tutorial and release of model for whole brain segmentation using the 3D transformer-based segmentation model UNEST.
13
 
@@ -27,7 +28,7 @@ Fig.1 - The demonstration of T1w MRI images registered in MNI space and the whol
27
 
28
 
29
  # Model Overview
30
- A pre-trained larger UNEST base model [1] for volumetric (3D) whole brain segmentation with T1w MR images.
31
  To leverage information across embedded sequences, ”shifted window” transformers
32
  are proposed for dense predictions and modeling multi-scale features. However, these
33
  attempts that aim to complicate the self-attention range often yield high computation
@@ -97,6 +98,11 @@ Add scripts component: To run the workflow with customized components, PYTHONPA
97
  export PYTHONPATH=$PYTHONPATH: '<path to the bundle root dir>/scripts'
98
  ```
99
 
 
 
 
 
 
100
 
101
  Execute inference:
102
 
@@ -111,6 +117,12 @@ python -m monai.bundle run evaluating --meta_file configs/metadata.json --config
111
  Fig.3 - The output prediction comparison with variant and ground truth
112
  </p>
113
 
 
 
 
 
 
 
114
 
115
  ## Complete ROI of the whole brain segmentation
116
  133 brain structures are segmented.
@@ -154,7 +166,7 @@ Fig.3 - The output prediction comparison with variant and ground truth
154
 
155
 
156
  ## Bundle Integration in MONAI Lable
157
- The inference pipleine can be easily used by the MONAI Label server and 3D Slicer for fast labeling T1w MRI images in MNI space.
158
 
159
  ![](./3DSlicer_use.png) <br>
160
 
 
7
  ---
8
  # Description
9
  Detailed whole brain segmentation is an essential quantitative technique in medical image analysis, which provides a non-invasive way of measuring brain regions from a clinical acquired structural magnetic resonance imaging (MRI).
10
+ We provide the pre-trained model for training and inferencing whole brain segmentation with 133 structures.
11
+ Training pipeline is provided to support active learning in MONAI Label and training with bundle.
12
 
13
  A tutorial and release of model for whole brain segmentation using the 3D transformer-based segmentation model UNEST.
14
 
 
28
 
29
 
30
  # Model Overview
31
+ A pre-trained UNEST base model [1] for volumetric (3D) whole brain segmentation with T1w MR images.
32
  To leverage information across embedded sequences, ”shifted window” transformers
33
  are proposed for dense predictions and modeling multi-scale features. However, these
34
  attempts that aim to complicate the self-attention range often yield high computation
 
98
  export PYTHONPATH=$PYTHONPATH: '<path to the bundle root dir>/scripts'
99
  ```
100
 
101
+ Execute Training:
102
+
103
+ ```
104
+ python -m monai.bundle run training --meta_file configs/metadata.json --config_file configs/train.json --logging_file configs/logging.conf
105
+ ```
106
 
107
  Execute inference:
108
 
 
117
  Fig.3 - The output prediction comparison with variant and ground truth
118
  </p>
119
 
120
+ ## Training/Validation Benchmarking
121
+ A graph showing the training accuracy for fine-tuning 600 epochs.
122
+
123
+ ![](./training.png) <br>
124
+
125
+ With 10 fine-tuned labels, the training process converges fast.
126
 
127
  ## Complete ROI of the whole brain segmentation
128
  133 brain structures are segmented.
 
166
 
167
 
168
  ## Bundle Integration in MONAI Lable
169
+ The inference and training pipleine can be easily used by the MONAI Label server and 3D Slicer for fast labeling T1w MRI images in MNI space.
170
 
171
  ![](./3DSlicer_use.png) <br>
172
 
configs/metadata.json CHANGED
@@ -1,11 +1,12 @@
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.1",
4
  "changelog": {
 
5
  "0.1.1": "Fix dimension according to MONAI 1.0 and fix readme file",
6
  "0.1.0": "complete the model package"
7
  },
8
- "monai_version": "0.9.1",
9
  "pytorch_version": "1.10.0",
10
  "numpy_version": "1.21.2",
11
  "optional_packages_version": {
 
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.2",
4
  "changelog": {
5
+ "0.1.2": "Add training support for whole brain segmentation, users can use active learning in the MONAI Label",
6
  "0.1.1": "Fix dimension according to MONAI 1.0 and fix readme file",
7
  "0.1.0": "complete the model package"
8
  },
9
+ "monai_version": "1.0.0",
10
  "pytorch_version": "1.10.0",
11
  "numpy_version": "1.21.2",
12
  "optional_packages_version": {
configs/multi_gpu_train.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "$@train#trainer.run()",
34
+ "$dist.destroy_process_group()"
35
+ ]
36
+ }
configs/train.json ADDED
@@ -0,0 +1,299 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "imports": [
3
+ "$import glob",
4
+ "$import os",
5
+ "$import ignite"
6
+ ],
7
+ "bundle_root": ".",
8
+ "ckpt_dir": "$@bundle_root + '/models'",
9
+ "output_dir": "$@bundle_root + '/eval'",
10
+ "dataset_dir": "$@bundle_root + '/dataset/brain'",
11
+ "images": "$list(sorted(glob.glob(@dataset_dir + '/images/*.nii.gz')))",
12
+ "labels": "$list(sorted(glob.glob(@dataset_dir + '/labels/*.nii.gz')))",
13
+ "val_interval": 5,
14
+ "device": "$torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')",
15
+ "network_def": {
16
+ "_target_": "scripts.networks.unest_base_patch_4.UNesT",
17
+ "in_channels": 1,
18
+ "out_channels": 133,
19
+ "patch_size": 4,
20
+ "depths": [
21
+ 2,
22
+ 2,
23
+ 8
24
+ ],
25
+ "embed_dim": [
26
+ 128,
27
+ 256,
28
+ 512
29
+ ],
30
+ "num_heads": [
31
+ 4,
32
+ 8,
33
+ 16
34
+ ]
35
+ },
36
+ "network": "$@network_def.to(@device)",
37
+ "loss": {
38
+ "_target_": "DiceCELoss",
39
+ "to_onehot_y": true,
40
+ "softmax": true,
41
+ "squared_pred": true,
42
+ "batch": true
43
+ },
44
+ "optimizer": {
45
+ "_target_": "torch.optim.Adam",
46
+ "params": "$@network.parameters()",
47
+ "lr": 0.0001
48
+ },
49
+ "train": {
50
+ "deterministic_transforms": [
51
+ {
52
+ "_target_": "LoadImaged",
53
+ "keys": [
54
+ "image",
55
+ "label"
56
+ ]
57
+ },
58
+ {
59
+ "_target_": "EnsureChannelFirstd",
60
+ "keys": [
61
+ "image",
62
+ "label"
63
+ ]
64
+ },
65
+ {
66
+ "_target_": "EnsureTyped",
67
+ "keys": [
68
+ "image",
69
+ "label"
70
+ ]
71
+ }
72
+ ],
73
+ "random_transforms": [
74
+ {
75
+ "_target_": "RandSpatialCropd",
76
+ "keys": [
77
+ "image",
78
+ "label"
79
+ ],
80
+ "roi_size": [
81
+ 96,
82
+ 96,
83
+ 96
84
+ ],
85
+ "random_size": false
86
+ },
87
+ {
88
+ "_target_": "RandFlipd",
89
+ "keys": [
90
+ "image",
91
+ "label"
92
+ ],
93
+ "spatial_axis": [
94
+ 0
95
+ ],
96
+ "prob": 0.1
97
+ },
98
+ {
99
+ "_target_": "RandFlipd",
100
+ "keys": [
101
+ "image",
102
+ "label"
103
+ ],
104
+ "spatial_axis": [
105
+ 1
106
+ ],
107
+ "prob": 0.1
108
+ },
109
+ {
110
+ "_target_": "RandFlipd",
111
+ "keys": [
112
+ "image",
113
+ "label"
114
+ ],
115
+ "spatial_axis": [
116
+ 2
117
+ ],
118
+ "prob": 0.1
119
+ },
120
+ {
121
+ "_target_": "RandRotate90d",
122
+ "keys": [
123
+ "image",
124
+ "label"
125
+ ],
126
+ "max_k": 3,
127
+ "prob": 0.1
128
+ },
129
+ {
130
+ "_target_": "NormalizeIntensityd",
131
+ "keys": "image",
132
+ "nonzero": true,
133
+ "channel_wise": true
134
+ }
135
+ ],
136
+ "preprocessing": {
137
+ "_target_": "Compose",
138
+ "transforms": "$@train#deterministic_transforms + @train#random_transforms"
139
+ },
140
+ "dataset": {
141
+ "_target_": "CacheDataset",
142
+ "data": "$[{'image': i, 'label': l} for i, l in zip(@images[:-2], @labels[:-2])]",
143
+ "transform": "@train#preprocessing",
144
+ "cache_rate": 1.0,
145
+ "num_workers": 2
146
+ },
147
+ "dataloader": {
148
+ "_target_": "DataLoader",
149
+ "dataset": "@train#dataset",
150
+ "batch_size": 1,
151
+ "shuffle": true,
152
+ "num_workers": 1
153
+ },
154
+ "inferer": {
155
+ "_target_": "SimpleInferer"
156
+ },
157
+ "postprocessing": {
158
+ "_target_": "Compose",
159
+ "transforms": [
160
+ {
161
+ "_target_": "Activationsd",
162
+ "keys": "pred",
163
+ "softmax": true
164
+ },
165
+ {
166
+ "_target_": "AsDiscreted",
167
+ "keys": [
168
+ "pred",
169
+ "label"
170
+ ],
171
+ "argmax": [
172
+ true,
173
+ false
174
+ ],
175
+ "to_onehot": 133
176
+ }
177
+ ]
178
+ },
179
+ "handlers": [
180
+ {
181
+ "_target_": "ValidationHandler",
182
+ "validator": "@validate#evaluator",
183
+ "epoch_level": true,
184
+ "interval": "@val_interval"
185
+ },
186
+ {
187
+ "_target_": "StatsHandler",
188
+ "tag_name": "train_loss",
189
+ "output_transform": "$monai.handlers.from_engine(['loss'], first=True)"
190
+ },
191
+ {
192
+ "_target_": "TensorBoardStatsHandler",
193
+ "log_dir": "@output_dir",
194
+ "tag_name": "train_loss",
195
+ "output_transform": "$monai.handlers.from_engine(['loss'], first=True)"
196
+ }
197
+ ],
198
+ "key_metric": {
199
+ "train_accuracy": {
200
+ "_target_": "ignite.metrics.Accuracy",
201
+ "output_transform": "$monai.handlers.from_engine(['pred', 'label'])"
202
+ }
203
+ },
204
+ "trainer": {
205
+ "_target_": "SupervisedTrainer",
206
+ "max_epochs": 2000,
207
+ "device": "@device",
208
+ "train_data_loader": "@train#dataloader",
209
+ "network": "@network",
210
+ "loss_function": "@loss",
211
+ "optimizer": "@optimizer",
212
+ "inferer": "@train#inferer",
213
+ "postprocessing": "@train#postprocessing",
214
+ "key_train_metric": "@train#key_metric",
215
+ "train_handlers": "@train#handlers",
216
+ "amp": true
217
+ }
218
+ },
219
+ "validate": {
220
+ "preprocessing": {
221
+ "_target_": "Compose",
222
+ "transforms": "%train#deterministic_transforms"
223
+ },
224
+ "dataset": {
225
+ "_target_": "CacheDataset",
226
+ "data": "$[{'image': i, 'label': l} for i, l in zip(@images[-2:], @labels[-2:])]",
227
+ "transform": "@validate#preprocessing",
228
+ "cache_rate": 1.0
229
+ },
230
+ "dataloader": {
231
+ "_target_": "DataLoader",
232
+ "dataset": "@validate#dataset",
233
+ "batch_size": 2,
234
+ "shuffle": false,
235
+ "num_workers": 1
236
+ },
237
+ "inferer": {
238
+ "_target_": "SlidingWindowInferer",
239
+ "roi_size": [
240
+ 96,
241
+ 96,
242
+ 96
243
+ ],
244
+ "sw_batch_size": 4,
245
+ "overlap": 0.5
246
+ },
247
+ "postprocessing": "%train#postprocessing",
248
+ "handlers": [
249
+ {
250
+ "_target_": "StatsHandler",
251
+ "iteration_log": false
252
+ },
253
+ {
254
+ "_target_": "TensorBoardStatsHandler",
255
+ "log_dir": "@output_dir",
256
+ "iteration_log": false
257
+ },
258
+ {
259
+ "_target_": "CheckpointSaver",
260
+ "save_dir": "@ckpt_dir",
261
+ "save_dict": {
262
+ "model": "@network"
263
+ },
264
+ "save_key_metric": true,
265
+ "key_metric_filename": "model.pt"
266
+ }
267
+ ],
268
+ "key_metric": {
269
+ "val_mean_dice": {
270
+ "_target_": "MeanDice",
271
+ "include_background": false,
272
+ "output_transform": "$monai.handlers.from_engine(['pred', 'label'])"
273
+ }
274
+ },
275
+ "additional_metrics": {
276
+ "val_accuracy": {
277
+ "_target_": "ignite.metrics.Accuracy",
278
+ "output_transform": "$monai.handlers.from_engine(['pred', 'label'])"
279
+ }
280
+ },
281
+ "evaluator": {
282
+ "_target_": "SupervisedEvaluator",
283
+ "device": "@device",
284
+ "val_data_loader": "@validate#dataloader",
285
+ "network": "@network",
286
+ "inferer": "@validate#inferer",
287
+ "postprocessing": "@validate#postprocessing",
288
+ "key_val_metric": "@validate#key_metric",
289
+ "additional_metrics": "@validate#additional_metrics",
290
+ "val_handlers": "@validate#handlers",
291
+ "amp": true
292
+ }
293
+ },
294
+ "training": [
295
+ "$monai.utils.set_determinism(seed=123)",
296
+ "$setattr(torch.backends.cudnn, 'benchmark', True)",
297
+ "$@train#trainer.run()"
298
+ ]
299
+ }
docs/README.md CHANGED
@@ -1,6 +1,7 @@
1
  # Description
2
  Detailed whole brain segmentation is an essential quantitative technique in medical image analysis, which provides a non-invasive way of measuring brain regions from a clinical acquired structural magnetic resonance imaging (MRI).
3
- We provide the pre-trained model for inferencing whole brain segmentation with 133 structures.
 
4
 
5
  A tutorial and release of model for whole brain segmentation using the 3D transformer-based segmentation model UNEST.
6
 
@@ -20,7 +21,7 @@ Fig.1 - The demonstration of T1w MRI images registered in MNI space and the whol
20
 
21
 
22
  # Model Overview
23
- A pre-trained larger UNEST base model [1] for volumetric (3D) whole brain segmentation with T1w MR images.
24
  To leverage information across embedded sequences, ”shifted window” transformers
25
  are proposed for dense predictions and modeling multi-scale features. However, these
26
  attempts that aim to complicate the self-attention range often yield high computation
@@ -90,6 +91,11 @@ Add scripts component: To run the workflow with customized components, PYTHONPA
90
  export PYTHONPATH=$PYTHONPATH: '<path to the bundle root dir>/scripts'
91
  ```
92
 
 
 
 
 
 
93
 
94
  Execute inference:
95
 
@@ -104,6 +110,12 @@ python -m monai.bundle run evaluating --meta_file configs/metadata.json --config
104
  Fig.3 - The output prediction comparison with variant and ground truth
105
  </p>
106
 
 
 
 
 
 
 
107
 
108
  ## Complete ROI of the whole brain segmentation
109
  133 brain structures are segmented.
@@ -147,7 +159,7 @@ Fig.3 - The output prediction comparison with variant and ground truth
147
 
148
 
149
  ## Bundle Integration in MONAI Lable
150
- The inference pipleine can be easily used by the MONAI Label server and 3D Slicer for fast labeling T1w MRI images in MNI space.
151
 
152
  ![](./3DSlicer_use.png) <br>
153
 
 
1
  # Description
2
  Detailed whole brain segmentation is an essential quantitative technique in medical image analysis, which provides a non-invasive way of measuring brain regions from a clinical acquired structural magnetic resonance imaging (MRI).
3
+ We provide the pre-trained model for training and inferencing whole brain segmentation with 133 structures.
4
+ Training pipeline is provided to support active learning in MONAI Label and training with bundle.
5
 
6
  A tutorial and release of model for whole brain segmentation using the 3D transformer-based segmentation model UNEST.
7
 
 
21
 
22
 
23
  # Model Overview
24
+ A pre-trained UNEST base model [1] for volumetric (3D) whole brain segmentation with T1w MR images.
25
  To leverage information across embedded sequences, ”shifted window” transformers
26
  are proposed for dense predictions and modeling multi-scale features. However, these
27
  attempts that aim to complicate the self-attention range often yield high computation
 
91
  export PYTHONPATH=$PYTHONPATH: '<path to the bundle root dir>/scripts'
92
  ```
93
 
94
+ Execute Training:
95
+
96
+ ```
97
+ python -m monai.bundle run training --meta_file configs/metadata.json --config_file configs/train.json --logging_file configs/logging.conf
98
+ ```
99
 
100
  Execute inference:
101
 
 
110
  Fig.3 - The output prediction comparison with variant and ground truth
111
  </p>
112
 
113
+ ## Training/Validation Benchmarking
114
+ A graph showing the training accuracy for fine-tuning 600 epochs.
115
+
116
+ ![](./training.png) <br>
117
+
118
+ With 10 fine-tuned labels, the training process converges fast.
119
 
120
  ## Complete ROI of the whole brain segmentation
121
  133 brain structures are segmented.
 
159
 
160
 
161
  ## Bundle Integration in MONAI Lable
162
+ The inference and training pipleine can be easily used by the MONAI Label server and 3D Slicer for fast labeling T1w MRI images in MNI space.
163
 
164
  ![](./3DSlicer_use.png) <br>
165
 
docs/training.png ADDED