Repository: Project-MONAI/MONAI

Issue:
test_keep_largest_connected_component
```
ERROR: test_correct_results_before_after_onehot_60_2_regions (tests.test_keep_largest_connected_component.TestKeepLargestConnectedComponent)
From torch==1.7, torch.argmax changes its mechanism that if there are multiple maximal values then the [with _='2 regions', args={'num_components': 2}, input_image=tensor([[[0, 0, 1, 1, 0, 0, 1],
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/opt/conda/lib/python3.8/site-packages/parameterized/parameterized.py", line 620, in standalone_func
    return func(*(a + p.args), **p.kwargs, **kw)
  File "/__w/MONAI/MONAI/tests/test_keep_largest_connected_component.py", line 401, in test_correct_results_before_after_onehot
    result = converter(deepcopy(input_image))
  File "/__w/MONAI/MONAI/monai/transforms/post/array.py", line 334, in __call__
    mask = get_largest_connected_component_mask(foreground, self.connectivity, self.num_components)
  File "/__w/MONAI/MONAI/monai/transforms/utils.py", line 1034, in get_largest_connected_component_mask
    label = cucim.skimage.measure.label
  File "/opt/conda/lib/python3.8/site-packages/lazy_loader/__init__.py", line 89, in __getattr__
    raise AttributeError(f"No {package_name} attribute {name}")
AttributeError: No cucim attribute skimage

======================================================================
```
test_keep_largest_connected_component
```
ERROR: test_correct_results_before_after_onehot_60_2_regions (tests.test_keep_largest_connected_component.TestKeepLargestConnectedComponent)
From torch==1.7, torch.argmax changes its mechanism that if there are multiple maximal values then the [with _='2 regions', args={'num_components': 2}, input_image=tensor([[[0, 0, 1, 1, 0, 0, 1],
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/opt/conda/lib/python3.8/site-packages/parameterized/parameterized.py", line 620, in standalone_func
    return func(*(a + p.args), **p.kwargs, **kw)
  File "/__w/MONAI/MONAI/tests/test_keep_largest_connected_component.py", line 401, in test_correct_results_before_after_onehot
    result = converter(deepcopy(input_image))
  File "/__w/MONAI/MONAI/monai/transforms/post/array.py", line 334, in __call__
    mask = get_largest_connected_component_mask(foreground, self.connectivity, self.num_components)
  File "/__w/MONAI/MONAI/monai/transforms/utils.py", line 1034, in get_largest_connected_component_mask
    label = cucim.skimage.measure.label
  File "/opt/conda/lib/python3.8/site-packages/lazy_loader/__init__.py", line 89, in __getattr__
    raise AttributeError(f"No {package_name} attribute {name}")
AttributeError: No cucim attribute skimage

======================================================================
```


Discussion:

Resolving patch:
diff --git a/monai/auto3dseg/utils.py b/monai/auto3dseg/utils.py
--- a/monai/auto3dseg/utils.py
+++ b/monai/auto3dseg/utils.py
@@ -94,11 +94,11 @@ def get_label_ccp(mask_index: MetaTensor, use_gpu: bool = True) -> tuple[list[An
             regardless of this setting.
 
     """
-    cucim, has_cucim = optional_import("cucim")
+    skimage, has_cucim = optional_import("cucim.skimage")
     shape_list = []
     if mask_index.device.type == "cuda" and has_cp and has_cucim and use_gpu:
         mask_cupy = ToCupy()(mask_index.short())
-        labeled = cucim.skimage.measure.label(mask_cupy)
+        labeled = skimage.measure.label(mask_cupy)
         vals = cp.unique(labeled[cp.nonzero(labeled)])
 
         for ncomp in vals:
diff --git a/monai/transforms/utils.py b/monai/transforms/utils.py
--- a/monai/transforms/utils.py
+++ b/monai/transforms/utils.py
@@ -1027,11 +1027,11 @@ def get_largest_connected_component_mask(
     """
     # use skimage/cucim.skimage and np/cp depending on whether packages are
     # available and input is non-cpu torch.tensor
-    cucim, has_cucim = optional_import("cucim")
+    skimage, has_cucim = optional_import("cucim.skimage")
     use_cp = has_cp and has_cucim and isinstance(img, torch.Tensor) and img.device != torch.device("cpu")
     if use_cp:
         img_ = convert_to_cupy(img.short())  # type: ignore
-        label = cucim.skimage.measure.label
+        label = skimage.measure.label
         lib = cp
     else:
         if not has_measure:


Test patch: