NKI-AI / dlup

Dlup are the Deep Learning Utilities for Pathology developed at the Netherlands Cancer Institute
Apache License 2.0
25 stars 7 forks source link

Numpy bug in Cashing-branch #68

Closed Dafidofff closed 2 years ago

Dafidofff commented 2 years ago

Describe the bug If I want to add a mask to the TiledROISlideImageDataset I get an attribute error (object not having a shape). (ellogon) dwessels@hpc2:~/VarMil_lightning$ python dlup_problem.py Traceback (most recent call last): File "/homes/dwessels/VarMil_lightning/dlup_problem.py", line 9, in <module> wsi = TiledROIsSlideImageDataset.from_standard_tiling( File "/homes/dwessels/environments/ellogon/lib/python3.9/site-packages/dlup/data/dataset.py", line 373, in from_standard_tiling return cls(path, [(grid, tile_size, mpp)], crop, mask, mask_threshold, annotations, transform) File "/homes/dwessels/environments/ellogon/lib/python3.9/site-packages/dlup/data/dataset.py", line 304, in __init__ super().__init__( File "/homes/dwessels/environments/ellogon/lib/python3.9/site-packages/dlup/data/dataset.py", line 190, in __init__ boolean_mask[i] = is_foreground(self.slide_image, mask, region, mask_threshold) File "/homes/dwessels/environments/ellogon/lib/python3.9/site-packages/dlup/background.py", line 234, in is_foreground mask_size = np.array(background_mask.shape[:2][::-1]) File "/homes/dwessels/environments/ellogon/lib/python3.9/site-packages/PIL/Image.py", line 548, in __getattr__ raise AttributeError(name) AttributeError: shape

To Reproduce

import imageio.v3 as iio
from dlup.data.dataset import TiledROIsSlideImageDataset, TilingMode

SLIDE_PATH = '/data/TIGER/tiger-training-data/wsitils/images/104S.tif'
MASK_PATH = '/data/TIGER/tiger-training-data/wsitils/tissue-masks/104S_tissue.tif'

mask = iio.imread(MASK_PATH)

wsi = TiledROIsSlideImageDataset.from_standard_tiling(
            path=SLIDE_PATH,
            mask=mask,
            mpp=0.5,
            tile_size=(256, 256),
            tile_overlap=(0, 0),
            tile_mode=TilingMode.overflow,
            crop=False,
        )

Expected behavior A clear and concise description of what you expected to happen.

Environment dlup version: dlup-0.2.0 How installed: pip install git+https://github.com/NKI-AI/dlup.git@caching Python version: Python 3.9.2 Operating System: Debian GNU/Linux 11

Additional context This problem occurred on the cashing-branch because there was said to work from that branch instead of main. If I run the same code example from the main-branch I got other errors even deeper within the code (error stated below). However, I do think that the bug stated above will also occur once the other bugs in main are fixed. Because, the erroring line of code is the same in both branches.

My proposed fix for the bug in the Cashing-branch is the following: Currently: line 234, in is_foreground --> mask_size = np.array(background_mask.shape[:2][::-1]) Solution: line 234, in is_foreground --> mask_size = np.array(background_mask).shape[:2][::-1]

So the parentheses should only go around 'background_mask'

jonasteuwen commented 2 years ago

Thanks. Will look into it. The caching branch is a bunch of experimental features. Will remove and split it into different commits.

jonasteuwen commented 2 years ago

This is still pending, but is soon on the list

jonasteuwen commented 2 years ago

Can you let me know if you still have this error in the current upstream version?

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days