Skip to content

1866 Add TransformInverter handler #1970

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

Merged
merged 11 commits into from
Apr 9, 2021

Conversation

Nic-Ma
Copy link
Contributor

@Nic-Ma Nic-Ma commented Apr 8, 2021

Fixes #1866 .

Description

This PR added the ignite handler to invert transforms for model output data.

Status

Ready

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.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

@Nic-Ma Nic-Ma requested review from rijobro, ericspod and wyli April 8, 2021 10:31
@Nic-Ma Nic-Ma changed the title [WIP] 1866 add TransformInverter handler [WIP] 1866 Add TransformInverter handler Apr 8, 2021
Signed-off-by: Nic Ma <[email protected]>
@Nic-Ma Nic-Ma force-pushed the 1866-add-inverse-handler branch from f68639f to c632b37 Compare April 8, 2021 10:59
@Nic-Ma Nic-Ma force-pushed the 1866-add-inverse-handler branch from c632b37 to 13e1617 Compare April 8, 2021 11:01
@rijobro
Copy link
Contributor

rijobro commented Apr 8, 2021

Thanks for looking into this @Nic-Ma. I notice an issue here that I hadn't thought about previously.

During training/validation/testing, there will typically be a ground truth label attached, and we'll want to use those transforms for the inverse.

At deployment, we'll probably only be using images (no labels). And typically for labels, we'll use nearest-neighbour interpolation, whereas for images we'll use something else (e.g., linear). So if we do the inverse as you've suggested in this PR, we'll probably be using non-nearest neighbour interpolation on our labels.

I wonder if this would be solved by simply doing AsDiscrete at the end. A little messy. cc @wyli @ericspod.

@Nic-Ma Nic-Ma marked this pull request as ready for review April 8, 2021 12:23
@Nic-Ma
Copy link
Contributor Author

Nic-Ma commented Apr 8, 2021

/black

@Nic-Ma Nic-Ma changed the title [WIP] 1866 Add TransformInverter handler 1866 Add TransformInverter handler Apr 8, 2021
@Nic-Ma
Copy link
Contributor Author

Nic-Ma commented Apr 8, 2021

Hi @rijobro ,

Thanks for your review, there are another 2 minor issues about inverse logic:

  1. You didn't implement the inverse for ToTensorD transform, so it will run with Tensor data, fixed in this PR.
  2. The BatchInverseTransform requires the transform must be InvertibleTransform while the allow_missing_keys_mode requires Compose or MapTransform, it will cause some typehints issue, I ignored in the PR.

About the sampling question you proposed, it's a good point, let me add another arg as_discrete.

Thanks.

@Nic-Ma
Copy link
Contributor Author

Nic-Ma commented Apr 8, 2021

/black

Copy link
Contributor

@rijobro rijobro left a comment

Choose a reason for hiding this comment

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

test is basic, but I suppose testing shape is sufficient here, as voxel values are tested in test_inverse.py. Thanks!

Have you tested this personally to check it works as you expect?

@Nic-Ma
Copy link
Contributor Author

Nic-Ma commented Apr 8, 2021

Hi @rijobro ,

Thanks for your review, I already tested it with the workflow example:
https://github.com/Project-MONAI/tutorials/blob/master/modules/engines/unet_evaluation_dict.py

And I will write another PR to solve the interpolation mode issue soon.

Thanks.

@wyli
Copy link
Contributor

wyli commented Apr 8, 2021

thanks @rijobro chat with Nic offline that we plan to update to store/use the inverse parameters such as mode and align_corners in EXTRA_INFO

@Nic-Ma Nic-Ma enabled auto-merge (squash) April 8, 2021 14:19
@Nic-Ma Nic-Ma merged commit e9ac80c into Project-MONAI:master Apr 9, 2021
nsrivathsa pushed a commit to nsrivathsa/MONAI that referenced this pull request Apr 12, 2021
* [DLMED] add TransformInverter handler

Signed-off-by: Nic Ma <[email protected]>

* [DLMED] fix typo

Signed-off-by: Nic Ma <[email protected]>

* [DLMED] add support in SegmentationSaver handler

Signed-off-by: Nic Ma <[email protected]>

* [DLMED] fix flake8 issue

Signed-off-by: Nic Ma <[email protected]>

* [DLMED] fix flake8 issue

Signed-off-by: Nic Ma <[email protected]>

* [DLMED] fix CI test

Signed-off-by: Nic Ma <[email protected]>

* [MONAI] python code formatting

Signed-off-by: monai-bot <[email protected]>

Co-authored-by: monai-bot <[email protected]>
Signed-off-by: Neha Srivathsa <[email protected]>
@Nic-Ma Nic-Ma deleted the 1866-add-inverse-handler branch July 2, 2021 23:36
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 ignite handler to inverse transforms
4 participants