katielink commited on
Commit
560f266
1 Parent(s): 9272243

Add training pipeline for fine-tuning models, support MONAI Label active learning

Browse files
README.md CHANGED
@@ -6,7 +6,7 @@ library_name: monai
6
  license: unknown
7
  ---
8
  # Description
9
- A pre-trained model for inferencing volumetric (3D) kidney substructures segmentation from contrast-enhanced CT images (Arterial/Portal Venous Phase).
10
 
11
  A tutorial and release of model for kidney cortex, medulla and collecting system segmentation.
12
 
@@ -68,7 +68,11 @@ Add scripts component: To run the workflow with customized components, PYTHONPA
68
  export PYTHONPATH=$PYTHONPATH:"'<path to the bundle root dir>/scripts'"
69
 
70
  ```
 
71
 
 
 
 
72
 
73
  Execute inference:
74
 
 
6
  license: unknown
7
  ---
8
  # Description
9
+ A pre-trained model for training and inferencing volumetric (3D) kidney substructures segmentation from contrast-enhanced CT images (Arterial/Portal Venous Phase). Training pipeline is provided to support model fine-tuning with bundle and MONAI Label active learning.
10
 
11
  A tutorial and release of model for kidney cortex, medulla and collecting system segmentation.
12
 
 
68
  export PYTHONPATH=$PYTHONPATH:"'<path to the bundle root dir>/scripts'"
69
 
70
  ```
71
+ Execute Training:
72
 
73
+ ```
74
+ python -m monai.bundle run training --meta_file configs/metadata.json --config_file configs/train.json --logging_file configs/logging.conf
75
+ ```
76
 
77
  Execute inference:
78
 
configs/metadata.json CHANGED
@@ -1,12 +1,13 @@
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": "fixed the dimension in convolution according to MONAI 1.0 update",
6
  "0.1.1": "fixed the model state dict name",
7
  "0.1.0": "complete the model package"
8
  },
9
- "monai_version": "0.9.0",
10
  "pytorch_version": "1.10.0",
11
  "numpy_version": "1.21.2",
12
  "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.3",
4
  "changelog": {
5
+ "0.1.3": "Add training pipeline for fine-tuning models, support MONAI Label active learning",
6
  "0.1.2": "fixed the dimension in convolution according to MONAI 1.0 update",
7
  "0.1.1": "fixed the model state dict name",
8
  "0.1.0": "complete the model package"
9
  },
10
+ "monai_version": "1.0.0",
11
  "pytorch_version": "1.10.0",
12
  "numpy_version": "1.21.2",
13
  "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,321 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "imports": [
3
+ "$import glob",
4
+ "$import os",
5
+ "$import ignite"
6
+ ],
7
+ "bundle_root": "/models/renalStructures_UNEST_segmentation",
8
+ "ckpt_dir": "$@bundle_root + '/models'",
9
+ "output_dir": "$@bundle_root + '/eval'",
10
+ "dataset_dir": "$@bundle_root + './dataset'",
11
+ "images": "$list(sorted(glob.glob(@dataset_dir + '/imagesTr/*.nii.gz')))",
12
+ "labels": "$list(sorted(glob.glob(@dataset_dir + '/labelsTr/*.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.UNesT",
17
+ "in_channels": 1,
18
+ "out_channels": 4
19
+ },
20
+ "network": "$@network_def.to(@device)",
21
+ "loss": {
22
+ "_target_": "DiceCELoss",
23
+ "to_onehot_y": true,
24
+ "softmax": true,
25
+ "squared_pred": true,
26
+ "batch": true
27
+ },
28
+ "optimizer": {
29
+ "_target_": "torch.optim.Adam",
30
+ "params": "$@network.parameters()",
31
+ "lr": 0.0002
32
+ },
33
+ "train": {
34
+ "deterministic_transforms": [
35
+ {
36
+ "_target_": "LoadImaged",
37
+ "keys": [
38
+ "image",
39
+ "label"
40
+ ]
41
+ },
42
+ {
43
+ "_target_": "EnsureChannelFirstd",
44
+ "keys": [
45
+ "image",
46
+ "label"
47
+ ]
48
+ },
49
+ {
50
+ "_target_": "Orientationd",
51
+ "keys": [
52
+ "image",
53
+ "label"
54
+ ],
55
+ "axcodes": "RAS"
56
+ },
57
+ {
58
+ "_target_": "Spacingd",
59
+ "keys": [
60
+ "image",
61
+ "label"
62
+ ],
63
+ "pixdim": [
64
+ 1.0,
65
+ 1.0,
66
+ 1.0
67
+ ],
68
+ "mode": [
69
+ "bilinear",
70
+ "nearest"
71
+ ]
72
+ },
73
+ {
74
+ "_target_": "ScaleIntensityRanged",
75
+ "keys": "image",
76
+ "a_min": -175,
77
+ "a_max": 250,
78
+ "b_min": 0.0,
79
+ "b_max": 1.0,
80
+ "clip": true
81
+ },
82
+ {
83
+ "_target_": "EnsureTyped",
84
+ "keys": [
85
+ "image",
86
+ "label"
87
+ ]
88
+ }
89
+ ],
90
+ "random_transforms": [
91
+ {
92
+ "_target_": "RandCropByPosNegLabeld",
93
+ "keys": [
94
+ "image",
95
+ "label"
96
+ ],
97
+ "label_key": "label",
98
+ "spatial_size": [
99
+ 96,
100
+ 96,
101
+ 96
102
+ ],
103
+ "pos": 1,
104
+ "neg": 1,
105
+ "num_samples": 4,
106
+ "image_key": "image",
107
+ "image_threshold": 0
108
+ },
109
+ {
110
+ "_target_": "RandFlipd",
111
+ "keys": [
112
+ "image",
113
+ "label"
114
+ ],
115
+ "spatial_axis": [
116
+ 0
117
+ ],
118
+ "prob": 0.1
119
+ },
120
+ {
121
+ "_target_": "RandFlipd",
122
+ "keys": [
123
+ "image",
124
+ "label"
125
+ ],
126
+ "spatial_axis": [
127
+ 1
128
+ ],
129
+ "prob": 0.1
130
+ },
131
+ {
132
+ "_target_": "RandFlipd",
133
+ "keys": [
134
+ "image",
135
+ "label"
136
+ ],
137
+ "spatial_axis": [
138
+ 2
139
+ ],
140
+ "prob": 0.1
141
+ },
142
+ {
143
+ "_target_": "RandRotate90d",
144
+ "keys": [
145
+ "image",
146
+ "label"
147
+ ],
148
+ "max_k": 3,
149
+ "prob": 0.1
150
+ },
151
+ {
152
+ "_target_": "RandShiftIntensityd",
153
+ "keys": "image",
154
+ "offsets": 0.1,
155
+ "prob": 0.5
156
+ }
157
+ ],
158
+ "preprocessing": {
159
+ "_target_": "Compose",
160
+ "transforms": "$@train#deterministic_transforms + @train#random_transforms"
161
+ },
162
+ "dataset": {
163
+ "_target_": "CacheDataset",
164
+ "data": "$[{'image': i, 'label': l} for i, l in zip(@images[:-9], @labels[:-9])]",
165
+ "transform": "@train#preprocessing",
166
+ "cache_rate": 1.0,
167
+ "num_workers": 4
168
+ },
169
+ "dataloader": {
170
+ "_target_": "DataLoader",
171
+ "dataset": "@train#dataset",
172
+ "batch_size": 2,
173
+ "shuffle": true,
174
+ "num_workers": 4
175
+ },
176
+ "inferer": {
177
+ "_target_": "SimpleInferer"
178
+ },
179
+ "postprocessing": {
180
+ "_target_": "Compose",
181
+ "transforms": [
182
+ {
183
+ "_target_": "Activationsd",
184
+ "keys": "pred",
185
+ "softmax": true
186
+ },
187
+ {
188
+ "_target_": "AsDiscreted",
189
+ "keys": [
190
+ "pred",
191
+ "label"
192
+ ],
193
+ "argmax": [
194
+ true,
195
+ false
196
+ ],
197
+ "to_onehot": 4
198
+ }
199
+ ]
200
+ },
201
+ "handlers": [
202
+ {
203
+ "_target_": "ValidationHandler",
204
+ "validator": "@validate#evaluator",
205
+ "epoch_level": true,
206
+ "interval": "@val_interval"
207
+ },
208
+ {
209
+ "_target_": "StatsHandler",
210
+ "tag_name": "train_loss",
211
+ "output_transform": "$monai.handlers.from_engine(['loss'], first=True)"
212
+ },
213
+ {
214
+ "_target_": "TensorBoardStatsHandler",
215
+ "log_dir": "@output_dir",
216
+ "tag_name": "train_loss",
217
+ "output_transform": "$monai.handlers.from_engine(['loss'], first=True)"
218
+ }
219
+ ],
220
+ "key_metric": {
221
+ "train_accuracy": {
222
+ "_target_": "ignite.metrics.Accuracy",
223
+ "output_transform": "$monai.handlers.from_engine(['pred', 'label'])"
224
+ }
225
+ },
226
+ "trainer": {
227
+ "_target_": "SupervisedTrainer",
228
+ "max_epochs": 1000,
229
+ "device": "@device",
230
+ "train_data_loader": "@train#dataloader",
231
+ "network": "@network",
232
+ "loss_function": "@loss",
233
+ "optimizer": "@optimizer",
234
+ "inferer": "@train#inferer",
235
+ "postprocessing": "@train#postprocessing",
236
+ "key_train_metric": "@train#key_metric",
237
+ "train_handlers": "@train#handlers",
238
+ "amp": true
239
+ }
240
+ },
241
+ "validate": {
242
+ "preprocessing": {
243
+ "_target_": "Compose",
244
+ "transforms": "%train#deterministic_transforms"
245
+ },
246
+ "dataset": {
247
+ "_target_": "CacheDataset",
248
+ "data": "$[{'image': i, 'label': l} for i, l in zip(@images[-9:], @labels[-9:])]",
249
+ "transform": "@validate#preprocessing",
250
+ "cache_rate": 1.0
251
+ },
252
+ "dataloader": {
253
+ "_target_": "DataLoader",
254
+ "dataset": "@validate#dataset",
255
+ "batch_size": 1,
256
+ "shuffle": false,
257
+ "num_workers": 4
258
+ },
259
+ "inferer": {
260
+ "_target_": "SlidingWindowInferer",
261
+ "roi_size": [
262
+ 96,
263
+ 96,
264
+ 96
265
+ ],
266
+ "sw_batch_size": 4,
267
+ "overlap": 0.5
268
+ },
269
+ "postprocessing": "%train#postprocessing",
270
+ "handlers": [
271
+ {
272
+ "_target_": "StatsHandler",
273
+ "iteration_log": false
274
+ },
275
+ {
276
+ "_target_": "TensorBoardStatsHandler",
277
+ "log_dir": "@output_dir",
278
+ "iteration_log": false
279
+ },
280
+ {
281
+ "_target_": "CheckpointSaver",
282
+ "save_dir": "@ckpt_dir",
283
+ "save_dict": {
284
+ "model": "@network"
285
+ },
286
+ "save_key_metric": true,
287
+ "key_metric_filename": "model.pt"
288
+ }
289
+ ],
290
+ "key_metric": {
291
+ "val_mean_dice": {
292
+ "_target_": "MeanDice",
293
+ "include_background": false,
294
+ "output_transform": "$monai.handlers.from_engine(['pred', 'label'])"
295
+ }
296
+ },
297
+ "additional_metrics": {
298
+ "val_accuracy": {
299
+ "_target_": "ignite.metrics.Accuracy",
300
+ "output_transform": "$monai.handlers.from_engine(['pred', 'label'])"
301
+ }
302
+ },
303
+ "evaluator": {
304
+ "_target_": "SupervisedEvaluator",
305
+ "device": "@device",
306
+ "val_data_loader": "@validate#dataloader",
307
+ "network": "@network",
308
+ "inferer": "@validate#inferer",
309
+ "postprocessing": "@validate#postprocessing",
310
+ "key_val_metric": "@validate#key_metric",
311
+ "additional_metrics": "@validate#additional_metrics",
312
+ "val_handlers": "@validate#handlers",
313
+ "amp": true
314
+ }
315
+ },
316
+ "training": [
317
+ "$monai.utils.set_determinism(seed=123)",
318
+ "$setattr(torch.backends.cudnn, 'benchmark', True)",
319
+ "$@train#trainer.run()"
320
+ ]
321
+ }
docs/README.md CHANGED
@@ -1,5 +1,5 @@
1
  # Description
2
- A pre-trained model for inferencing volumetric (3D) kidney substructures segmentation from contrast-enhanced CT images (Arterial/Portal Venous Phase).
3
 
4
  A tutorial and release of model for kidney cortex, medulla and collecting system segmentation.
5
 
@@ -61,7 +61,11 @@ Add scripts component: To run the workflow with customized components, PYTHONPA
61
  export PYTHONPATH=$PYTHONPATH:"'<path to the bundle root dir>/scripts'"
62
 
63
  ```
 
64
 
 
 
 
65
 
66
  Execute inference:
67
 
 
1
  # Description
2
+ A pre-trained model for training and inferencing volumetric (3D) kidney substructures segmentation from contrast-enhanced CT images (Arterial/Portal Venous Phase). Training pipeline is provided to support model fine-tuning with bundle and MONAI Label active learning.
3
 
4
  A tutorial and release of model for kidney cortex, medulla and collecting system segmentation.
5
 
 
61
  export PYTHONPATH=$PYTHONPATH:"'<path to the bundle root dir>/scripts'"
62
 
63
  ```
64
+ Execute Training:
65
 
66
+ ```
67
+ python -m monai.bundle run training --meta_file configs/metadata.json --config_file configs/train.json --logging_file configs/logging.conf
68
+ ```
69
 
70
  Execute inference:
71