From f18096d5ed11e256c54b7c2d0f5bc8c9e41a218c Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Mon, 22 Jan 2024 12:08:05 +0800 Subject: [PATCH 1/4] fix #7407 Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- monai/metrics/utils.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/monai/metrics/utils.py b/monai/metrics/utils.py index d4b8f6e9b6..e34401391e 100644 --- a/monai/metrics/utils.py +++ b/monai/metrics/utils.py @@ -38,10 +38,6 @@ binary_erosion, _ = optional_import("scipy.ndimage.morphology", name="binary_erosion") distance_transform_edt, _ = optional_import("scipy.ndimage.morphology", name="distance_transform_edt") distance_transform_cdt, _ = optional_import("scipy.ndimage.morphology", name="distance_transform_cdt") -cucim_binary_erosion, has_cucim_binary_erosion = optional_import("cucim.skimage.morphology", name="binary_erosion") -cucim_distance_transform_edt, has_cucim_distance_transform_edt = optional_import( - "cucim.core.operations.morphology", name="distance_transform_edt" -) __all__ = [ "ignore_background", @@ -179,6 +175,7 @@ def get_mask_edges( always_return_as_numpy: whether to a numpy array regardless of the input type. If False, return the same type as inputs. """ + cucim_binary_erosion, has_cucim_binary_erosion = optional_import("cucim.skimage.morphology", name="binary_erosion") if seg_pred.shape != seg_gt.shape: raise ValueError(f"seg_pred and seg_gt should have same shapes, got {seg_pred.shape} and {seg_gt.shape}.") converter: Any From 6e588813a74ffee57c74b86c3caa1697b3eee75f Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Mon, 22 Jan 2024 23:12:01 +0800 Subject: [PATCH 2/4] add tests Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- tests/test_set_visible_devices.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_set_visible_devices.py b/tests/test_set_visible_devices.py index 53703e107a..993e8a4ac2 100644 --- a/tests/test_set_visible_devices.py +++ b/tests/test_set_visible_devices.py @@ -35,6 +35,13 @@ def test_visible_devices(self): ) self.assertEqual(num_gpus_before, num_gpus_after) + # test import monai won't affect setting CUDA_VISIBLE_DEVICES + num_gpus_after_monai = self.run_process_and_get_exit_code( + 'python -c "import os; import torch; import monai; ' + + "os.environ['CUDA_VISIBLE_DEVICES'] = '0'; exit(torch.cuda.device_count())\"" + ) + self.assertEqual(num_gpus_after_monai, 1) + if __name__ == "__main__": unittest.main() From 0abd612f92eb5bf9db55ffa688aad475bea8163b Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Mon, 22 Jan 2024 23:14:03 +0800 Subject: [PATCH 3/4] address comments Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- monai/metrics/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/monai/metrics/utils.py b/monai/metrics/utils.py index e34401391e..bc588a4ed6 100644 --- a/monai/metrics/utils.py +++ b/monai/metrics/utils.py @@ -175,6 +175,7 @@ def get_mask_edges( always_return_as_numpy: whether to a numpy array regardless of the input type. If False, return the same type as inputs. """ + # move in the funciton to avoid using all the GPUs cucim_binary_erosion, has_cucim_binary_erosion = optional_import("cucim.skimage.morphology", name="binary_erosion") if seg_pred.shape != seg_gt.shape: raise ValueError(f"seg_pred and seg_gt should have same shapes, got {seg_pred.shape} and {seg_gt.shape}.") From fa988df803fc0d9eb96fb53a25adb5c4087ca99b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 22 Jan 2024 15:14:49 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- monai/metrics/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monai/metrics/utils.py b/monai/metrics/utils.py index bc588a4ed6..e7057256fb 100644 --- a/monai/metrics/utils.py +++ b/monai/metrics/utils.py @@ -175,7 +175,7 @@ def get_mask_edges( always_return_as_numpy: whether to a numpy array regardless of the input type. If False, return the same type as inputs. """ - # move in the funciton to avoid using all the GPUs + # move in the funciton to avoid using all the GPUs cucim_binary_erosion, has_cucim_binary_erosion = optional_import("cucim.skimage.morphology", name="binary_erosion") if seg_pred.shape != seg_gt.shape: raise ValueError(f"seg_pred and seg_gt should have same shapes, got {seg_pred.shape} and {seg_gt.shape}.")