MONAI icon indicating copy to clipboard operation
MONAI copied to clipboard

Lazy resampling does not get the `mode` and `padding_mode` from the pending transforms properly

Open function2-llx opened this issue 10 months ago • 2 comments

Describe the bug

The lazy spatial resample records the mode and padding_mode in the extra_info field:

https://github.com/Project-MONAI/MONAI/blob/8e99af5f96df0746d6cbcaed88feaea0e51abd56/monai/transforms/spatial/functional.py#L118-L124

https://github.com/Project-MONAI/MONAI/blob/8e99af5f96df0746d6cbcaed88feaea0e51abd56/monai/transforms/spatial/functional.py#L135-L146

However, the during lazy resampling, the corresponding value is not get from the extra_info filed but directly from the operation. Well, the comment here may also indicate this issue.

https://github.com/Project-MONAI/MONAI/blob/8e99af5f96df0746d6cbcaed88feaea0e51abd56/monai/transforms/lazy/utils.py#L92-L104

To Reproduce

import torch

from monai import transforms as mt
from monai.data import MetaTensor
from monai.utils import GridSampleMode, GridSamplePadMode

def main():
    trans = mt.Compose(
        [
            mt.Spacing((1.5, 1.5, 1.5), mode=GridSampleMode.NEAREST, padding_mode=GridSamplePadMode.ZEROS),
        ],
        lazy=True,
    )
    x = MetaTensor(torch.randint(3, size=(1, 1, 16, 16, 16)))
    print(x.unique())
    y = trans(x)
    print(y.unique())

if __name__ == '__main__':
    main()

Expected behavior Output without lazy:

tensor([0, 1, 2])
metatensor([0., 1., 2.])

Actual result

metatensor([0, 1, 2])
metatensor([0.0000, 0.2500, 0.5000, 0.7500, 1.0000, 1.2500, 1.5000, 1.7500, 2.0000])

function2-llx avatar Aug 10 '23 08:08 function2-llx