Skip to content

Conversation

@rijobro
Copy link
Contributor

@rijobro rijobro commented Feb 25, 2021

Adds randomizable constructor.

Description

This allows the parent class to store prob and _do_transform.

I'll need this for the inverse transformation PR.
#1515

Status

Ready

Signed-off-by: Richard Brown <33289025+rijobro@users.noreply.github.com>
Signed-off-by: Richard Brown <33289025+rijobro@users.noreply.github.com>
Signed-off-by: Richard Brown <33289025+rijobro@users.noreply.github.com>
Signed-off-by: Richard Brown <33289025+rijobro@users.noreply.github.com>
…ctor

Signed-off-by: Richard Brown <33289025+rijobro@users.noreply.github.com>
Signed-off-by: Richard Brown <33289025+rijobro@users.noreply.github.com>
Signed-off-by: Richard Brown <33289025+rijobro@users.noreply.github.com>
Signed-off-by: Richard Brown <33289025+rijobro@users.noreply.github.com>
Signed-off-by: Richard Brown <33289025+rijobro@users.noreply.github.com>
Signed-off-by: Richard Brown <33289025+rijobro@users.noreply.github.com>
…ctor

Signed-off-by: Richard Brown <33289025+rijobro@users.noreply.github.com>
@rijobro
Copy link
Contributor Author

rijobro commented Feb 26, 2021

@wyli any chance you could have a look at this? Hoping to get it merged so I can move onto the next set of PRs.

@rijobro rijobro requested a review from wyli February 26, 2021 09:56
Signed-off-by: Richard Brown <33289025+rijobro@users.noreply.github.com>
@wyli
Copy link
Contributor

wyli commented Feb 26, 2021

@wyli any chance you could have a look at this? Hoping to get it merged so I can move onto the next set of PRs.

thanks I'll need more time to check the details as there's no unit test to cover the changes...

Randomizable is a general one, for example it's also used for shuffling the dataset https://github.com/Project-MONAI/MONAI/blob/master/monai/apps/datasets.py#L136 perhaps we could subclass it for the randomised transforms?

@rijobro
Copy link
Contributor Author

rijobro commented Feb 26, 2021

thanks I'll need more time to check the details as there's no unit test to cover the changes...

Sure, my metric was just that none of the previous unit tests were broken. Slightly worrying that the code format wasn't picking up any warnings with this one... https://github.com/Project-MONAI/MONAI/blob/master/monai/apps/datasets.py#L136

EDIT: oh, it's because it doesn't call the base class.

Signed-off-by: Richard Brown <33289025+rijobro@users.noreply.github.com>
@rijobro rijobro force-pushed the randomizable_constructor branch from e9b7b81 to 9edb551 Compare February 26, 2021 11:16
Signed-off-by: Richard Brown <33289025+rijobro@users.noreply.github.com>
Signed-off-by: Richard Brown <33289025+rijobro@users.noreply.github.com>
Signed-off-by: Richard Brown <33289025+rijobro@users.noreply.github.com>
@rijobro
Copy link
Contributor Author

rijobro commented Feb 26, 2021

@wyli updated to add a RandomizableTransform class.

@wyli
Copy link
Contributor

wyli commented Feb 26, 2021

/integration-test

@rijobro rijobro enabled auto-merge (squash) February 26, 2021 13:05
Copy link
Contributor

@wyli wyli left a comment

Choose a reason for hiding this comment

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

thanks, it looks good to me

return self

@abstractmethod
def randomize(self, data: Any) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

shall we support None here and in the RandomizableTransform? (if it doesn't break anything...)

Suggested change
def randomize(self, data: Any) -> None:
def randomize(self, data: Optional[Any] = None) -> None:

Copy link
Contributor Author

@rijobro rijobro Feb 26, 2021

Choose a reason for hiding this comment

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

I shouldn't have enabled automatic merging!

I would quite like the default of data for Randomizable and RandomizableTransform to default to None. Currently I have to use a lot of super().randomize(None), but I'd rather have super().randomize().

However, this is incompatible with certain child classes. E.g., RandFlip takes np.ndarray as argument, which is incompatible with None.

The alternative is to switch all child classes from e.g., np.ndarray to Optional[np.ndarray], but that doesn't make sense either, because the np.ndarray in this case isn't optional.

Another alternative is just to ignore the mypy errors for those classes.

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks! it's just a very minor issue, I think the current one is also good, I forgot the mypy errors...

@rijobro rijobro merged commit 1df6352 into Project-MONAI:master Feb 26, 2021
@rijobro rijobro deleted the randomizable_constructor branch February 26, 2021 13:29
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