Skip to content

Torch flip#2822

Merged
rijobro merged 13 commits intoProject-MONAI:devfrom
rijobro:torch_flip
Aug 24, 2021
Merged

Torch flip#2822
rijobro merged 13 commits intoProject-MONAI:devfrom
rijobro:torch_flip

Conversation

@rijobro
Copy link
Copy Markdown
Contributor

@rijobro rijobro commented Aug 23, 2021

Description

Torch/Numpy Flip-based transforms.

Requires #2815 to be merged first.

Status

Ready

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • 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.

rijobro added 12 commits August 20, 2021 15:55
Signed-off-by: Richard Brown <[email protected]>
Signed-off-by: Richard Brown <[email protected]>
Signed-off-by: Richard Brown <[email protected]>
Signed-off-by: Richard Brown <[email protected]>
Signed-off-by: Richard Brown <[email protected]>
Signed-off-by: Richard Brown <[email protected]>
Signed-off-by: Richard Brown <[email protected]>
Signed-off-by: Richard Brown <[email protected]>
@rijobro
Copy link
Copy Markdown
Contributor Author

rijobro commented Aug 24, 2021

/build

@rijobro rijobro requested review from Nic-Ma and wyli August 24, 2021 09:48
result = flip(im)
if isinstance(result, torch.Tensor):
result = result.cpu()
self.assertTrue(np.allclose(expected, result))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

could you help change this to np.testing.assert_allclose(doc) it would give us more info when there are mismatches. also, as we are having more transform supporting both tensor and np.array, would be great to have a utility assert_allclose that can handle both types

@wyli
Copy link
Copy Markdown
Contributor

wyli commented Aug 24, 2021

/build
I also enable the testing here in case you want to merge it without revising

@wyli
Copy link
Copy Markdown
Contributor

wyli commented Aug 24, 2021

/build

@rijobro rijobro enabled auto-merge (squash) August 24, 2021 13:17
@rijobro
Copy link
Copy Markdown
Contributor Author

rijobro commented Aug 24, 2021

thanks @wyli - will add the testing as the next PR.

@rijobro rijobro merged commit fab8467 into Project-MONAI:dev Aug 24, 2021
@rijobro rijobro deleted the torch_flip branch August 24, 2021 13:52
data[str(key) + InverseKeys.KEY_SUFFIX].pop()

def inverse(self, data: dict) -> Dict[Hashable, np.ndarray]:
def inverse(self, data: dict) -> dict:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

May I know why you change Dict annotation to dict?

Thanks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I needed to make it more general. Otherwise the derived classes can't return Dict[Hashable, NdarrayOrTensor]. I'm hoping to be able to put it back in once the transforms are done. For some reason I couldn't set the parent class (InvertibleTransform) to have Dict[Hashable, NdarrayOrTensor] and have the unmodified classes return Dict[Hashable, np.ndarray], even though this is a more-specific return type. So I had to settle for dict.

@wyli wyli mentioned this pull request Aug 26, 2021
5 tasks
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.

3 participants