Project-MONAI / Project-MONAI/MONAI

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

Open
#6,850 2 comments 0 reactions 1 assignee View on GitHub

@atbenmurray is already working on this.

Since Jan 19, 2024.

Feature request
Dominant language
Python
Stars
8.7k
Forks
1.6k
Avg merge
5d 1h
Merged PRs (30d)
20

Description

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])

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.