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

set image_only=True in LoadImaged #5007

Closed
KumoLiu opened this issue Aug 26, 2022 · 2 comments · Fixed by #5900
Closed

set image_only=True in LoadImaged #5007

KumoLiu opened this issue Aug 26, 2022 · 2 comments · Fixed by #5900

Comments

@KumoLiu
Copy link
Contributor

KumoLiu commented Aug 26, 2022

Is your feature request related to a problem? Please describe.
Since 0.9.1, we recommend that users use MataTensor, which will save the meta information in metatensor by default. The default value of image_only in LoadImage is False, which will return image and header dict.

image_only: bool = False,

For some transforms that have deprecated the meta_dict which meta information in meta_dict will not be updated in time. Such as Spacingd
@deprecated_arg(name="meta_keys", since="0.9")
@deprecated_arg(name="meta_key_postfix", since="0.9")

Describe the solution you'd like
Set image_only=True in LoadImaged and LoadImage

@rijobro
Copy link
Contributor

rijobro commented Aug 26, 2022

I think we'd definitely like to see this happen, we didn't do this initially as there may be lots of other places in the codebase that assume load image to return the meta data, or at least to return multiple objects. This sort of thing would be trickier to pick up on:

image = LoadImage()(fname)[0]

With the old default, [0] would return just the image and omit the metadata. But if the default were changed then [0] would slice the image taking the 0th element of the 0th dimension. This wouldn't cause an error, so would be hard to spot but would clearly be erroneous as we'd be throwing away parts of the image.

It would be hard to find and replace all instances of this in our own code base and tutorials, and we have have no way of correcting code that users have written, nor any way of printing a deprecated error/warning if users were using the default and the default has changed.

@wyli
Copy link
Contributor

wyli commented Sep 7, 2022

changing the default will avoid this confusion #5097.

wyli added a commit that referenced this issue Jan 27, 2023
…adImage` (#5900)

Signed-off-by: Wenqi Li <[email protected]>

Fixes #5007

### Description
adds a warning message about changing the default value of
`image_only=False` to `image=True` in 1.3

example warnings:

```py
Python 3.8.13 (default, Mar 28 2022, 06:16:26) 
[Clang 12.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from monai.transforms import LoadImage; LoadImage()
monai.transforms.io.array LoadImage.__init__:image_only: Current default value of argument `image_only=False` has been deprecated since 1.1. It will be changed to `image_only=True` in version 1.3.
<monai.transforms.io.array.LoadImage object at 0x7fe9e807fe20>
>>> from monai.transforms import LoadImageD; LoadImageD('test')
monai.transforms.io.dictionary LoadImaged.__init__:image_only: Current default value of argument `image_only=False` has been deprecated since 1.1. It will be changed to `image_only=True` in version 1.3.
<monai.transforms.io.dictionary.LoadImaged object at 0x7fe9c97062b0>
>>> 

```

### 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: Wenqi Li <[email protected]>
Signed-off-by: Wenqi Li <[email protected]>
Co-authored-by: Eric Kerfoot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants