Skip to content

Commit

Permalink
Fix MONAILabel-related bugs in dtype conversion and inverse of Spacing (
Browse files Browse the repository at this point in the history
#6315)

Fixes issues relating to dtype and src_affine in inverse of spatial
transforms. Issue found to occur when inverse for a given function is
required many times, e.g. for iterative updates in interactive
segmentation. Related issue #6314

---------

Signed-off-by: Liam Chalcroft <[email protected]>
  • Loading branch information
liamchalcroft authored Apr 11, 2023
1 parent 9cb17ae commit 768964b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions monai/transforms/spatial/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ def inverse(self, data: torch.Tensor) -> torch.Tensor:
with self.trace_transform(False):
# we can't use `self.__call__` in case a child class calls this inverse.
out: torch.Tensor = SpatialResample.__call__(self, data, **kw_args)
kw_args["src_affine"] = kw_args.get("dst_affine")
return out


Expand Down
2 changes: 1 addition & 1 deletion monai/utils/type_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

def get_numpy_dtype_from_string(dtype: str) -> np.dtype:
"""Get a numpy dtype (e.g., `np.float32`) from its string (e.g., `"float32"`)."""
return np.empty([], dtype=dtype).dtype
return np.empty([], dtype=str(dtype).split(".")[-1]).dtype


def get_torch_dtype_from_string(dtype: str) -> torch.dtype:
Expand Down

0 comments on commit 768964b

Please sign in to comment.