Skip to content

Commit a131166

Browse files
authored
Update "app_integrate_bundle" (Project-MONAI#1500)
Fixes Project-MONAI#1499. ### Description - update README - use `create_workflow` ### Checks <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Avoid including large-size files in the PR. - [x] Clean up long text outputs from code cells in the notebook. - [x] For security purposes, please check the contents and remove any sensitive info such as user names and private key. - [x] Ensure (1) hyperlinks and markdown anchors are working (2) use relative paths for tutorial repo files (3) put figure and graphs in the `./figure` folder - [ ] Notebook runs automatically `./runner.sh -t <path to .ipynb file>` Signed-off-by: KumoLiu <yunl@nvidia.com>
1 parent 0140280 commit a131166

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

model_zoo/app_integrate_bundle/README.md

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,18 @@ python ensemble.py --bundle_root bundle_root_path --dataset_dir data_root_path
8383

8484
## **How to integrate Bundle in your own application**
8585
### Get component from bundle
86+
Check all supported properties in https://github.com/Project-MONAI/MONAI/blob/dev/monai/bundle/properties.py.
8687
```
87-
from monai.bundle import ConfigWorkflow
88-
89-
train_workflow = ConfigWorkflow(
90-
config_file=bundle_config_path,
91-
meta_file=bundle_metadata_path,
92-
logging_file=bundle_logging_path,
93-
workflow="train",
94-
)
95-
train_workflow.initialize()
88+
from monai.bundle import create_workflow
89+
90+
train_workflow = create_workflow(config_file=bundle_config_path, workflow_type="train")
91+
92+
# get train postprocessing
9693
postprocessing = train_workflow.train_postprocessing
94+
95+
# get meta information
96+
version = train_workflow.version
97+
description = train_workflow.description
9798
```
9899
### Use component in your pipeline
99100
```
@@ -108,9 +109,25 @@ evaluator = SupervisedEvaluator(
108109
)
109110
```
110111
### Update component with your own args
112+
113+
- If the component you want to replace is listed [here](https://github.com/Project-MONAI/MONAI/blob/dev/monai/bundle/properties.py), you can replace it directly as below:
111114
```
112115
# update `max_epochs` in workflow
113116
train_workflow.max_epochs = max_epochs
117+
118+
# must execute 'initialize' again after changing the content
119+
train_workflow.initialize()
120+
print(train_workflow.max_epochs)
121+
```
122+
- Otherwise, you can override the components when you create the workflow.
123+
```
124+
override = {
125+
"network": "$@network_def.to(@device)",
126+
"dataset#_target_": "Dataset",
127+
"dataset#data": [{"image": filename}],
128+
"postprocessing#transforms#2#output_postfix": "seg",
129+
}
130+
train_workflow = create_workflow(config_file=bundle_config_path, workflow_type="train", **override)
114131
```
115132
116133
## Questions and bugs

model_zoo/app_integrate_bundle/ensemble.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import torch
1919
from monai.transforms import Compose
2020
from monai.transforms.post.dictionary import MeanEnsembled, VoteEnsembled
21-
from monai.bundle import ConfigWorkflow
21+
from monai.bundle import create_workflow
2222
from monai.engines import EnsembleEvaluator
2323
from monai.utils import optional_import
2424

@@ -74,12 +74,7 @@ def __init__(self, path):
7474
self.bundle_metadata_path = os.path.join(path, "configs", Const.METADATA_JSON)
7575
self.bundle_logging_path = os.path.join(path, "configs", Const.LOGGING_CONFIG)
7676

77-
self.train_workflow = ConfigWorkflow(
78-
config_file=self.bundle_config_path,
79-
meta_file=self.bundle_metadata_path,
80-
logging_file=self.bundle_logging_path,
81-
workflow="train",
82-
)
77+
self.train_workflow = create_workflow(config_file=self.bundle_config_path, workflow_type="train")
8378

8479
def _partition_datalist(self, datalist, n_splits=5, shuffle=False):
8580
logger.info(f"Total Records in Dataset: {len(datalist)}")
@@ -110,12 +105,7 @@ def ensemble_inference(self, device, test_datalist, ensemble="Mean"):
110105
logger.info(f"Total Records in Test Dataset: {len(test_datalist)}")
111106

112107
bundle_inference_config_path = os.path.join(self.bundle_path, "configs", inference_config_paths[0])
113-
inference_workflow = ConfigWorkflow(
114-
config_file=bundle_inference_config_path,
115-
meta_file=None,
116-
logging_file=None,
117-
workflow="inference",
118-
)
108+
inference_workflow = create_workflow(config_file=bundle_inference_config_path, workflow_type="inference")
119109
inference_workflow.dataset_data = test_datalist
120110
# this application has an additional requirement for the bundle workflow to provide the property dataloader
121111
inference_workflow.add_property(name="dataloader", required=True, config_id="dataloader")

0 commit comments

Comments
 (0)