diff --git a/monai/data/image_reader.py b/monai/data/image_reader.py index cd1486d6d3..be583fc375 100644 --- a/monai/data/image_reader.py +++ b/monai/data/image_reader.py @@ -673,8 +673,10 @@ def __init__(self, reader_lib: str = "OpenSlide"): if has_osl: self.wsi_reader = openslide.OpenSlide elif self.reader_lib == "cucim": - if has_cim: + if has_cim and hasattr(cucim, "CuImage"): self.wsi_reader = cucim.CuImage + else: + raise ImportError("Please check the cuCIM installation.") else: raise ValueError('`reader_lib` should be either "cuCIM" or "OpenSlide"') diff --git a/requirements-dev.txt b/requirements-dev.txt index ed8739ded8..1b9ae52ae1 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -31,7 +31,7 @@ Sphinx==3.5.3 recommonmark==0.6.0 sphinx-autodoc-typehints==1.11.1 sphinx-rtd-theme==0.5.2 -cucim~=0.19.0; platform_system == "Linux" +cucim>=21.8.2; platform_system == "Linux" openslide-python==1.1.2 pandas requests diff --git a/setup.cfg b/setup.cfg index f7ed90a14a..eddb898b0d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -40,7 +40,7 @@ all = tqdm>=4.47.0 lmdb psutil - cucim~=0.19.0 + cucim>=21.8.2 openslide-python==1.1.2 pandas einops @@ -68,7 +68,7 @@ lmdb = psutil = psutil cucim = - cucim~=0.19.0 + cucim>=21.8.2 openslide = openslide-python==1.1.2 pandas = diff --git a/tests/test_cuimage_reader.py b/tests/test_cuimage_reader.py index 2cbfaec113..934afe4771 100644 --- a/tests/test_cuimage_reader.py +++ b/tests/test_cuimage_reader.py @@ -21,7 +21,8 @@ from monai.data.image_reader import WSIReader from monai.utils import optional_import -_, has_cim = optional_import("cucim") +cucim, has_cucim = optional_import("cucim") +has_cucim = has_cucim and hasattr(cucim, "CuImage") PILImage, has_pil = optional_import("PIL.Image") FILE_URL = "http://openslide.cs.cmu.edu/download/openslide-testdata/Generic-TIFF/CMU-1.tiff" @@ -83,7 +84,7 @@ class TestCuCIMReader(unittest.TestCase): - @skipUnless(has_cim, "Requires CuCIM") + @skipUnless(has_cucim, "Requires CuCIM") def setUp(self): download_url(FILE_URL, FILE_PATH, "5a3cfd4fd725c50578ddb80b517b759f") @@ -112,6 +113,7 @@ def test_read_patches(self, file_path, patch_info, expected_img): @parameterized.expand([TEST_CASE_RGB_0, TEST_CASE_RGB_1]) @skipUnless(has_pil, "Requires PIL") + @skipUnless(has_cucim and cucim.__version__ == "0.19.0", "Skipped for cicum>0.19.0") def test_read_rgba(self, img_expected): image = {} reader = WSIReader("cuCIM") diff --git a/tests/test_lesion_froc.py b/tests/test_lesion_froc.py index 2454de88fa..04b4cb1355 100644 --- a/tests/test_lesion_froc.py +++ b/tests/test_lesion_froc.py @@ -19,7 +19,8 @@ from monai.apps.pathology.metrics import LesionFROC from monai.utils import optional_import -_, has_cucim = optional_import("cucim") +_cucim, has_cucim = optional_import("cucim") +has_cucim = has_cucim and hasattr(_cucim, "CuImage") _, has_skimage = optional_import("skimage.measure") _, has_sp = optional_import("scipy.ndimage") PILImage, has_pil = optional_import("PIL.Image") diff --git a/tests/test_patch_wsi_dataset.py b/tests/test_patch_wsi_dataset.py index f775f28376..0d08d6b946 100644 --- a/tests/test_patch_wsi_dataset.py +++ b/tests/test_patch_wsi_dataset.py @@ -21,7 +21,8 @@ from monai.apps.utils import download_url from monai.utils import optional_import -_, has_cim = optional_import("cucim") +_cucim, has_cim = optional_import("cucim") +has_cim = has_cim and hasattr(_cucim, "CuImage") _, has_osl = optional_import("openslide") FILE_URL = "http://openslide.cs.cmu.edu/download/openslide-testdata/Generic-TIFF/CMU-1.tiff" diff --git a/tests/test_smartcache_patch_wsi_dataset.py b/tests/test_smartcache_patch_wsi_dataset.py index c484e5fc69..af60d23cfc 100644 --- a/tests/test_smartcache_patch_wsi_dataset.py +++ b/tests/test_smartcache_patch_wsi_dataset.py @@ -21,7 +21,8 @@ from monai.apps.utils import download_url from monai.utils import optional_import -_, has_cim = optional_import("cucim") +_cucim, has_cim = optional_import("cucim") +has_cim = has_cim and hasattr(_cucim, "CuImage") FILE_URL = "http://openslide.cs.cmu.edu/download/openslide-testdata/Generic-TIFF/CMU-1.tiff" FILE_PATH = os.path.join(os.path.dirname(__file__), "testing_data", "temp_" + os.path.basename(FILE_URL))