Skip to content

Commit a4e4894

Browse files
authored
6834 Add MetaProterties and update load API (#6835)
Fixes #6834. ### Description This PR introduces the idea of `BundleManager`, with `get` as one of the methods, to avoid repeatedly instantiating `ConfigWorkflow`. **usage** ``` bundle = BundleManager("spleen_ct_segmentation") bundle.get("network_data_format") or bundle.get(property="train_preprocessing") ``` ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: KumoLiu <yunl@nvidia.com>
1 parent 6f5005f commit a4e4894

14 files changed

+378
-147
lines changed

monai/bundle/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313

1414
from .config_item import ComponentLocator, ConfigComponent, ConfigExpression, ConfigItem, Instantiable
1515
from .config_parser import ConfigParser
16-
from .properties import InferProperties, TrainProperties
16+
from .properties import InferProperties, MetaProperties, TrainProperties
1717
from .reference_resolver import ReferenceResolver
1818
from .scripts import (
1919
ckpt_export,
20+
create_workflow,
2021
download,
2122
get_all_bundles_list,
2223
get_bundle_info,

monai/bundle/properties.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
to interact with the bundle workflow.
1414
Some properties are required and some are optional, optional properties mean: if some component of the
1515
bundle workflow refer to the property, the property must be defined, otherwise, the property can be None.
16-
Every item in this `TrainProperties` or `InferProperties` dictionary is a property,
16+
Every item in this `TrainProperties` or `InferProperties` or `MetaProperties` dictionary is a property,
1717
the key is the property name and the values include:
1818
1. description.
1919
2. whether it's a required property.
@@ -48,6 +48,11 @@
4848
BundleProperty.REQUIRED: True,
4949
BundlePropertyConfig.ID: f"train{ID_SEP_KEY}trainer",
5050
},
51+
"network_def": {
52+
BundleProperty.DESC: "network module for the training.",
53+
BundleProperty.REQUIRED: False,
54+
BundlePropertyConfig.ID: "network_def",
55+
},
5156
"max_epochs": {
5257
BundleProperty.DESC: "max number of epochs to execute the training.",
5358
BundleProperty.REQUIRED: True,
@@ -216,3 +221,42 @@
216221
BundlePropertyConfig.REF_ID: f"evaluator{ID_SEP_KEY}key_val_metric",
217222
},
218223
}
224+
225+
MetaProperties = {
226+
"version": {
227+
BundleProperty.DESC: "bundle version",
228+
BundleProperty.REQUIRED: True,
229+
BundlePropertyConfig.ID: f"_meta_{ID_SEP_KEY}version",
230+
},
231+
"monai_version": {
232+
BundleProperty.DESC: "required monai version used for bundle",
233+
BundleProperty.REQUIRED: True,
234+
BundlePropertyConfig.ID: f"_meta_{ID_SEP_KEY}monai_version",
235+
},
236+
"pytorch_version": {
237+
BundleProperty.DESC: "required pytorch version used for bundle",
238+
BundleProperty.REQUIRED: True,
239+
BundlePropertyConfig.ID: f"_meta_{ID_SEP_KEY}pytorch_version",
240+
},
241+
"numpy_version": {
242+
BundleProperty.DESC: "required numpy version used for bundle",
243+
BundleProperty.REQUIRED: True,
244+
BundlePropertyConfig.ID: f"_meta_{ID_SEP_KEY}numpy_version",
245+
},
246+
"description": {
247+
BundleProperty.DESC: "description for bundle",
248+
BundleProperty.REQUIRED: False,
249+
BundlePropertyConfig.ID: f"_meta_{ID_SEP_KEY}description",
250+
},
251+
"spatial_shape": {
252+
BundleProperty.DESC: "spatial shape for the inputs",
253+
BundleProperty.REQUIRED: False,
254+
BundlePropertyConfig.ID: f"_meta_{ID_SEP_KEY}network_data_format{ID_SEP_KEY}inputs{ID_SEP_KEY}image"
255+
f"{ID_SEP_KEY}spatial_shape",
256+
},
257+
"channel_def": {
258+
BundleProperty.DESC: "channel definition for the prediction",
259+
BundleProperty.REQUIRED: False,
260+
BundlePropertyConfig.ID: f"_meta_{ID_SEP_KEY}network_data_format{ID_SEP_KEY}outputs{ID_SEP_KEY}pred{ID_SEP_KEY}channel_def",
261+
},
262+
}

0 commit comments

Comments
 (0)