Skip to content

Make spatial transform inverse compatible for multiple passes #6314

Closed

Description

@liamchalcroft

Using SpacingD as a pre-processing transform in a MONAILabel app, and the Deepedit click transforms often require multiple iterations. The default inverse transform runs into 2 errors when trying to inverse the SpacingD transform for the second time:

  1. 'TypeError: Cannot interpret 'torch.float64' as a data type' from 'get_numpy_dtype_from_string' in 'monai/utils/type_conversion.py' . I am able to fix this locally by changing the function to remove any numpy/torch prefix: 'dtype=str(dtype).split('.')[-1]'
  2. ' KeyError: 'src_affine' ' from 'monai/transforms/spatial/array.py", line 226, in inverse: kw_args["dst_affine"] = kw_args.pop("src_affine")' . I am able to fix this locally by adding this line before the inverse fn return: 'kw_args["src_affine"] = kw_args["dst_affine"]' in order to restore the src_affine.

Activity

  1. wyli commented on Apr 6, 2023

    @wyli
    Contributor

    thanks for reporting these, if you plan to contribute,
    for 1, please add tests to

    @parameterized.expand([["float", np.float64], ["float32", np.float32], ["float64", np.float64]])
    def test_from_string(self, dtype_str, expected_np):
    expected_pt = get_equivalent_dtype(expected_np, torch.Tensor)
    # numpy
    dtype = get_numpy_dtype_from_string(dtype_str)
    self.assertEqual(dtype, expected_np)

    for 2, please change it to kw_args["src_affine"] = kw_wargs.get("dst_affine") to allow for empty src_affine before calling the inverse fn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions