Project-MONAI / Project-MONAI/MONAI
Make `apply_pending_transforms` optional in `execute_compose`
@atbenmurray is already working on this.
Since Jan 19, 2024.
- Dominant language
- Python
- Stars
- 8.7k
- Forks
- 1.6k
- Avg merge
- 5d 1h
- Merged PRs (30d)
- 20
Description
Is your feature request related to a problem? Please describe.
Suppose I'm defining transform as follows:
from monai import transforms as mt
crop_t = mt.OneOf(
[
mt.RandSpatialCropD(['img', 'seg'], roi_size=(8, 8)),
mt.RandCropByPosNegLabelD(['img', 'seg'], label_key='seg', spatial_size=(8, 8)),
],
lazy=True,
)
rotate_t = mt.RotateD(['img', 'seg'], np.pi / 3)
t = mt.Compose([crop_t, rotate_t], lazy=True)
What I intend to do here is to crop a patch from the image with one of the two methods (similar to what nnU-Net does), and rotate the cropped patch afterwards. It will be very nice if I can lazy resample the patch after both crop and rotation (, and which should be possible). However, OneOf is a subclass of Compose, and it calls execute_compose, which always calls apply_pending_transforms at last, which makes the cropped patch resampled in advance and causes information loss during the subsequent rotation.
Describe the solution you'd like
We can add a parameter to execute_compose, and the subclasses of Compose if necessary, with a name like apply_pendding indicating if the pending operations should be applied.
Additional context
This was originally proposed in a discussion (the second question). It seems that my feature request is not clearly conveyed. But I believe this is a very useful feature (as my example shows), therefore I'd like to propose again here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.