monai
medical
katielink commited on
Commit
80ed565
1 Parent(s): e5d4212

adapt to BundleWorkflow interface and val metric

Browse files
README.md CHANGED
@@ -117,13 +117,13 @@ For more details usage instructions, visit the [MONAI Bundle Configuration Page]
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).
@@ -131,24 +131,24 @@ Please note that the distributed training-related options depend on the actual r
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
 
 
117
  #### Execute training
118
 
119
  ```
120
+ python -m monai.bundle run --config_file configs/train.json
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 --config_file "['configs/train.json','configs/multi_gpu_train.json']"
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).
 
131
  #### Override the `train` config to execute evaluation with the trained model
132
 
133
  ```
134
+ python -m monai.bundle run --config_file "['configs/train.json','configs/evaluate.json']"
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 --config_file "['configs/train.json','configs/evaluate.json','configs/multi_gpu_evaluate.json']"
141
  ```
142
 
143
  #### Execute inference
144
 
145
  ```
146
+ python -m monai.bundle run --config_file configs/inference.json
147
  ```
148
  #### Execute inference with Data Samples
149
 
150
  ```
151
+ python -m monai.bundle run --config_file configs/inference.json --datalist "['sampledata/imagesTr/s0037.nii.gz','sampledata/imagesTr/s0038.nii.gz']"
152
  ```
153
 
154
 
configs/evaluate.json CHANGED
@@ -8,31 +8,31 @@
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",
@@ -71,8 +71,10 @@
71
  "summary_ops": "*"
72
  }
73
  ],
74
- "evaluating": [
75
- "$setattr(torch.backends.cudnn, 'benchmark', True)",
 
 
76
  "$@validate#evaluator.run()"
77
  ]
78
  }
 
8
  "softmax": true
9
  },
10
  {
11
+ "_target_": "Invertd",
12
  "keys": [
13
  "pred",
14
  "label"
15
  ],
16
+ "transform": "@validate#preprocessing",
17
+ "orig_keys": "image",
18
+ "meta_key_postfix": "meta_dict",
19
+ "nearest_interp": [
20
  true,
21
+ true
22
  ],
23
+ "to_tensor": true
24
  },
25
  {
26
+ "_target_": "AsDiscreted",
27
  "keys": [
28
  "pred",
29
  "label"
30
  ],
31
+ "argmax": [
 
 
 
32
  true,
33
+ false
34
  ],
35
+ "to_onehot": 105
36
  },
37
  {
38
  "_target_": "SaveImaged",
 
71
  "summary_ops": "*"
72
  }
73
  ],
74
+ "initialize": [
75
+ "$setattr(torch.backends.cudnn, 'benchmark', True)"
76
+ ],
77
+ "run": [
78
  "$@validate#evaluator.run()"
79
  ]
80
  }
configs/inference.json CHANGED
@@ -152,8 +152,10 @@
152
  "val_handlers": "@handlers",
153
  "amp": true
154
  },
155
- "evaluating": [
156
- "$setattr(torch.backends.cudnn, 'benchmark', True)",
 
 
157
  "$@evaluator.run()"
158
  ]
159
  }
 
152
  "val_handlers": "@handlers",
153
  "amp": true
154
  },
155
+ "initialize": [
156
+ "$setattr(torch.backends.cudnn, 'benchmark', True)"
157
+ ],
158
+ "run": [
159
  "$@evaluator.run()"
160
  ]
161
  }
configs/metadata.json CHANGED
@@ -1,13 +1,14 @@
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"
@@ -23,7 +24,7 @@
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": [
 
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": "adapt to BundleWorkflow interface and val metric",
6
  "0.1.0": "complete the model package",
7
  "0.0.1": "initialize the model package structure"
8
  },
9
+ "monai_version": "1.2.0rc3",
10
+ "pytorch_version": "1.13.1",
11
+ "numpy_version": "1.22.2",
12
  "optional_packages_version": {
13
  "nibabel": "4.0.1",
14
  "pytorch-ignite": "0.4.9"
 
24
  "label_classes": "0 is the background, others are whole body segments",
25
  "pred_classes": "0 is the background, 104 other chanels are whole body segments",
26
  "eval_metrics": {
27
+ "mean_dice": 0.8
28
  },
29
  "intended_use": "This is an example, not to be used for diagnostic purposes",
30
  "references": [
configs/multi_gpu_evaluate.json CHANGED
@@ -15,14 +15,18 @@
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
  }
 
15
  },
16
  "validate#dataloader#sampler": "@validate#sampler",
17
  "validate#handlers#1#_disabled_": "$dist.get_rank() > 0",
18
+ "initialize": [
19
  "$import torch.distributed as dist",
20
+ "$dist.is_initialized() or 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
+ ],
26
+ "run": [
27
+ "$@validate#evaluator.run()"
28
+ ],
29
+ "finalize": [
30
  "$dist.destroy_process_group()"
31
  ]
32
  }
configs/multi_gpu_train.json CHANGED
@@ -24,16 +24,20 @@
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
  }
 
24
  },
25
  "validate#dataloader#sampler": "@validate#sampler",
26
  "validate#evaluator#val_handlers": "$None if dist.get_rank() > 0 else @validate#handlers",
27
+ "initialize": [
28
  "$import torch.distributed as dist",
29
+ "$dist.is_initialized() or 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
+ ],
37
+ "run": [
38
+ "$@train#trainer.run()"
39
+ ],
40
+ "finalize": [
41
  "$dist.destroy_process_group()"
42
  ]
43
  }
configs/train.json CHANGED
@@ -414,9 +414,11 @@
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
  }
 
414
  "amp": true
415
  }
416
  },
417
+ "initialize": [
418
  "$monai.utils.set_determinism(seed=123)",
419
+ "$setattr(torch.backends.cudnn, 'benchmark', True)"
420
+ ],
421
+ "run": [
422
  "$@train#trainer.run()"
423
  ]
424
  }
docs/README.md CHANGED
@@ -110,13 +110,13 @@ For more details usage instructions, visit the [MONAI Bundle Configuration Page]
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).
@@ -124,24 +124,24 @@ Please note that the distributed training-related options depend on the actual r
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
 
 
110
  #### Execute training
111
 
112
  ```
113
+ python -m monai.bundle run --config_file configs/train.json
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 --config_file "['configs/train.json','configs/multi_gpu_train.json']"
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).
 
124
  #### Override the `train` config to execute evaluation with the trained model
125
 
126
  ```
127
+ python -m monai.bundle run --config_file "['configs/train.json','configs/evaluate.json']"
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 --config_file "['configs/train.json','configs/evaluate.json','configs/multi_gpu_evaluate.json']"
134
  ```
135
 
136
  #### Execute inference
137
 
138
  ```
139
+ python -m monai.bundle run --config_file configs/inference.json
140
  ```
141
  #### Execute inference with Data Samples
142
 
143
  ```
144
+ python -m monai.bundle run --config_file configs/inference.json --datalist "['sampledata/imagesTr/s0037.nii.gz','sampledata/imagesTr/s0038.nii.gz']"
145
  ```
146
 
147