Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error loading multiple slides in pathml #324

Closed
archanabhardwaj opened this issue Jul 29, 2022 · 4 comments
Closed

Error loading multiple slides in pathml #324

archanabhardwaj opened this issue Jul 29, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@archanabhardwaj
Copy link

archanabhardwaj commented Jul 29, 2022

Hello
With the help of examples tutorials, all the pre-processing works fine for single slide data. But while loading multiple slides , it gives me error :

Here is script that I followed:

from pathlib import Path
from pathml.core import HESlide, SlideDataset
data_dir = Path("/DATA/Desktop/AI_pathology/test_AB/")
wsi_paths = list(data_dir.glob("*.svs"))
wsi_paths
wsi_list = [HESlide(p) for p in wsi_paths]

All the above steps are exactly as given in section under "Datasets of Images" at https://pathml.readthedocs.io/en/latest/loading_slides.html

Error :
ArgumentError: argument 1: <class 'TypeError'>: Incorrect type

If I am missing something, please correct me.

Thanks in advance

@archanabhardwaj archanabhardwaj added the bug Something isn't working label Jul 29, 2022
@jacob-rosenthal
Copy link
Collaborator

Can you please share the full error message?
Can you please also share the output of print(wsi_paths)?

@archanabhardwaj
Copy link
Author

Hello

I am sharing full error message and exact path :

from pathlib import Path
from pathml.core import HESlide, SlideDataset
data_dir = Path("/home/Desktop/AI_pathology/test_AB/")
wsi_paths = list(data_dir.glob("*.svs"))

print(wsi_paths)
[PosixPath('/home/Desktop/AI_pathology/test_AB/test1.svs'), PosixPath('/home/Desktop/AI_pathology/test_AB/test2.svs')]

Error message :
wsi_list = [HESlide(p) for p in wsi_paths]


ArgumentError Traceback (most recent call last)
in
----> 1 wsi_list = [HESlide(p) for p in wsi_paths]

in (.0)
----> 1 wsi_list = [HESlide(p) for p in wsi_paths]

~/Desktop/AI_pathology/new_path/pathml/pathml/core/slide_data.py in init(self, *args, **kwargs)
501 def init(self, *args, **kwargs):
502 kwargs["slide_type"] = pathml.core.types.HE
--> 503 super().init(*args, **kwargs)
504
505

~/Desktop/AI_pathology/new_path/pathml/pathml/core/slide_data.py in init(self, filepath, name, masks, tiles, labels, backend, slide_type, stain, platform, tma, rgb, volumetric, time_series, counts, dtype)
161
162 if backend.lower() == "openslide":
--> 163 backend_obj = pathml.core.OpenSlideBackend(filepath)
164 elif backend.lower() == "bioformats":
165 backend_obj = pathml.core.BioFormatsBackend(filepath, dtype)

~/Desktop/AI_pathology/new_path/pathml/pathml/core/slide_backends.py in init(self, filename)
63 logger.info(f"OpenSlideBackend loading file at: {filename}")
64 self.filename = filename
---> 65 self.slide = openslide.open_slide(filename=filename)
66 self.level_count = self.slide.level_count
67

~/.local/lib/python3.8/site-packages/openslide/init.py in open_slide(filename)
386 object for other types of images."""
387 try:
--> 388 return OpenSlide(filename)
389 except OpenSlideUnsupportedFormatError:
390 return ImageSlide(filename)

~/.local/lib/python3.8/site-packages/openslide/init.py in init(self, filename)
158 AbstractSlide.init(self)
159 self._filename = filename
--> 160 self._osr = lowlevel.open(filename)
161
162 def repr(self):

ArgumentError: argument 1: <class 'TypeError'>: Incorrect type

Thanks in advance

@jacob-rosenthal
Copy link
Collaborator

Great, posting the entire error message is very useful!

Looks like the problem is being caused because the paths in wsi_paths are Pathlib.Path objects, which openslide doesn't know how to open (openslide/openslide-python#112). They did update openslide to fix this in v1.2.0 (openslide/openslide-python#123, mentioned in release notes).

So, I think there are two ways you could fix this:

  1. convert the Path objects to strings first (wsi_list = [HESlide(str(p)) for p in wsi_paths])
  2. Update openslide to v1.2.0 or greater

We can also add a check in PathML to prevent this from happening in the future. Thanks!!

@archanabhardwaj
Copy link
Author

Hi
I converted the converted the Path objects to strings and it worked.

Thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants