Skip to content

Commit

Permalink
6834 Add MetaProterties and update load API (#6835)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
KumoLiu authored Aug 30, 2023
1 parent 6f5005f commit a4e4894
Show file tree
Hide file tree
Showing 14 changed files with 378 additions and 147 deletions.
3 changes: 2 additions & 1 deletion monai/bundle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@

from .config_item import ComponentLocator, ConfigComponent, ConfigExpression, ConfigItem, Instantiable
from .config_parser import ConfigParser
from .properties import InferProperties, TrainProperties
from .properties import InferProperties, MetaProperties, TrainProperties
from .reference_resolver import ReferenceResolver
from .scripts import (
ckpt_export,
create_workflow,
download,
get_all_bundles_list,
get_bundle_info,
Expand Down
46 changes: 45 additions & 1 deletion monai/bundle/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
to interact with the bundle workflow.
Some properties are required and some are optional, optional properties mean: if some component of the
bundle workflow refer to the property, the property must be defined, otherwise, the property can be None.
Every item in this `TrainProperties` or `InferProperties` dictionary is a property,
Every item in this `TrainProperties` or `InferProperties` or `MetaProperties` dictionary is a property,
the key is the property name and the values include:
1. description.
2. whether it's a required property.
Expand Down Expand Up @@ -48,6 +48,11 @@
BundleProperty.REQUIRED: True,
BundlePropertyConfig.ID: f"train{ID_SEP_KEY}trainer",
},
"network_def": {
BundleProperty.DESC: "network module for the training.",
BundleProperty.REQUIRED: False,
BundlePropertyConfig.ID: "network_def",
},
"max_epochs": {
BundleProperty.DESC: "max number of epochs to execute the training.",
BundleProperty.REQUIRED: True,
Expand Down Expand Up @@ -216,3 +221,42 @@
BundlePropertyConfig.REF_ID: f"evaluator{ID_SEP_KEY}key_val_metric",
},
}

MetaProperties = {
"version": {
BundleProperty.DESC: "bundle version",
BundleProperty.REQUIRED: True,
BundlePropertyConfig.ID: f"_meta_{ID_SEP_KEY}version",
},
"monai_version": {
BundleProperty.DESC: "required monai version used for bundle",
BundleProperty.REQUIRED: True,
BundlePropertyConfig.ID: f"_meta_{ID_SEP_KEY}monai_version",
},
"pytorch_version": {
BundleProperty.DESC: "required pytorch version used for bundle",
BundleProperty.REQUIRED: True,
BundlePropertyConfig.ID: f"_meta_{ID_SEP_KEY}pytorch_version",
},
"numpy_version": {
BundleProperty.DESC: "required numpy version used for bundle",
BundleProperty.REQUIRED: True,
BundlePropertyConfig.ID: f"_meta_{ID_SEP_KEY}numpy_version",
},
"description": {
BundleProperty.DESC: "description for bundle",
BundleProperty.REQUIRED: False,
BundlePropertyConfig.ID: f"_meta_{ID_SEP_KEY}description",
},
"spatial_shape": {
BundleProperty.DESC: "spatial shape for the inputs",
BundleProperty.REQUIRED: False,
BundlePropertyConfig.ID: f"_meta_{ID_SEP_KEY}network_data_format{ID_SEP_KEY}inputs{ID_SEP_KEY}image"
f"{ID_SEP_KEY}spatial_shape",
},
"channel_def": {
BundleProperty.DESC: "channel definition for the prediction",
BundleProperty.REQUIRED: False,
BundlePropertyConfig.ID: f"_meta_{ID_SEP_KEY}network_data_format{ID_SEP_KEY}outputs{ID_SEP_KEY}pred{ID_SEP_KEY}channel_def",
},
}
Loading

0 comments on commit a4e4894

Please sign in to comment.