Skip to content
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

4855 lazy resampling impl -- Compose #5860

Merged
merged 286 commits into from
Mar 23, 2023

Conversation

wyli
Copy link
Contributor

@wyli wyli commented Jan 17, 2023

part of #4855

upgrade #4911 to use the latest dev API

Description

e.g., for a sequence of spatial transforms

xforms = [
    mt.LoadImageD(keys, ensure_channel_first=True),
    mt.Orientationd(keys, "RAS"),
    mt.SpacingD(keys, (1.5, 1.5, 1.5)),
    mt.CenterScaleCropD(keys, roi_scale=0.9),
    # mt.CropForegroundD(keys, source_key="seg", k_divisible=5),
    mt.RandRotateD(keys, prob=1.0, range_y=np.pi / 2, range_x=np.pi / 3),
    mt.RandSpatialCropD(keys, roi_size=(76, 87, 73)),
    mt.RandScaleCropD(keys, roi_scale=0.9),
    mt.Resized(keys, (30, 40, 60)),
    # mt.NormalizeIntensityd(keys),
    mt.ZoomD(keys, 1.3, keep_size=False),
    mt.FlipD(keys),
    mt.Rotate90D(keys),
    mt.RandAffined(keys),
    mt.ResizeWithPadOrCropd(keys, spatial_size=(32, 43, 54)),
    mt.DivisiblePadD(keys, k=3),
]
lazy_kwargs = dict(mode=("bilinear", 0), padding_mode=("border", "nearest"), dtype=(torch.float32, torch.uint8))
xform = mt.Compose(xforms, lazy_evaluation=True, overrides=lazy_kwargs, override_keys=keys)
xform.set_random_state(0)

lazy_evaluation=True preserves more details
Screenshot 2023-01-17 at 00 31 40
compared with the regular compose
Screenshot 2023-01-17 at 00 31 43

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • Breaking change (fix or new feature that would cause existing functionality to change).
  • 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 --disttests.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

@wyli wyli force-pushed the 4855-lazy-resampling-impl branch from 690d075 to bd21ea0 Compare January 17, 2023 15:24
@wyli wyli force-pushed the 4855-lazy-resampling-impl branch 3 times, most recently from 5e58297 to 42844e8 Compare January 24, 2023 00:38
wyli added 9 commits January 25, 2023 16:01
Signed-off-by: Wenqi Li <[email protected]>
Signed-off-by: Wenqi Li <[email protected]>
Signed-off-by: Wenqi Li <[email protected]>
Signed-off-by: Wenqi Li <[email protected]>
Signed-off-by: Wenqi Li <[email protected]>
Signed-off-by: Wenqi Li <[email protected]>
Signed-off-by: Wenqi Li <[email protected]>
Signed-off-by: Wenqi Li <[email protected]>
@wyli wyli force-pushed the 4855-lazy-resampling-impl branch from 45631e0 to 1232a6b Compare January 25, 2023 18:38
Signed-off-by: Wenqi Li <[email protected]>
@wyli wyli force-pushed the 4855-lazy-resampling-impl branch from 1232a6b to aa0389e Compare January 25, 2023 18:51
wyli added 3 commits January 25, 2023 21:08
@wyli wyli force-pushed the 4855-lazy-resampling-impl branch from 9790148 to fce044b Compare January 26, 2023 00:52
@atbenmurray atbenmurray mentioned this pull request Mar 22, 2023
7 tasks
monai/transforms/compose.py Outdated Show resolved Hide resolved
Copy link
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, looking forward to more tests and some bundle benchmarks before merging.

Thanks.

monai/transforms/lazy/functional.py Outdated Show resolved Hide resolved
tests/test_integration_lazy_samples.py Outdated Show resolved Hide resolved
monai/transforms/compose.py Outdated Show resolved Hide resolved
@wyli
Copy link
Contributor Author

wyli commented Mar 23, 2023

thanks, I'm working on this branch to address the review comments.

@atbenmurray
Copy link
Contributor

thanks, I'm working on this branch to address the review comments.

Ahh, @wyli I was in the process of adding the missing keywords to the overrides namespace, but if you are already doing it I'll leave it

@wyli
Copy link
Contributor Author

wyli commented Mar 23, 2023

thanks, I'm working on this branch to address the review comments.

Ahh, @wyli I was in the process of adding the missing keywords to the overrides namespace, but if you are already doing it I'll leave it

sure, I'll make minor usability fixes and merge it soon..

wyli and others added 7 commits March 23, 2023 14:22
@wyli
Copy link
Contributor Author

wyli commented Mar 23, 2023

/build

@wyli wyli enabled auto-merge (squash) March 23, 2023 18:17
Signed-off-by: Wenqi Li <[email protected]>
@wyli
Copy link
Contributor Author

wyli commented Mar 23, 2023

/build

@wyli wyli disabled auto-merge March 23, 2023 18:30
@wyli wyli changed the title 4855 lazy resampling impl 4855 lazy resampling impl -- Compose Mar 23, 2023
@wyli wyli merged commit b87375f into Project-MONAI:dev Mar 23, 2023
jak0bw pushed a commit to jak0bw/MONAI that referenced this pull request Mar 28, 2023
part of Project-MONAI#4855

upgrade Project-MONAI#4911 to use the
latest dev API

### Description
Example usage:

for a sequence of spatial transforms

```py
xforms = [
    mt.LoadImageD(keys, ensure_channel_first=True),
    mt.Orientationd(keys, "RAS"),
    mt.SpacingD(keys, (1.5, 1.5, 1.5)),
    mt.CenterScaleCropD(keys, roi_scale=0.9),
    # mt.CropForegroundD(keys, source_key="seg", k_divisible=5),
    mt.RandRotateD(keys, prob=1.0, range_y=np.pi / 2, range_x=np.pi / 3),
    mt.RandSpatialCropD(keys, roi_size=(76, 87, 73)),
    mt.RandScaleCropD(keys, roi_scale=0.9),
    mt.Resized(keys, (30, 40, 60)),
    # mt.NormalizeIntensityd(keys),
    mt.ZoomD(keys, 1.3, keep_size=False),
    mt.FlipD(keys),
    mt.Rotate90D(keys),
    mt.RandAffined(keys),
    mt.ResizeWithPadOrCropd(keys, spatial_size=(32, 43, 54)),
    mt.DivisiblePadD(keys, k=3),
]
lazy_kwargs = dict(mode=("bilinear", 0), padding_mode=("border", "nearest"), dtype=(torch.float32, torch.uint8))
xform = mt.Compose(xforms, lazy_evaluation=True, overrides=lazy_kwargs, override_keys=keys)
xform.set_random_state(0)
```
lazy_evaluation=True preserves more details
![Screenshot 2023-01-17 at 00 31
40](https://user-images.githubusercontent.com/831580/212784981-ea39833b-54ab-42fb-bc03-38b012281857.png)
compared with the regular compose
![Screenshot 2023-01-17 at 00 31
43](https://user-images.githubusercontent.com/831580/212785016-ba3be8ff-f17f-47b4-8025-cd351a637a82.png)



### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [ ] Breaking change (fix or new feature that would cause existing
functionality to change).
- [ ] 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 --disttests`.
- [ ] In-line docstrings updated.
- [ ] Documentation updated, tested `make html` command in the `docs/`
folder.

---------

Signed-off-by: Wenqi Li <[email protected]>
Signed-off-by: Yiheng Wang <[email protected]>
Signed-off-by: KumoLiu <[email protected]>
Signed-off-by: Ben Murray <[email protected]>
Co-authored-by: Ben Murray <[email protected]>
Co-authored-by: binliu <[email protected]>
Co-authored-by: Yiheng Wang <[email protected]>
Co-authored-by: YunLiu <[email protected]>
Co-authored-by: Yiheng Wang <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: KumoLiu <[email protected]>
jak0bw pushed a commit to jak0bw/MONAI that referenced this pull request Mar 28, 2023
part of Project-MONAI#4855

upgrade Project-MONAI#4911 to use the
latest dev API

### Description
Example usage:

for a sequence of spatial transforms

```py
xforms = [
    mt.LoadImageD(keys, ensure_channel_first=True),
    mt.Orientationd(keys, "RAS"),
    mt.SpacingD(keys, (1.5, 1.5, 1.5)),
    mt.CenterScaleCropD(keys, roi_scale=0.9),
    # mt.CropForegroundD(keys, source_key="seg", k_divisible=5),
    mt.RandRotateD(keys, prob=1.0, range_y=np.pi / 2, range_x=np.pi / 3),
    mt.RandSpatialCropD(keys, roi_size=(76, 87, 73)),
    mt.RandScaleCropD(keys, roi_scale=0.9),
    mt.Resized(keys, (30, 40, 60)),
    # mt.NormalizeIntensityd(keys),
    mt.ZoomD(keys, 1.3, keep_size=False),
    mt.FlipD(keys),
    mt.Rotate90D(keys),
    mt.RandAffined(keys),
    mt.ResizeWithPadOrCropd(keys, spatial_size=(32, 43, 54)),
    mt.DivisiblePadD(keys, k=3),
]
lazy_kwargs = dict(mode=("bilinear", 0), padding_mode=("border", "nearest"), dtype=(torch.float32, torch.uint8))
xform = mt.Compose(xforms, lazy_evaluation=True, overrides=lazy_kwargs, override_keys=keys)
xform.set_random_state(0)
```
lazy_evaluation=True preserves more details
![Screenshot 2023-01-17 at 00 31
40](https://user-images.githubusercontent.com/831580/212784981-ea39833b-54ab-42fb-bc03-38b012281857.png)
compared with the regular compose
![Screenshot 2023-01-17 at 00 31
43](https://user-images.githubusercontent.com/831580/212785016-ba3be8ff-f17f-47b4-8025-cd351a637a82.png)



### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [ ] Breaking change (fix or new feature that would cause existing
functionality to change).
- [ ] 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 --disttests`.
- [ ] In-line docstrings updated.
- [ ] Documentation updated, tested `make html` command in the `docs/`
folder.

---------

Signed-off-by: Wenqi Li <[email protected]>
Signed-off-by: Yiheng Wang <[email protected]>
Signed-off-by: KumoLiu <[email protected]>
Signed-off-by: Ben Murray <[email protected]>
Co-authored-by: Ben Murray <[email protected]>
Co-authored-by: binliu <[email protected]>
Co-authored-by: Yiheng Wang <[email protected]>
Co-authored-by: YunLiu <[email protected]>
Co-authored-by: Yiheng Wang <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: KumoLiu <[email protected]>
@atbenmurray atbenmurray mentioned this pull request Apr 28, 2023
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

7 participants