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

6834 Add MetaProterties and update load API #6835

Merged
merged 70 commits into from
Aug 30, 2023
Merged

Conversation

KumoLiu
Copy link
Contributor

@KumoLiu KumoLiu commented Aug 8, 2023

Fixes #6834.

Description

See #6835 (comment).

Types of changes

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

@KumoLiu KumoLiu changed the title 6834 from_bundle API: support get properties and metadata from bundle 6834 get API: support get properties and metadata from bundle Aug 10, 2023
KumoLiu and others added 3 commits August 10, 2023 23:42
Signed-off-by: KumoLiu <yunl@nvidia.com>
to `bundle_name` and `config_path`

Signed-off-by: KumoLiu <yunl@nvidia.com>
@KumoLiu KumoLiu marked this pull request as ready for review August 11, 2023 07:08
@KumoLiu
Copy link
Contributor Author

KumoLiu commented Aug 11, 2023

After all the reviews, I'll add the relevant unittests.

Signed-off-by: KumoLiu <yunl@nvidia.com>
@KumoLiu KumoLiu requested a review from wyli August 11, 2023 07:52
Signed-off-by: KumoLiu <yunl@nvidia.com>
Signed-off-by: KumoLiu <yunl@nvidia.com>
Copy link
Contributor

@wyli wyli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, please see some comments inline..

monai/bundle/scripts.py Outdated Show resolved Hide resolved
monai/bundle/scripts.py Outdated Show resolved Hide resolved
monai/bundle/scripts.py Outdated Show resolved Hide resolved
monai/bundle/scripts.py Outdated Show resolved Hide resolved
monai/bundle/scripts.py Outdated Show resolved Hide resolved
Signed-off-by: KumoLiu <yunl@nvidia.com>
Signed-off-by: KumoLiu <yunl@nvidia.com>
Signed-off-by: KumoLiu <yunl@nvidia.com>
monai/bundle/scripts.py Outdated Show resolved Hide resolved
monai/bundle/scripts.py Outdated Show resolved Hide resolved
Signed-off-by: KumoLiu <yunl@nvidia.com>
Signed-off-by: KumoLiu <yunl@nvidia.com>
@Nic-Ma
Copy link
Contributor

Nic-Ma commented Aug 29, 2023

I will review this PR tonight.

Thanks.

monai/bundle/scripts.py Outdated Show resolved Hide resolved
monai/bundle/scripts.py Show resolved Hide resolved
monai/bundle/scripts.py Show resolved Hide resolved
monai/bundle/workflows.py Outdated Show resolved Hide resolved
monai/bundle/workflows.py Outdated Show resolved Hide resolved
@ericspod
Copy link
Member

looks good to me, it seems monai.bundle.scripts module now has too many functions, perhaps it could be refactored into multiple modules/files..

Yes maybe we should turn this into a subdirectory now and have separate files for each script. I would leave that to a later PR however and get this one completed sooner as I want to align my bundle tutorials with this.

KumoLiu and others added 5 commits August 30, 2023 10:56
Signed-off-by: KumoLiu <yunl@nvidia.com>
Signed-off-by: KumoLiu <yunl@nvidia.com>
Signed-off-by: KumoLiu <yunl@nvidia.com>
Copy link
Contributor

@Nic-Ma Nic-Ma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put some minor comments inline, others look good to me.

Thanks.

KumoLiu and others added 3 commits August 30, 2023 13:24
Signed-off-by: KumoLiu <yunl@nvidia.com>
Signed-off-by: KumoLiu <yunl@nvidia.com>
@wyli
Copy link
Contributor

wyli commented Aug 30, 2023

/build

@wyli wyli enabled auto-merge (squash) August 30, 2023 12:49
@wyli wyli merged commit a4e4894 into Project-MONAI:dev Aug 30, 2023
27 of 32 checks passed
@KumoLiu KumoLiu deleted the from-bundle branch August 30, 2023 14:18
KumoLiu added a commit to KumoLiu/MONAI that referenced this pull request Aug 30, 2023
Fixes Project-MONAI#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>
wyli pushed a commit to Project-MONAI/tutorials that referenced this pull request Sep 4, 2023
Fixes #1503.

### Description
After Project-MONAI/MONAI#6835, `load` can
directly return an instantiated network that loaded the weights.

### Checks
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [ ] Avoid including large-size files in the PR.
- [ ] Clean up long text outputs from code cells in the notebook.
- [ ] For security purposes, please check the contents and remove any
sensitive info such as user names and private key.
- [ ] 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>
wyli pushed a commit that referenced this pull request Sep 7, 2023
Fixes # .

### Description
Avoid breaking changes introduced by
#6835
- when creating `BundleWorkflow`
- when using `load` API, add `return_state_dict` when `model` and
`net_name` are both `None`.

### 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>
Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
Co-authored-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
wyli pushed a commit that referenced this pull request Sep 12, 2023
…6917)

Part of #6552.

### Description
After PR #6835, we have added `copy_model_args` in the `load` API which
can help us update the state_dict flexibly.

https://github.com/KumoLiu/MONAI/blob/93a149a611b66153cf804b31a7b36a939e2e593a/monai/bundle/scripts.py#L397

Given this [issue](#6552),
we need to be able to filter the model's weights flexibly.
In `copy_model_state`, we already have a "mapping" arg, the filter will
be more flexible if we can support regular expression in the mapping.
This PR mainly added the support for regular expression for "mapping"
arg.

In the
[example](#6552 (comment))
in this [issue](#6552),
after this PR, we can do something like:
```
exclude_vars = "encoder.mask_token|encoder.norm.weight|encoder.norm.bias|out.conv.conv.weight|out.conv.conv.bias"
mapping={"encoder.layers(.*).0.0.": "swinViT.layers(.*).0."}
dst_dict, updated_keys, unchanged_keys = copy_model_state(
       model, ssl_weights, exclude_vars=exclude_vars, mapping=mapping
)
```

Additionally, based on the comments of Eric
[here](#6552 (comment)),
I totally agree, we could add a handler to make the pipeline easier to
implement, but perhaps this task is no need to set as a "BundleTodo" for
MONAIv1.3 but as an enhancement for MONAI near future.
What do you think? @ericspod @wyli @Nic-Ma 

### 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>
boneseva pushed a commit to boneseva/MONAI-tutorials that referenced this pull request Apr 21, 2024
Fixes Project-MONAI#1503.

### Description
After Project-MONAI/MONAI#6835, `load` can
directly return an instantiated network that loaded the weights.

### Checks
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [ ] Avoid including large-size files in the PR.
- [ ] Clean up long text outputs from code cells in the notebook.
- [ ] For security purposes, please check the contents and remove any
sensitive info such as user names and private key.
- [ ] 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add MetaProterties and update load API
6 participants