Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

294 Update Spleen bundle with new interface #331

Merged
merged 2 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
modify spleen
  • Loading branch information
yiheng-wang-nv committed Mar 23, 2023
commit f3d01c3e7b3868763cb29d9572d945b3e67c7005
6 changes: 4 additions & 2 deletions models/spleen_ct_segmentation/configs/evaluate.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@
"summary_ops": "*"
}
],
"evaluating": [
"$setattr(torch.backends.cudnn, 'benchmark', True)",
"initialize": [
"$setattr(torch.backends.cudnn, 'benchmark', True)"
],
"run": [
"$@validate#evaluator.run()"
]
}
8 changes: 5 additions & 3 deletions models/spleen_ct_segmentation/configs/inference.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"$import glob",
"$import os"
],
"bundle_root": "/workspace/data/spleen_ct_segmentation",
"bundle_root": ".",
"output_dir": "$@bundle_root + '/eval'",
"dataset_dir": "/workspace/data/Task09_Spleen",
"datalist": "$list(sorted(glob.glob(@dataset_dir + '/imagesTs/*.nii.gz')))",
Expand Down Expand Up @@ -146,8 +146,10 @@
"val_handlers": "@handlers",
"amp": true
},
"evaluating": [
"$setattr(torch.backends.cudnn, 'benchmark', True)",
"initialize": [
"$setattr(torch.backends.cudnn, 'benchmark', True)"
],
"run": [
"$@evaluator.run()"
]
}
5 changes: 3 additions & 2 deletions models/spleen_ct_segmentation/configs/metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"schema": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_20220324.json",
"version": "0.3.8",
"version": "0.3.9",
"changelog": {
"0.3.9": "use new interface",
yiheng-wang-nv marked this conversation as resolved.
Show resolved Hide resolved
"0.3.8": "add name tag",
"0.3.7": "restructure readme to match updated template",
"0.3.6": "enhance readme with details of model training",
Expand All @@ -16,7 +17,7 @@
"0.1.0": "complete the model package",
"0.0.1": "initialize the model package structure"
},
"monai_version": "1.0.1",
"monai_version": "1.2.0rc2",
"pytorch_version": "1.13.0",
"numpy_version": "1.21.2",
"optional_packages_version": {
Expand Down
10 changes: 7 additions & 3 deletions models/spleen_ct_segmentation/configs/multi_gpu_evaluate.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@
},
"validate#dataloader#sampler": "@validate#sampler",
"validate#handlers#1#_disabled_": "$dist.get_rank() > 0",
"evaluating": [
"initialize": [
"$import torch.distributed as dist",
"$dist.init_process_group(backend='nccl')",
yiheng-wang-nv marked this conversation as resolved.
Show resolved Hide resolved
"$torch.cuda.set_device(@device)",
"$setattr(torch.backends.cudnn, 'benchmark', True)",
"$import logging",
"$@validate#evaluator.logger.setLevel(logging.WARNING if dist.get_rank() > 0 else logging.INFO)",
"$@validate#evaluator.run()",
"$@validate#evaluator.logger.setLevel(logging.WARNING if dist.get_rank() > 0 else logging.INFO)"
],
"run": [
"$@validate#evaluator.run()"
],
"finalize": [
"$dist.destroy_process_group()"
]
}
10 changes: 7 additions & 3 deletions models/spleen_ct_segmentation/configs/multi_gpu_train.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,20 @@
},
"validate#dataloader#sampler": "@validate#sampler",
"validate#evaluator#val_handlers": "$None if dist.get_rank() > 0 else @validate#handlers",
"training": [
"initialize": [
"$import torch.distributed as dist",
"$dist.init_process_group(backend='nccl')",
"$torch.cuda.set_device(@device)",
"$monai.utils.set_determinism(seed=123)",
"$setattr(torch.backends.cudnn, 'benchmark', True)",
"$import logging",
"$@train#trainer.logger.setLevel(logging.WARNING if dist.get_rank() > 0 else logging.INFO)",
"$@validate#evaluator.logger.setLevel(logging.WARNING if dist.get_rank() > 0 else logging.INFO)",
"$@train#trainer.run()",
"$@validate#evaluator.logger.setLevel(logging.WARNING if dist.get_rank() > 0 else logging.INFO)"
],
"run": [
"$@train#trainer.run()"
],
"finalize": [
"$dist.destroy_process_group()"
]
}
8 changes: 5 additions & 3 deletions models/spleen_ct_segmentation/configs/train.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"$import os",
"$import ignite"
],
"bundle_root": "/workspace/data/spleen_ct_segmentation",
"bundle_root": ".",
"ckpt_dir": "$@bundle_root + '/models'",
"output_dir": "$@bundle_root + '/eval'",
"dataset_dir": "/workspace/data/Task09_Spleen",
Expand Down Expand Up @@ -281,9 +281,11 @@
"amp": true
}
},
"training": [
"initialize": [
"$monai.utils.set_determinism(seed=123)",
"$setattr(torch.backends.cudnn, 'benchmark', True)",
"$setattr(torch.backends.cudnn, 'benchmark', True)"
],
"run": [
"$@train#trainer.run()"
]
}
10 changes: 5 additions & 5 deletions models/spleen_ct_segmentation/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,33 +52,33 @@ For more details usage instructions, visit the [MONAI Bundle Configuration Page]
#### Execute training:

```
python -m monai.bundle run training --meta_file configs/metadata.json --config_file configs/train.json --logging_file configs/logging.conf
python -m monai.bundle run --config_file configs/train.json
```

#### Override the `train` config to execute multi-GPU training:

```
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
torchrun --standalone --nnodes=1 --nproc_per_node=2 -m monai.bundle run --config_file "['configs/train.json','configs/multi_gpu_train.json']"
```

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).

#### Override the `train` config to execute evaluation with the trained model:

```
python -m monai.bundle run evaluating --meta_file configs/metadata.json --config_file "['configs/train.json','configs/evaluate.json']" --logging_file configs/logging.conf
python -m monai.bundle run --config_file "['configs/train.json','configs/evaluate.json']"
```

#### Override the `train` config and `evaluate` config to execute multi-GPU evaluation:

```
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
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']"
```

#### Execute inference:

```
python -m monai.bundle run evaluating --meta_file configs/metadata.json --config_file configs/inference.json --logging_file configs/logging.conf
python -m monai.bundle run --config_file configs/inference.json
```

# References
Expand Down