SBU-BMI / wsinfer

πŸ”₯ πŸš€ Blazingly fast pipeline for patch-based classification in whole slide images
https://wsinfer.readthedocs.io
Apache License 2.0
55 stars 9 forks source link

wsinfer.errors.CannotReadSpacing #213

Closed jeginderof closed 4 months ago

jeginderof commented 5 months ago
(wsinfer_env) PS C:\Users\pqmao> wsinfer run -i slides/ -o results/ -m "breast-tumor-resnet34.tcga-brca"

Running wsinfer version 0.5.0

If you run into issues, please submit a new issue at
https://github.com/kaczmarj/patch-classification-pipeline/issues/new

System information
------------------
Timestamp: Thu Feb  8 16:47:09 2024 W. Europe Standard Time
Windows-10
User: pqmao
Hostname: xxxx
Working directory: C:\Users\pqmao
In container: no
Python executable: C:\Users\pqmao\wsinfer_env\Scripts\python.exe
Python version: 3.11.5
  Torch version: 2.2.0+cu121
  Torchvision version: 0.17.0+cu121
GPU available
  Using 1 GPU(s)
  CUDA version: 12.1
CUDA_VISIBLE_DEVICES: 0

Command line arguments
----------------------
wsi_dir = C:\Users\pqmao\slides
results_dir = C:\Users\pqmao\results
model_name = breast-tumor-resnet34.tcga-brca
config = None
model_path = None
batch_size = 32
num_workers = 8
speedup = False
----------------------

Finding patch coordinates...

Slide 1 of 1 (100.00%)
INFO:wsinfer.patchlib:Segmenting and patching slide C:\Users\pqmao\slides\a.tiff
INFO:wsinfer.patchlib:Using prefix as slide ID: a
ERROR:wsinfer.patchlib:Failed to segment and patch slide
C:\Users\pqmao\slides\a.tiff
Traceback (most recent call last):
  File "C:\Users\pqmao\wsinfer_env\Lib\site-packages\wsinfer\patchlib\__init__.py", line 357, in segment_and_patch_directory_of_slides
    segment_and_patch_one_slide(
  File "C:\Users\pqmao\wsinfer_env\Lib\site-packages\wsinfer\patchlib\__init__.py", line 106, in segment_and_patch_one_slide
    mpp = get_avg_mpp(slide_path)
          ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\pqmao\wsinfer_env\Lib\site-packages\wsinfer\wsi.py", line 291, in get_avg_mpp
    raise CannotReadSpacing(slide_path)
wsinfer.errors.CannotReadSpacing: C:\Users\pqmao\slides\a.tiff

Could you please assist me in resolving this issue?

kaczmarj commented 5 months ago

the microns per pixel (MPP) values cannot be read from C:\Users\pqmao\slides\a.tiff. if you have openslide or qupath on your computer, could you try reading the MPP of your image?

jeginderof commented 5 months ago
a_HE_properties

I attached image properties.

kaczmarj commented 5 months ago

hmm very interesting... is there any way you could share this image?

in addition, wsinfer has two slide-reading backends: tiffslide and openslide. you can try installing openslide-python in your python environment and running

wsinfer --backend=openslide run .....
jeginderof commented 5 months ago

for some reason installing openslide was unsucessful; then I tried tiffslide but same error:

wsinfer  --backend=tiffslide run -i slides/ -o results/ -m "breast-tumor-resnet34.tcga-brca"
INFO:wsinfer.wsi:Setting backend to tiffslide

Running wsinfer version 0.5.0

If you run into issues, please submit a new issue at
https://github.com/kaczmarj/patch-classification-pipeline/issues/new

System information
------------------
Timestamp: Fri Feb  9 06:45:39 2024 W. Europe Standard Time
Windows-10
Working directory: C:\Users\pqmamo
In container: no
Python executable: C:\Users\pqmamo\wsinfer_env\Scripts\python.exe
Python version: 3.11.5
  Torch version: 2.2.0+cu121
  Torchvision version: 0.17.0+cu121
GPU available
  Using 1 GPU(s)
  CUDA version: 12.1
CUDA_VISIBLE_DEVICES: 0

Command line arguments
----------------------
wsi_dir = C:\Users\pqmamo\slides
results_dir = C:\Users\pqmamo\results
model_name = breast-tumor-resnet34.tcga-brca
config = None
model_path = None
batch_size = 32
num_workers = 8
speedup = False
----------------------

Finding patch coordinates...

Slide 1 of 1 (100.00%)
INFO:wsinfer.patchlib:Segmenting and patching slide C:\Users\pqmamo\slides\a.tiff
INFO:wsinfer.patchlib:Using prefix as slide ID: a
ERROR:wsinfer.patchlib:Failed to segment and patch slide
C:\Users\pqmamo\slides\a.tiff
Traceback (most recent call last):
  File "C:\Users\pqmamo\wsinfer_env\Lib\site-packages\wsinfer\patchlib\__init__.py", line 357, in segment_and_patch_directory_of_slides
    segment_and_patch_one_slide(
  File "C:\Users\pqmamo\wsinfer_env\Lib\site-packages\wsinfer\patchlib\__init__.py", line 106, in segment_and_patch_one_slide
    mpp = get_avg_mpp(slide_path)
          ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\pqmamo\wsinfer_env\Lib\site-packages\wsinfer\wsi.py", line 291, in get_avg_mpp
    raise CannotReadSpacing(slide_path)
wsinfer.errors.CannotReadSpacing: C:\Users\pqmamo\slides\a.tiff

Running model inference.

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\pqmamo\wsinfer_env\Scripts\wsinfer.exe\__main__.py", line 7, in <module>
  File "C:\Users\pqmamo\wsinfer_env\Lib\site-packages\click\core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\pqmamo\wsinfer_env\Lib\site-packages\click\core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "C:\Users\pqmamo\wsinfer_env\Lib\site-packages\click\core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\pqmamo\wsinfer_env\Lib\site-packages\click\core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\pqmamo\wsinfer_env\Lib\site-packages\click\core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\pqmamo\wsinfer_env\Lib\site-packages\click\decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\pqmamo\wsinfer_env\Lib\site-packages\wsinfer\cli\infer.py", line 352, in run
    failed_patching, failed_inference = run_inference(
                                        ^^^^^^^^^^^^^^
  File "C:\Users\pqmamo\wsinfer_env\Lib\site-packages\wsinfer\modellib\run_inference.py", line 85, in run_inference
    raise errors.PatchDirectoryNotFound("Results dir must include 'patches' dir")
wsinfer.errors.PatchDirectoryNotFound: Results dir must include 'patches' dir
jeginderof commented 5 months ago

I tried with another model:

(wsinfer_env) PS C:\Users\pqmamo> wsinfer  --backend=tiffslide run -i slides/ -o results/ -m "colorectal-tiatoolbox-resnet50.kather100k"
INFO:wsinfer.wsi:Setting backend to tiffslide

Running wsinfer version 0.5.0

If you run into issues, please submit a new issue at
https://github.com/kaczmarj/patch-classification-pipeline/issues/new

System information
------------------
Timestamp: Fri Feb  9 06:53:38 2024 W. Europe Standard Time
Windows-10
Working directory: C:\Users\pqmamo
In container: no
Python executable: C:\Users\pqmamo\wsinfer_env\Scripts\python.exe
Python version: 3.11.5
  Torch version: 2.2.0+cu121
  Torchvision version: 0.17.0+cu121
GPU available
  Using 1 GPU(s)
  CUDA version: 12.1
CUDA_VISIBLE_DEVICES: 0

Command line arguments
----------------------
wsi_dir = C:\Users\pqmamo\slides
results_dir = C:\Users\pqmamo\results
model_name = colorectal-tiatoolbox-resnet50.kather100k
config = None
model_path = None
batch_size = 32
num_workers = 8
speedup = False
----------------------

torchscript_model.pt: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 94.5M/94.5M [00:14<00:00, 6.33MB/s]
C:\Users\pqmamo\wsinfer_env\Lib\site-packages\huggingface_hub\file_download.py:149: UserWarning: `huggingface_hub` cache-system uses symlinks by default to efficiently store duplicated files but your machine does not support them in C:\Users\pqmamo\.cache\huggingface\hub\models--kaczmarj--colorectal-tiatoolbox-resnet50.kather100k. Caching files will still work but in a degraded version that might require more space on your disk. This warning can be disabled by setting the `HF_HUB_DISABLE_SYMLINKS_WARNING` environment variable. For more details, see https://huggingface.co/docs/huggingface_hub/how-to-cache#limitations.
To support symlinks on Windows, you either need to activate Developer Mode or to run Python as an administrator. In order to see activate developer mode, see this article: https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development
  warnings.warn(message)
config.json: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 493/493 [00:00<00:00, 32.0kB/s]

Finding patch coordinates...

Slide 1 of 1 (100.00%)
INFO:wsinfer.patchlib:Segmenting and patching slide C:\Users\pqmamo\slides\a.tiff
INFO:wsinfer.patchlib:Using prefix as slide ID: a
ERROR:wsinfer.patchlib:Failed to segment and patch slide
C:\Users\pqmamo\slides\a.tiff
Traceback (most recent call last):
  File "C:\Users\pqmamo\wsinfer_env\Lib\site-packages\wsinfer\patchlib\__init__.py", line 357, in segment_and_patch_directory_of_slides
    segment_and_patch_one_slide(
  File "C:\Users\pqmamo\wsinfer_env\Lib\site-packages\wsinfer\patchlib\__init__.py", line 106, in segment_and_patch_one_slide
    mpp = get_avg_mpp(slide_path)
          ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\pqmamo\wsinfer_env\Lib\site-packages\wsinfer\wsi.py", line 291, in get_avg_mpp
    raise CannotReadSpacing(slide_path)
wsinfer.errors.CannotReadSpacing: C:\Users\pqmamo\slides\a.tiff

Running model inference.

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\pqmamo\wsinfer_env\Scripts\wsinfer.exe\__main__.py", line 7, in <module>
  File "C:\Users\pqmamo\wsinfer_env\Lib\site-packages\click\core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\pqmamo\wsinfer_env\Lib\site-packages\click\core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "C:\Users\pqmamo\wsinfer_env\Lib\site-packages\click\core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\pqmamo\wsinfer_env\Lib\site-packages\click\core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\pqmamo\wsinfer_env\Lib\site-packages\click\core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\pqmamo\wsinfer_env\Lib\site-packages\click\decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\pqmamo\wsinfer_env\Lib\site-packages\wsinfer\cli\infer.py", line 352, in run
    failed_patching, failed_inference = run_inference(
                                        ^^^^^^^^^^^^^^
  File "C:\Users\pqmamo\wsinfer_env\Lib\site-packages\wsinfer\modellib\run_inference.py", line 85, in run_inference
    raise errors.PatchDirectoryNotFound("Results dir must include 'patches' dir")
wsinfer.errors.PatchDirectoryNotFound: Results dir must include 'patches' dir
jeginderof commented 5 months ago

hmm very interesting... is there any way you could share this image?

Please suggest a way I can share image with you

jeginderof commented 5 months ago

I used the original .ndpi image instead of .tiff or .jpg and now it works. At least no error. Matter is in the result folder, mask border is not tissue border, it is image border like a frame. That I do not know is related to input image extension or not but it is OK to close this issue.

kaczmarj commented 4 months ago

hi @jeginderof -

mask border is not tissue border, it is image border like a frame

the default settings for the tissue segmentation in wsinfer were not appropriate for your image. i have added options to customize these settings. please see the command below, which should work for your image. this is available with wsinfer 0.6.0 (released today)

wsinfer run -m breast-tumor-resnet34.tcga-brca -i slides-ndpi/ -o outputs --seg-binary-threshold 12

you can use ndpi or tiff. to convert from an ndpi to a pyramidal tiff, one can use libvips:

vips tiffsave slide.ndpi slide.tiff --compression jpeg --tile --tile-width 256 --tile-height 256 --pyramid --resunit cm

i will close this issue now but please do open a new issue if other problems arise. thanks for using wsinfer and helping us improve it!