Skip to content

lazy RandAffine has no effect #6773

Closed

Description

@function2-llx

Describe the bug
When using RandAffine with lazy=True, it does not perform any transform at all.

To Reproduce

import torch

from monai import transforms as mt

def main():
    x = torch.randn(1, 32, 32, 32)
    trans = mt.Compose(
        [mt.RandAffine(1., translate_range=[(0, 0), (1, 1), (2, 2)])],
        lazy=False
    )
    print(trans(x).affine)
    lazy_trans = mt.Compose(
        [mt.RandAffine(1., translate_range=[(0, 0), (1, 1), (2, 2)])],
        lazy=True,
    )
    print(lazy_trans(x).affine)

if __name__ == '__main__':
    main()

Actual Result

tensor([[1., 0., 0., 0.],
        [0., 1., 0., 1.],
        [0., 0., 1., 2.],
        [0., 0., 0., 1.]], dtype=torch.float64)
tensor([[1., 0., 0., 0.],
        [0., 1., 0., 0.],
        [0., 0., 1., 0.],
        [0., 0., 0., 1.]], dtype=torch.float64)

Activity

  1. self-assigned this
    on Jul 25, 2023
  2. added
    bugSomething isn't working
    on Jul 28, 2023
  3. wyli commented on Jul 28, 2023

    @wyli
    Contributor

    thanks for testing and reporting @function2-llx, that's a good point, the bug was not detected earlier because we used the same transform instance to verify lazy/non-lazy consistency in this case

    g = RandAffine(**input_param)
    g.set_random_state(123)
    result = g(**input_data)
    test_resampler_lazy(g, result, input_param, input_data, seed=123)
    , your PR #6774 addresses the issue, I'll try to make it backward compatible (in terms of pseudo random states) and merge it.

  4. added a commit that references this issue on Jul 28, 2023
    5feb353
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions