Skip to content

Issues with WSI-properties dictionary and .tif Support #87

@glebmanaev

Description

@glebmanaev

Hi, hope you are doing well. I have encountered several issues with CellViT repo recently.

Describe the bug
WSI-properties dictionary is either ignored or leads to errors during pre-processing.

To Reproduce
Steps to reproduce the behavior:

  1. Command: python ./preprocessing/patch_extraction/main_extraction.py --config ./example/preprocessing_example.yaml --wsi_properties "{\"slide_mpp\": \"0.5\", \"magnification\": \"20\"}"
    Error Traceback: main_extraction.py: error: argument --wsi_properties: invalid dict value: '{"slide_mpp": "0.5", "magnification": "20"}'

Identical errors for --wsi_properties '{"slide_mpp": 0.5, "magnification": 20}' and --wsi_properties "dict(slide_mpp=0.5, magnification=20)"

  1. The alternative addition of it to config.yaml mentioned in preprocessing.md
wsi_properties:
  - target_mpp: 0.5
  - magnification: 20

Causes:

Traceback (most recent call last):
  File "/cluster/CellViT/./preprocessing/patch_extraction/main_extraction.py", line 29, in <module>
    configuration, logger = configuration_parser.get_config()
  File "/cluster/CellViT/preprocessing/patch_extraction/src/cli.py", line 590, in get_config
    yaml_config = PreProcessingYamlConfig(**yaml_config)
  File "pydantic/main.py", line 342, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for PreProcessingYamlConfig
wsi_properties
  value is not a valid dict (type=type_error.dict)

The following options of config.yaml do not cause errors, but

target_mag: 20
target_mpp: 0.5
wsi_properties:
  target_mpp: 0.5
  magnification: 20

but are most likely ignored. Because when running preprocessing for a .tiff file that lacks metadata and using the config.yaml's from above:
OPENSLIDE_DEBUG=detection python ./preprocessing/patch_extraction/main_extraction.py --config ./example/preprocessing_example.yaml

I am getting:

2025-03-13 09:25:32,245 [INFO] - Using OpenSlide
2025-03-13 09:25:32,246 [INFO] - Data store directory: /cluster/CellViT/example/output/preprocessing
2025-03-13 09:25:32,246 [INFO] - Images found: 1
2025-03-13 09:25:32,246 [INFO] - Annotations found: 0
2025-03-13 09:25:32,246 [INFO] - Removing complete dataset! This may take a while.
2025-03-13 09:25:32,248 [INFO] - ****************************************************************************************************************************************************************************************************
2025-03-13 09:25:32,248 [INFO] - 1/1: MACEGEJ-1-1.tiff
2025-03-13 09:25:32,248 [INFO] - Computing patches for MACEGEJ-1-1.tiff
Openslide-Message: 09:25:32.248: mirax: Is a TIFF file
Openslide-Message: 09:25:32.249: hamamatsu-vms-vmu: Is a TIFF file
Openslide-Message: 09:25:32.249: hamamatsu-ndpi: No TIFF tag 65420
Openslide-Message: 09:25:32.249: sakura: Is a TIFF file
Openslide-Message: 09:25:32.249: trestle: No such value: directory 0, tag 305
Openslide-Message: 09:25:32.249: aperio: Not an Aperio slide
Openslide-Message: 09:25:32.249: leica: Not a Leica slide
Openslide-Message: 09:25:32.249: philips: No such value: directory 0, tag 305
Openslide-Message: 09:25:32.249: ventana: No such value: directory 0, tag 700
Openslide-Message: 09:25:32.253: mirax: Is a TIFF file
Openslide-Message: 09:25:32.253: hamamatsu-vms-vmu: Is a TIFF file
Openslide-Message: 09:25:32.253: hamamatsu-ndpi: No TIFF tag 65420
Openslide-Message: 09:25:32.253: sakura: Is a TIFF file
Openslide-Message: 09:25:32.254: trestle: No such value: directory 0, tag 305
Openslide-Message: 09:25:32.254: aperio: Not an Aperio slide
Openslide-Message: 09:25:32.254: leica: Not a Leica slide
Openslide-Message: 09:25:32.254: philips: No such value: directory 0, tag 305
Openslide-Message: 09:25:32.254: ventana: No such value: directory 0, tag 700
Traceback (most recent call last):
  File "/cluster/CellViT/./preprocessing/patch_extraction/main_extraction.py", line 33, in <module>
    slide_processor.sample_patches_dataset()
  File "/cluster/CellViT/preprocessing/patch_extraction/src/patch_extraction.py", line 345, in sample_patches_dataset
    ) = self._prepare_wsi(wsi_file)
  File "/cluster/CellViT/preprocessing/patch_extraction/src/patch_extraction.py", line 601, in _prepare_wsi
    raise NotImplementedError(
NotImplementedError: MPP must be defined either by metadata or by config file!

Additional context
Actually, I started with a .tif file, but it throws an UnsupportedFromatError, even though there is a .tif option in wsi_extension:

2025-03-13 09:26:09,185 [INFO] - Using OpenSlide
2025-03-13 09:26:09,185 [INFO] - Data store directory: /cluster/CellViT/example/output/preprocessing
2025-03-13 09:26:09,186 [INFO] - Images found: 1
2025-03-13 09:26:09,186 [INFO] - Annotations found: 0
2025-03-13 09:26:09,186 [INFO] - Removing complete dataset! This may take a while.
2025-03-13 09:26:09,187 [INFO] - ****************************************************************************************************************************************************************************************************
2025-03-13 09:26:09,188 [INFO] - 1/1: MACEGEJ-1-1.tif
2025-03-13 09:26:09,188 [INFO] - Computing patches for MACEGEJ-1-1.tif
Openslide-Message: 09:26:09.287: mirax: Is a TIFF file
Openslide-Message: 09:26:09.287: hamamatsu-vms-vmu: Is a TIFF file
Openslide-Message: 09:26:09.287: hamamatsu-ndpi: No TIFF tag 65420
Openslide-Message: 09:26:09.287: sakura: Is a TIFF file
Openslide-Message: 09:26:09.288: trestle: Not a Trestle slide
Openslide-Message: 09:26:09.288: aperio: TIFF is not tiled
Openslide-Message: 09:26:09.288: leica: TIFF is not tiled
Openslide-Message: 09:26:09.288: philips: Not a Philips slide
Openslide-Message: 09:26:09.288: ventana: No such value: directory 0, tag 700
Openslide-Message: 09:26:09.288: generic-tiff: TIFF is not tiled
Traceback (most recent call last):
  File "/cluster/CellViT/./preprocessing/patch_extraction/main_extraction.py", line 33, in <module>
    slide_processor.sample_patches_dataset()
  File "/cluster/CellViT/preprocessing/patch_extraction/src/patch_extraction.py", line 345, in sample_patches_dataset
    ) = self._prepare_wsi(wsi_file)
  File "/cluster/CellViT/preprocessing/patch_extraction/src/patch_extraction.py", line 591, in _prepare_wsi
    slide = OpenSlide(str(wsi_file))
  File "/cluster/users/gmanaiev/conda/envs/cellvit/lib/python3.9/site-packages/openslide/__init__.py", line 166, in __init__
    self._osr = lowlevel.open(str(filename))
  File "/cluster/users/gmanaiev/conda/envs/cellvit/lib/python3.9/site-packages/openslide/lowlevel.py", line 195, in _check_open
    raise OpenSlideUnsupportedFormatError("Unsupported or missing image file")
openslide.lowlevel.OpenSlideUnsupportedFormatError: Unsupported or missing image file

Module versions
All the modules have the required versions, and in particular:

openslide                 3.4.1                h7773abc_6    https://conda.anaconda.org/conda-forge
openslide-python          1.2.0                    pypi_0    pypi
libtiff                   4.5.0                h6adf6a1_2    https://conda.anaconda.org/conda-forge

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions