Skip to content

backward compatible inverse#4648

Merged
wyli merged 19 commits intoProject-MONAI:devfrom
wyli:compatibility
Jul 10, 2022
Merged

backward compatible inverse#4648
wyli merged 19 commits intoProject-MONAI:devfrom
wyli:compatibility

Conversation

@wyli
Copy link
Copy Markdown
Contributor

@wyli wyli commented Jul 7, 2022

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

Description

adding pre/post hooks to MapTransform/InvertibleTransform so that the dictionary-based transforms and their inverse can still have v0.9.0 behaviour.

Status

Ready/Work in progress/Hold

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.

@wyli wyli requested review from Nic-Ma, ericspod and rijobro July 7, 2022 00:27
@Nic-Ma Nic-Ma requested a review from KumoLiu July 7, 2022 02:16
@Nic-Ma
Copy link
Copy Markdown
Contributor

Nic-Ma commented Jul 7, 2022

Hi @wyli ,

Thanks for raising the idea.
Could you please help add the doc-string and typical use-cases for the new functions?
I tried to guess what the functions are used and the args mean, but still don't quite understand.

Thanks in advance.

wyli added 2 commits July 7, 2022 07:29
Signed-off-by: Wenqi Li <[email protected]>
Signed-off-by: Wenqi Li <[email protected]>
@wyli wyli force-pushed the compatibility branch from 485b3c6 to 7f65b37 Compare July 7, 2022 06:29
@wyli
Copy link
Copy Markdown
Contributor Author

wyli commented Jul 7, 2022

sure, I updated the docstring, it adds hooks to MapTransform.__call__ and InvertibleTransform.inverse, for example the cropper's output will have img_transforms in this case, with img_transforms's value from d['img'].applied_operations:

import torch
from monai.transforms import CenterSpatialCropD

a = torch.zeros((1, 10, 10))
data_dict = {"img": a}
cropper = CenterSpatialCropD("img", roi_size=(7, 7))
output = cropper(data_dict)
print(output.keys())
print(output['img'])
print(output['img_transforms'])

output:

dict_keys(['img', 'img_transforms'])
tensor([[[0., 0., 0., 0., 0., 0., 0.],
         [0., 0., 0., 0., 0., 0., 0.],
         [0., 0., 0., 0., 0., 0., 0.],
         [0., 0., 0., 0., 0., 0., 0.],
         [0., 0., 0., 0., 0., 0., 0.],
         [0., 0., 0., 0., 0., 0., 0.],
         [0., 0., 0., 0., 0., 0., 0.]]])
MetaData
	affine: tensor([[1., 0., 0., 2.],
        [0., 1., 0., 2.],
        [0., 0., 1., 0.],
        [0., 0., 0., 1.]], dtype=torch.float64)

Applied operations
[{class: 'CenterSpatialCrop', extra_info: {'cropped': [2, 1, 2, 1]}, id: 140454425823456, orig_size: (10, 10)}]
Is batch?: False
[{class: 'CenterSpatialCrop', id: 140454425823456, orig_size: (10, 10), extra_info: {'cropped': [2, 1, 2, 1]}}]

wyli added 3 commits July 7, 2022 09:01
Signed-off-by: Wenqi Li <[email protected]>
Signed-off-by: Wenqi Li <[email protected]>
Signed-off-by: Wenqi Li <[email protected]>
@wyli wyli force-pushed the compatibility branch from 14d4444 to 79c2557 Compare July 7, 2022 12:39
Signed-off-by: Wenqi Li <[email protected]>
@wyli wyli force-pushed the compatibility branch from 79c2557 to 49d91e8 Compare July 7, 2022 13:17
@Nic-Ma
Copy link
Copy Markdown
Contributor

Nic-Ma commented Jul 7, 2022

Hi @wyli ,

Could you please help add this print(output['img_transforms']) in some unit test to verify?

Thanks in advance.

wyli added 7 commits July 7, 2022 15:11
Signed-off-by: Wenqi Li <[email protected]>
Signed-off-by: Wenqi Li <[email protected]>
Signed-off-by: Wenqi Li <[email protected]>
Signed-off-by: Wenqi Li <[email protected]>
Signed-off-by: Wenqi Li <[email protected]>
Signed-off-by: Wenqi Li <[email protected]>
@wyli wyli force-pushed the compatibility branch from 74ce3b3 to 3d81031 Compare July 8, 2022 11:00
Signed-off-by: Wenqi Li <[email protected]>
@wyli
Copy link
Copy Markdown
Contributor Author

wyli commented Jul 8, 2022

/black
/integration-test
/black

Could you please help add this print(output['img_transforms']) in some unit test to verify?

Thanks in advance.

thanks, I've updated and now the default is USE_META_DICT=False. please help review again.

@wyli wyli marked this pull request as ready for review July 8, 2022 13:33
@wyli wyli force-pushed the compatibility branch from 7eee0a2 to fddeaf8 Compare July 8, 2022 21:52
Copy link
Copy Markdown
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.

It overall looks good to me, put minor comments inline. Mainly about adding the array level Invert transform for MetaTensor.

Thanks.

wyli added 2 commits July 10, 2022 12:10
Signed-off-by: Wenqi Li <[email protected]>
@wyli
Copy link
Copy Markdown
Contributor Author

wyli commented Jul 10, 2022

/build

@Nic-Ma
Copy link
Copy Markdown
Contributor

Nic-Ma commented Jul 10, 2022

Hi @wyli ,

Is there any unit tests or integration tests error after removing all the deepcopy in the inverse functions?

Thanks.

@wyli
Copy link
Copy Markdown
Contributor Author

wyli commented Jul 10, 2022

Hi @wyli ,

Is there any unit tests or integration tests error after removing all the deepcopy in the inverse functions?

Thanks.

Don't see any issue, probably it's not needed and is more efficient.

@wyli wyli merged commit 9580603 into Project-MONAI:dev Jul 10, 2022
@wyli wyli deleted the compatibility branch July 10, 2022 14:45
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.

2 participants