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

SemanticSegmentor predict not running with .dcm WSI slides #886

Open
fastorik opened this issue Nov 26, 2024 · 0 comments
Open

SemanticSegmentor predict not running with .dcm WSI slides #886

fastorik opened this issue Nov 26, 2024 · 0 comments

Comments

@fastorik
Copy link

  • TIA Toolbox version: 1.5.1
  • Python version: 3.8
  • Operating System: win 11

Description

Trying to run .dcm WSI with SemanticSegmentor.predict

What I Did

Traceback (most recent call last):
File "C:\Users\vlad\Desktop\testPytorch\main.py", line 244, in
main()
File "C:\Users\vlad\Desktop\testPytorch\main.py", line 79, in main
histomorpho_mask_output = histomorpho_segmentor.predict(
File "C:\Users\vlad\miniconda3\envs\testPytorch\lib\site-packages\tiatoolbox\models\engine\semantic_segmentor.py", line 1399, in predict
self._predict_wsi_handle_exception(
File "C:\Users\vlad\miniconda3\envs\testPytorch\lib\site-packages\tiatoolbox\models\engine\semantic_segmentor.py", line 1249, in _predict_wsi_handle_exception
raise err # noqa: TRY201
File "C:\Users\vlad\miniconda3\envs\testPytorch\lib\site-packages\tiatoolbox\models\engine\semantic_segmentor.py", line 1225, in _predict_wsi_handle_exception
self._predict_one_wsi(wsi_idx, ioconfig, str(wsi_save_path), mode)
File "C:\Users\vlad\miniconda3\envs\testPytorch\lib\site-packages\tiatoolbox\models\engine\semantic_segmentor.py", line 763, in _predict_one_wsi
wsi_reader, mask_reader = self.get_reader(
File "C:\Users\vlad\miniconda3\envs\testPytorch\lib\site-packages\tiatoolbox\models\engine\semantic_segmentor.py", line 732, in get_reader
mask_reader = reader.tissue_mask(resolution=1.25, units="power")
File "C:\Users\vlad\miniconda3\envs\testPytorch\lib\site-packages\tiatoolbox\wsicore\wsireader.py", line 1468, in tissue_mask
thumbnail = self.slide_thumbnail(resolution, units)
File "C:\Users\vlad\miniconda3\envs\testPytorch\lib\site-packages\tiatoolbox\wsicore\wsireader.py", line 1434, in slide_thumbnail
return self.read_bounds(bounds, resolution=resolution, units=units)
File "C:\Users\vlad\miniconda3\envs\testPytorch\lib\site-packages\tiatoolbox\wsicore\wsireader.py", line 4571, in read_bounds
) = self._find_read_bounds_params(
File "C:\Users\vlad\miniconda3\envs\testPytorch\lib\site-packages\tiatoolbox\wsicore\wsireader.py", line 794, in _find_read_bounds_params
read_level, post_read_scale_factor = self._find_optimal_level_and_downsample(
File "C:\Users\vlad\miniconda3\envs\testPytorch\lib\site-packages\tiatoolbox\wsicore\wsireader.py", line 477, in _find_optimal_level_and_downsample
level_scales = self.info.relative_level_scales(resolution, units)
File "C:\Users\vlad\miniconda3\envs\testPytorch\lib\site-packages\tiatoolbox\wsicore\wsimeta.py", line 298, in relative_level_scales
raise ValueError(
ValueError: ('Objective power is None. Cannot determine scale in terms of objective power.',)

issue is that DICOMWSIReader doesnt even include objective power metadata (am not quite sure if it exists for .dcm but still)

def _info(self: DICOMWSIReader) -> WSIMeta:
    """WSI metadata constructor.

    Returns:
        WSIMeta:
            Containing metadata.

    """
    level_dimensions = [
        (level.size.width, level.size.height) for level in self.wsi.levels
    ]
    level_downsamples = [
        np.mean(
            [
                level_dimensions[0][0] / level.size.width,
                level_dimensions[0][1] / level.size.height,
            ],
        )
        for level in self.wsi.levels
    ]
    dataset = self.wsi.levels.base_level.datasets[0]
    # Get pixel spacing in mm from DICOM file and convert to um/px (mpp)
    mm_per_pixel = dataset.pixel_spacing
    mpp = (mm_per_pixel.width * 1e3, mm_per_pixel.height * 1e3)

    return WSIMeta(
        slide_dimensions=level_dimensions[0],
        level_dimensions=level_dimensions,
        level_downsamples=level_downsamples,
        axes="YXS",
        mpp=mpp,
        level_count=len(level_dimensions),
        vendor=dataset.Manufacturer,
    )

however in call
mask_reader = reader.tissue_mask(resolution=1.25, units="power")
File "C:\Users\vlad\miniconda3\envs\testPytorch\lib\site-packages\tiatoolbox\wsicore\wsireader.py", line 1468, in tissue_mask

units (power) are hardcoded so there is no chance of running prediction for .dcm files currently

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant