-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Lazy eval refactor #6257
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
Closed
Closed
Lazy eval refactor #6257
Changes from all commits
Commits
Show all changes
141 commits
Select commit
Hold shift + click to select a range
06d5842
Initial commit
atbenmurray 2507a0b
Refactors and simplification of api / calls
atbenmurray 56b618e
Refactoring functional spatial transform to support lazy_evaluation p…
atbenmurray 315e5b7
Making lazy_evaluation parameter consistent across spatial array lazy…
atbenmurray 4e69313
Updating apply and dictionary spatial transforms to support
atbenmurray 99fa35b
Missing changes to spatial dictionary
atbenmurray a798e0e
Enable call-time overriding of lazy_evaluation in croppad/functional and
atbenmurray 114b8cc
Updating croppad dictionary and croppad array for call-time laziness
atbenmurray 5df4261
Fix for push_transform; updating the lazy integration test
atbenmurray 84d65f7
removing issue.txt
atbenmurray 7ec442f
. Renaming apply_transform to apply_pending as it is more semantically
atbenmurray 8f62776
Tweaked array ApplyPending and ApplyPendingd for array and dict data
atbenmurray 2492223
Added missing license text.
atbenmurray 0064326
Missing import for apply_pending
atbenmurray 0646602
Merge branch 'dev' into lazy_eval_refactor
atbenmurray 05eb3f9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 788cd74
Fixing syntax error created by merge of dev to PR
atbenmurray 4bd22f8
Fixing issues with pad_func post merge
atbenmurray 1e0510c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] c36b69f
Fixing issues in crop while running unit tests
atbenmurray 8a4f310
Merge branch 'lazy_eval_refactor' of github.com:atbenmurray/monai int…
atbenmurray 3c69776
Fixing issues with OneOf/SomeOf/RandomOrder after dev merge
atbenmurray 6b94aa1
More croppad fixes post dev merge
atbenmurray bf1c01a
Fixing test_nvtx_decorator after def merge
atbenmurray 19745f9
Removed use of **kwargs parameter in tests as it isn't supported by a…
atbenmurray b219f13
Setting use of lazy_evaluation to False for Rand2D/Rand3DElastic
atbenmurray 6af8f24
Fixed test_spatial_pad
atbenmurray 173c161
Renaming lazy_evaluation to lazy
atbenmurray 2262ba9
Fixed all outstanding usages of apply_pending in tests. Removed the
atbenmurray aaaea13
Merge branch 'dev' into lazy_eval_refactor
atbenmurray 088d14e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 3e6a637
Accepting formatting auto-fixes
atbenmurray 98a53bf
Renaming surviving lazy_evaluation instances to lazy.
atbenmurray 28a0175
Renamed the last errant 'lazy_evaluation' instances to 'lazy'
atbenmurray 4e9b6c6
Fixing ruff errors for over-long line lengths
atbenmurray ad23bea
Fix for issue when the 'lazy' property is set to None
atbenmurray 81549e2
Fix for _apply_transform when lazy is None, post merge tidy up
atbenmurray 77eff5b
Removing the redundant check for log_stats from
atbenmurray 7c53d26
Further formatting auto-fixes
atbenmurray ee5378f
Making default for overrides be None instead of {}.
atbenmurray 28c05d0
Changed execute_pending_transforms to not make a shallow copy of dict…
atbenmurray d96fef0
Fixing docstring for Compose
atbenmurray 654cf48
Fixing type complaints
atbenmurray 64ec242
Fix for tests/tests_integration_lazy_samples. The modified lazy
atbenmurray f38eb9b
Flake8 fix
atbenmurray 14349ff
Flake8 fixes
atbenmurray 51fda45
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] c5742c0
Autoformat style fixes
atbenmurray ef5173e
Merge branch 'lazy_eval_refactor' of github.com:atbenmurray/monai int…
atbenmurray 916b0a9
Fixing bug introduced by flake8 fix
atbenmurray 20c1cfc
Merge branch 'dev' into lazy_eval_refactor
atbenmurray c94341f
Removal of obsolete lazy eval code
atbenmurray cc51f2f
Autoformat shuffle
atbenmurray 06aad01
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 3ae46e9
Resolving mypy issues
atbenmurray 95a6a5f
Merge branch 'lazy_eval_refactor' of github.com:atbenmurray/monai int…
atbenmurray 81559fa
Finally got to grips with mypy troubles
atbenmurray af9cad1
Final mypy complaints
atbenmurray a9c8849
Chasing autofixes again
atbenmurray aadbae3
test_invert_warn_pending is now obsolete due to this no longer being an
atbenmurray 1cccf9b
Adding documentation for ApplyPending/ApplyPendingd. Adding more
atbenmurray 9ae1140
More autofix
atbenmurray bb2ad0f
Restoring lazy.setters for croppad and spatial lazy transforms
atbenmurray 5abe294
Undoing the previous commit until I get to the bottom of the randaffined
atbenmurray c2bf4a7
Making apis for OneOf/SomeOf/RandomOrder consistent with Compose
atbenmurray b16a87f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 816666e
Removing partial docstring for 'lazy', which isn't on the init parameter
atbenmurray 8318121
Merge branch 'lazy_eval_refactor' of github.com:atbenmurray/monai int…
atbenmurray 0e10c24
Adding execute_pending_transforms to lazy/functional __all__
atbenmurray f323ff9
Removing LazyMode; lazy is now True / False / None
atbenmurray 4b69ec6
Renamed execute_pending_transforms to apply_pending_transforms.
atbenmurray 29ce2b7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 6774aaa
Removed "LazyMode" from enums.py __all__
atbenmurray de5b9b8
Merge branch 'lazy_eval_refactor' of github.com:atbenmurray/monai int…
atbenmurray 1c7d172
Modified ApplyPending/ApplyPendingd in the light of the override issue
atbenmurray bb22c13
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2159ce8
Correction to type info for execute_compose lazy parameter.
atbenmurray 2c3172d
Removal of comment in docstring about IdentityD being used to cause
atbenmurray bb1214c
Merge branch 'lazy_eval_refactor' of github.com:atbenmurray/monai int…
atbenmurray 5a7820c
Logging refactored with pending pipeline logging enabled
atbenmurray 503db85
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 1af35fd
All logging_names are now None by default to prevent massive spam in
atbenmurray 75771a8
Merge branch 'lazy_eval_refactor' of github.com:atbenmurray/monai int…
atbenmurray d97095a
Merge branch 'dev' into lazy_eval_refactor
atbenmurray af6cd62
More autofixes
atbenmurray cd246a8
Merge branch 'lazy_eval_refactor' of github.com:atbenmurray/monai int…
atbenmurray 1403d77
Making apply_transform logger_name None by default
atbenmurray 5c4c10a
Added a dictionary test to the compose logging test suite
atbenmurray 5755a65
Updated docstring for _apply_transform
atbenmurray ca0905a
Removed spurious empty string at the end of one of the logging test case
atbenmurray e8fdf5a
All spatial transforms now initialize LazyTransform correctly
atbenmurray 70d3517
Adding setters for lazy back in.
atbenmurray b361a13
Merge branch 'dev' into lazy_eval_refactor
atbenmurray a6ad51e
Sorting out line length complaint in compose logging tests
atbenmurray 7ec8429
Merge branch 'lazy_eval_refactor' of github.com:atbenmurray/monai int…
atbenmurray 305b88e
Fix for old lazy_evaluation name creeping in during merge
atbenmurray 2aa0ada
Autofix
atbenmurray 7b092ca
Merge branch 'Project-MONAI:dev' into lazy_eval_refactor
atbenmurray 62431ff
Using get_logger so that named loggers all get set up correctly
atbenmurray 6cdf4c6
Merge branch 'lazy_eval_refactor' of github.com:atbenmurray/monai int…
atbenmurray 2ea89c1
Fixes for logging; additional compose logging tests; missing imports
atbenmurray 628a7f8
Adding ApplyPending and ApplyPendingd to transforms.rst
atbenmurray 5b34755
Fixed transforms.rst modifications
atbenmurray d547b81
Refactor of lazy to provide in_order and out_of_order lazy execution
atbenmurray 03386dc
Merge branch 'lazy_eval_refactor' of github.com:atbenmurray/monai int…
atbenmurray d2fa521
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] eb641c6
Tidied up __all__ issues caused by refactor
atbenmurray d7d7cdb
Merge branch 'lazy_eval_refactor' of github.com:atbenmurray/monai int…
atbenmurray 29b37bf
Removed can_invert flag from compose compiler policy
atbenmurray 3194980
Moved to use of a TraceKey.STATUS flag. This can be used to track
atbenmurray 5ff516d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] eebb3de
Formatting autofixes
atbenmurray d966856
Merge branch 'lazy_eval_refactor' of github.com:atbenmurray/monai int…
atbenmurray e39e0a3
Lazy {reorder: lazy_last_nosync} now passes
atbenmurray cf58b9f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 883f8c5
Fixed broken call to isinstance in lazy executors
atbenmurray e81f359
Autofix
atbenmurray db1486b
Resolving lint issue
atbenmurray b151607
Missing passing logger_name through to _apply_transform when mapping …
atbenmurray 24286f1
Autofix
atbenmurray 43f7bc0
Added missing lazy=None option from integration tests for lazy
atbenmurray b217dbe
Autofix
atbenmurray ed1d952
Fixing lint issues
atbenmurray e7f3a07
Autofixes
atbenmurray 0751c52
lint fix
atbenmurray 6114a67
started on the lazy resampling topic page
atbenmurray 240059b
Merge branch 'lazy_eval_refactor' of github.com:atbenmurray/monai int…
atbenmurray 23ff89c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5e1b81d
Removing unused Sequence import from lazy/executors
atbenmurray 5dd6113
Renaming ComposeCompiler to ExecuteOptions in test_compose
atbenmurray 74bed34
Update tests/test_compose.py
atbenmurray 76e4b85
Execution options is no longer a poltergeist. Refactored is_tensor_in…
atbenmurray 1c4fa6c
Merge branch 'lazy_eval_refactor' of github.com:atbenmurray/monai int…
atbenmurray 8dde40d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 7fd32e2
Removing unnecessary active_key property
atbenmurray 10d95ce
Merge branch 'lazy_eval_refactor' of github.com:atbenmurray/monai int…
atbenmurray 0d6a847
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 1ceeb1a
Fix for multi-sampled data for transforms that aceept *args; refactor…
atbenmurray 38bdef6
Merge branch 'lazy_eval_refactor' of github.com:atbenmurray/monai int…
atbenmurray 6e0cfd9
Renaming LazyTrait partially_lazy -> checks_data
atbenmurray f2fb06a
Merge branch 'Project-MONAI:dev' into lazy_eval_refactor
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 hidden or 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,104 @@ | ||
:github_url: https://github.com/Project-MONAI/MONAI | ||
|
||
Lazy Resampling | ||
=============== | ||
|
||
.. toctree:: | ||
: maxdepth: 2 | ||
|
||
mb_specification | ||
config_syntax.md | ||
|
||
Introduction | ||
^^^^^^^^^^^^ | ||
|
||
Lazy Resampling is a new feature for MONAI 1.2. This feature is still experimental at this time and it is possible that | ||
behaviour and APIs will change in upcoming releases. | ||
|
||
Lazy resampling is a feature that can be used to improve preprocessing pipelines in the following ways: | ||
* it can improve pipeline execution time | ||
* it can improve pipeline memory usage | ||
* it can improve image and segmentation quality by reducing incidental noise caused by resampling | ||
|
||
How Lazy Resampling changes preprocessing | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
In order to understand how lazy resampling changes preprocessing, we'll first discuss standard processing pipeline | ||
behaviour, and then compare it with the way lazy resampling works. | ||
|
||
Traditional resampling pipelines | ||
++++++++++++++++++++++++++++++++ | ||
|
||
With traditional resampling, found both in MONAI and many other preprocessing libraries, you typically define a sequence | ||
of transforms and pass them to a ``Compose`` object, such as `monai.transforms.compose.Compose`_. | ||
|
||
Example:: | ||
|
||
transforms = [ | ||
LoadImaged(keys=["img", "seg"], ...), | ||
EnsureChannelFirstd(keys=["img", "seg"], ...), | ||
Spacingd(keys=["img", "seg"], ...), | ||
Orientationd(keys=["img", "seg"], ...), | ||
RandSpatialCropd(keys=["img", "seg"], ...), | ||
RandRotate90d(keys=["img", "seg"], ...), | ||
RandRotated(keys=["img", "seg"], ...), | ||
RandZoomd(keys=["img", "seg"], ...), | ||
RandGaussianNoised(keys="img", ...), | ||
] | ||
compose = Compose(transforms) | ||
|
||
# elsewhere this will be called many times (such as in a Dataset instance) | ||
outputs = compose(inputs) | ||
:: | ||
|
||
The following will then happen when we call ``compose(inputs)``: | ||
|
||
1. ``LoadImaged`` is called with its inputs (a dictionary of strings containing file locations). This loads and | ||
returns a dictionary of the corresponding data samples | ||
2. ``EnsureChannelFirstd`` is called with the dictionary of data samples and adds a channel so that they have the | ||
appropriate shape for the rest of the pipeline | ||
3. ``Spacingd`` is called and reinterpolates the data samples | ||
4. ``Orientationd`` permutes the data samples so that their spatial dimensions are reorganised | ||
5. ``RandSpatialCropd`` crops a random patch of the data samples, throwing away the rest of the data in the process | ||
6. ``RandRotate90d`` has a chance of performing a tensor-based rotation of the data samples | ||
7. ``RandRotated`` has a chance of performing a full resample of the data samples | ||
8. ``RandZoomd`` has a chance of performing a reinterpolation of the data samples | ||
9. ``RandGaussianNoised`` has a chance of adding noise to ``img`` | ||
|
||
Overall, there are up to three occasions where the data is either interpolated or resampled through spatial transforms. | ||
Furthermore, the crop that occurs means that the output data samples might contain pixels for which there is data but | ||
that show padding values, because the data was thrown away by ``RandSpatialCrop``. | ||
|
||
Each of these operations takes time and memory, but, as we can see in the example above, also creates resampling | ||
artifacts and can even destroy data in the resulting data samples (see `lazy resampling best practices`_ for examples). | ||
|
||
Lazy resampling pipelines | ||
^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
Lazy resampling works very differently. When you execute the same pipeline with `lazy=True`, the following happens: | ||
|
||
1. ``LoadImaged`` behaves identically | ||
2. ``EnsureChannelFirstd`` behaves identically | ||
3. ``Spacingd`` is executing lazily. It puts a description of the operation that it wants to perform onto a list of | ||
pending operations | ||
4. ``Orientationd`` is executing lazily. It adds a description of its own operation to the pending operation list so | ||
now there are 2 pending operations | ||
5. ``RandSpatialCropd`` is executing lazily. It adds a description of its own operation to the pending operation list | ||
so now there are 3 pending operations | ||
6. ``RandRotate90d`` is executing lazily. It adds a description of its own operation to the pending operation list | ||
so now there are 4 pending operations | ||
7. ``RandRotated`` is executing lazily. It adds a description of its own operation to the pending operation list | ||
so now there are 5 pending operations | ||
8. ``RandZoomd`` is executing lazily. It adds a description of its own operation to the pending operation list | ||
so now there are 6 pending operations | ||
1. ``[Spacingd, Orientationd, RandSpatialCropd, RandRotate90d, RandRotated, RandZoomd]`` are all on the pending | ||
operations list but have yet to be carried out on the data | ||
9. ``RandGaussianNoised`` is not a lazy transform. It is now time for the pending operations to be evaluated. Their | ||
descriptions are mathematically composited together, to determine the operation that results from all of them | ||
being carried out. This is then applied in a single resample operation. Once that is done, ``RandGaussianNoised`` | ||
operates on the resulting data | ||
|
||
The single resampling operation has less noise induced by resampling, as it only occurs once in this pipeline rather | ||
than three times in the traditional pipeline. More importantly, although the crop describes an operation to keep only a | ||
subset of the data sample, the crop is not performed until after the spatial transforms are completed, which means that | ||
all of the data sample that is within bounds is preserved and is part of the resulting output. |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.