Skip to content

torch transforms - RandRicianNoise, StdShiftIntensity, RandStdShiftIntensity#2815

Merged
wyli merged 9 commits intoProject-MONAI:devfrom
rijobro:intensity_torch_transforms_1
Aug 23, 2021
Merged

torch transforms - RandRicianNoise, StdShiftIntensity, RandStdShiftIntensity#2815
wyli merged 9 commits intoProject-MONAI:devfrom
rijobro:intensity_torch_transforms_1

Conversation

@rijobro
Copy link
Copy Markdown
Contributor

@rijobro rijobro commented Aug 20, 2021

Description

torch transforms - RandRicianNoise, StdShiftIntensity, RandStdShiftIntensity

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 rijobro requested review from Nic-Ma and wyli August 20, 2021 14:57
@rijobro
Copy link
Copy Markdown
Contributor Author

rijobro commented Aug 20, 2021

@wyli I continue to be hampered by the NdarrayTensor problem. Could we come up with a solution that doesn't require # type: ignore all over the place? There's not much point in type checking if we then have to use lots of ignores.

FYI, NdarrayTensor = Union[np.ndarray, torch.Tensor] would work for me. Although I'm sure it would break things elsewhere.

Signed-off-by: Richard Brown <[email protected]>
@wyli
Copy link
Copy Markdown
Contributor

wyli commented Aug 20, 2021

@wyli I continue to be hampered by the NdarrayTensor problem. Could we come up with a solution that doesn't require # type: ignore all over the place? There's not much point in type checking if we then have to use lots of ignores.

FYI, NdarrayTensor = Union[np.ndarray, torch.Tensor] would work for me. Although I'm sure it would break things elsewhere.

for now perhaps in the new feature, we don't include any typing annotations, we can gradually add them later with non-breaking pull requests.

@wyli
Copy link
Copy Markdown
Contributor

wyli commented Aug 21, 2021

/build

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.

Looks good to me except for some minor comments.
@wyli Do you have any other comments?

Thanks.


slices = (img != 0) if self.nonzero else ones(img.shape, dtype=bool)
if slices.any():
out = deepcopy(img)
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.

I think our transforms are in-place operation, no need to deepcopy?

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.

@Nic-Ma @wyli are we sure about the in-placeness of the transforms? When I deleted the deepcopy, i needed to modify the unit tests for them to pass - 2431dba.

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.

you're right, looks like a bug here, this astype will copy if the datatypes doesn't match, if that happens it's not an in-place operation

img = img.astype(self.dtype)

@rijobro
Copy link
Copy Markdown
Contributor Author

rijobro commented Aug 23, 2021

@wyli temporarily using NdarrayTensorUnion = Union[np.ndarray, torch.Tensor]. Happy to revert in the future once we find a solution.

@wyli
Copy link
Copy Markdown
Contributor

wyli commented Aug 23, 2021

/build

Signed-off-by: Richard Brown <[email protected]>
@rijobro
Copy link
Copy Markdown
Contributor Author

rijobro commented Aug 23, 2021

Thanks @Nic-Ma , updated for both those suggestions.

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]>
@wyli
Copy link
Copy Markdown
Contributor

wyli commented Aug 23, 2021

/build

@rijobro rijobro mentioned this pull request Aug 23, 2021
4 tasks
@wyli wyli enabled auto-merge (squash) August 23, 2021 17:28
@wyli wyli merged commit 93d467d into Project-MONAI:dev Aug 23, 2021
@rijobro rijobro deleted the intensity_torch_transforms_1 branch August 24, 2021 08:26
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