-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
RandomizableTransformType, LazyTransformType, and MultiSampleTransformType #5410
Closed
Closed
Changes from 3 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7352656
Implementation of IRandomizableTransform, ILazyTransform and IMultiSa…
atbenmurray e144315
Adding license text
atbenmurray d1010a4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2b23a90
Adding entries to docs; removing obsolete import from irandomizabletr…
atbenmurray 1665f10
Fixing merge conflict in irandomizabletransform test
atbenmurray 6d2f4fb
Adding interfaces to transforms/__init__.py
atbenmurray 8925e3e
5414 size/size() for metatensor compatibility (#5415)
wyli 4d2c988
Renaming interface types after feedback
atbenmurray 54f2ff3
Updating test class / method names to reflect name change to Randomiz…
atbenmurray af78ebd
Accepting autoformatting fixes
atbenmurray 247ab4e
Updating docs with revised type names
atbenmurray c0a3ff6
Implementation of IRandomizableTransform, ILazyTransform and IMultiSa…
atbenmurray a7b2fd9
Merge branch 'lr_interfaces' of github.com:project-monai/monai into l…
atbenmurray e2ba99f
Implementation of IRandomizableTransform, ILazyTransform and IMultiSa…
atbenmurray ad62067
Merge branch 'lr_interfaces' of github.com:project-monai/monai into l…
atbenmurray File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright (c) MONAI Consortium | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import unittest | ||
|
||
|
||
from monai.transforms.transform import IRandomizableTransform, RandomizableTransform | ||
|
||
|
||
class InheritsInterface(IRandomizableTransform): | ||
pass | ||
|
||
|
||
class InheritsImplementation(RandomizableTransform): | ||
|
||
def __call__(self, data): | ||
return data | ||
|
||
|
||
class TestIRandomizableTransform(unittest.TestCase): | ||
|
||
def test_is_irandomizable(self): | ||
inst = InheritsInterface() | ||
self.assertIsInstance(inst, IRandomizableTransform) | ||
|
||
def test_set_random_state_default_impl(self): | ||
inst = InheritsInterface() | ||
with self.assertRaises(TypeError): | ||
inst.set_random_state(seed=0) | ||
|
||
def test_set_random_state_randomizable_transform(self): | ||
inst = InheritsImplementation() | ||
inst.set_random_state(0) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that we need
IMultiSampleTransform
, but I'm not sure aboutIRandomizableTransform
orILazyTransform
, these are not required concepts at the moment according to the prototypes... I can redirect my PR (#5407) to your fork if that addresses any potential merging conflictsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you look at the dictionary transform implementations on #4922, they make use of IRandomizableTransform.
The point of IRandomizableTransform is twofold:
The addition of this interface is partially motivated by the way I've implemented RandRotated in the big PR #4922 .
MONAI/monai/transforms/atmostonce/dictionary.py
Line 174 in 62f8172
I might have gone too far in creating a separate Randomizer class that can be reused across the dictionary and array implementations, but I think it results in pretty clean code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, that looks like another refactoring effort introducing new concepts of
Randomizer
andIRandomizableTransform
... how about we limit the scope for lazy resampling feature, and all the other nice-to-have features stay on a feature branch for now?really hope we can ship the lazy resampling soon. The other refactorings add much risks but at the moment they are not critical from a user experience's perspective...