-
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
Compose caching #7131
Compose caching #7131
Conversation
Signed-off-by: Ben Murray <[email protected]>
Signed-off-by: Ben Murray <[email protected]>
…ons needing to be aware of additional arguments on func Signed-off-by: Ben Murray <[email protected]>
Signed-off-by: Ben Murray <[email protected]>
Signed-off-by: Ben Murray <[email protected]>
Signed-off-by: Ben Murray <[email protected]>
Signed-off-by: Ben Murray <[email protected]>
for more information, see https://pre-commit.ci
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.
Code looks good on a glance. Are the preceding commits related to this fix?
Thanks for taking a look! |
@@ -334,6 +334,18 @@ def __call__(self, input_, start=0, end=None, threading=False, lazy: bool | None | |||
|
|||
return result | |||
|
|||
def is_random(self): |
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.
Thanks for the PR!
Do we have another special reason to add this is_random
function?
Looks like we could directly use this flatten
function in the CacheDataset
, it can also apply to nested compose. Do you have concerns about this easy solution?
MONAI/monai/transforms/compose.py
Line 313 in 8a70678
def flatten(self): |
Line 808 in 8a70678
super().__init__(data=data, transform=transform) |
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'm not super happy with is_random
; it is just an initial attempt to solve the problem. I've thought about it over the weekend and if I can avoid introducing is_random
then I'll get rid of it. In particular, if we always iterate into Compose objects, we don't need a check to determine whether the Compose object contains only provably deterministic transforms.
flatten
has its own problems in that it isn't a complete mechanism and it produces a physically flattened set of transforms. I'm prepping another commit that iterates over transforms without flattening them and returns an index instead. This could then be used in the flatten
implementation internally where people really need it, but I think an iterator that knows how to visit transforms is cleaner
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 think this has also exposed a potential issue with the relationship between Compose
and OneOf
, SomeOf
, RandomOrder
. The latter three are always random and shouldn't be iterated into when trying to find the last deterministic transform, whereas Compose really is just a container and its randomness depends on its contents.
Ok. I think I have a clean solution. I'm just testing it, then I'll either wrap up this PR and create a new one or I'll continue with this one. Essentially, the iterative approach can replace the physical flattening quite nicely. This is good because we don't flatten the transforms when we execute the Compose pipeline but we do effective execute in a nested way. The solution is to modify execute_compose to be able to perform the iteration itself without flattening the data. The solution doesn't need is_random, although we might want to keep it (or something like it) so we don't have to keep a list of subclasses of Compose that we don't iterate into. |
Fixes #7130
Description
This is still a work in progress and a focus point for the discussion on #7130. At present, it provides an initial solution that only
solves the Compose always being treated as random part of the solution, but doesn't yet allow nested Composes to be iterated into.
So far, this implementation provides a solution to the issue where Compose is always treated as random.
Types of changes
./runtests.sh -f -u --net --coverage
../runtests.sh --quick --unittests --disttests
.make html
command in thedocs/
folder.