From a4989fb875f2b36af200477064b890fe16126877 Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Fri, 19 Apr 2024 13:44:34 +0800 Subject: [PATCH 1/3] fix #7660 Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- monai/transforms/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monai/transforms/utils.py b/monai/transforms/utils.py index 14f35e1219..b7e3637a05 100644 --- a/monai/transforms/utils.py +++ b/monai/transforms/utils.py @@ -2190,7 +2190,7 @@ def distance_transform_edt( if return_distances: dtype = torch.float64 if float64_distances else torch.float32 if distances is None: - distances = torch.zeros_like(img, dtype=dtype) # type: ignore + distances = torch.zeros_like(img.contiguous(), dtype=dtype) # type: ignore else: if not isinstance(distances, torch.Tensor) and distances.device != img.device: raise TypeError("distances must be a torch.Tensor on the same device as img") From 612c67be6879f89f5cffff674eea242db458121e Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Mon, 22 Apr 2024 21:48:28 +0800 Subject: [PATCH 2/3] address comments Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- monai/transforms/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monai/transforms/utils.py b/monai/transforms/utils.py index b7e3637a05..560dbac346 100644 --- a/monai/transforms/utils.py +++ b/monai/transforms/utils.py @@ -2190,7 +2190,7 @@ def distance_transform_edt( if return_distances: dtype = torch.float64 if float64_distances else torch.float32 if distances is None: - distances = torch.zeros_like(img.contiguous(), dtype=dtype) # type: ignore + distances = torch.zeros_like(img, memory_format=torch.contiguous_format, dtype=dtype) # type: ignore else: if not isinstance(distances, torch.Tensor) and distances.device != img.device: raise TypeError("distances must be a torch.Tensor on the same device as img") From bbe0058257b55e4cc66b84b496a96eb0faa2db21 Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Mon, 22 Apr 2024 23:04:26 +0800 Subject: [PATCH 3/3] fix ci Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- tests/test_clip_intensity_percentiles.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/test_clip_intensity_percentiles.py b/tests/test_clip_intensity_percentiles.py index f584a0bb41..3b4b1a6e61 100644 --- a/tests/test_clip_intensity_percentiles.py +++ b/tests/test_clip_intensity_percentiles.py @@ -18,7 +18,6 @@ from monai.transforms import ClipIntensityPercentiles from monai.transforms.utils import soft_clip from monai.transforms.utils_pytorch_numpy_unification import clip, percentile -from monai.utils.type_conversion import convert_to_tensor from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, NumpyImageTestCase3D, assert_allclose @@ -30,8 +29,8 @@ def test_hard_clipping_two_sided(self, p): im = p(self.imt) result = hard_clipper(im) lower, upper = percentile(im, (5, 95)) - expected = clip(convert_to_tensor(im), lower, upper) - assert_allclose(result, p(expected), type_test="tensor", rtol=1e-7, atol=0) + expected = clip(im, lower, upper) + assert_allclose(result, p(expected), type_test="tensor", rtol=1e-4, atol=0) @parameterized.expand([[p] for p in TEST_NDARRAYS]) def test_hard_clipping_one_sided_high(self, p):