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

🚸 Add Support for ignore_is_tiled_tiff in WSIReader.open() #807

Conversation

GeorgeBatch
Copy link
Contributor

@GeorgeBatch GeorgeBatch commented Apr 12, 2024

A possible solution for the issue #804

Checks if openslide is able to detect tiff format. In this case, OpenSlide opens the tiff file, otherwise falls back to tifffile or opencv.

@GeorgeBatch GeorgeBatch changed the title Add support for ignore_is_tiled_tiff in WSIReader.open() Add support for ignore_is_tiled_tiff in WSIReader.open() Apr 12, 2024
@Abdol Abdol added the bug Something isn't working label Apr 12, 2024
@shaneahmed
Copy link
Member

shaneahmed commented Apr 16, 2024

Thanks @GeorgeBatch. That's great. If you can provide us with a sample tif then we can upload this to our servers and set up automated tests. We can also investigate if there is another work around otherwise we can add tests and accept this PR.

Please can you provide a onedrive/dropbox/gdrive link to sample tif file and send it to tialab@dcs.warwick.ac.uk so we can upload to tiatest server. Please make sure that the test file is shared under BSD-3 license or an open license otherwise we will not be able to upload the file.

If you can find a file which is small in size that would be useful as it would mean tests run fast on GitHub actions.

@GeorgeBatch
Copy link
Contributor Author

@shaneahmed, I will try to get you access to one of our images as soon as possible. They come from an ongoing study so I might need to request a small dummy image scanned with the same scanner.

@shaneahmed
Copy link
Member

@shaneahmed, I will try to get you access to one of our images as soon as possible. They come from an ongoing study so I might need to request a small dummy image scanned with the same scanner.

A dummy slide would be great.

@shaneahmed shaneahmed added the enhancement New feature or request label Apr 19, 2024
@shaneahmed shaneahmed added this to the Release v1.6.0 milestone Apr 19, 2024
@shaneahmed
Copy link
Member

Updated branch with develop to fix integration with codecov.

Copy link

codecov bot commented Apr 29, 2024

Codecov Report

Attention: Patch coverage is 75.00000% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 99.87%. Comparing base (ec5a373) to head (5b488c7).

Files Patch % Lines
tiatoolbox/wsicore/wsireader.py 75.00% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #807      +/-   ##
===========================================
- Coverage    99.89%   99.87%   -0.03%     
===========================================
  Files           69       69              
  Lines         8574     8577       +3     
  Branches      1640     1642       +2     
===========================================
+ Hits          8565     8566       +1     
  Misses           1        1              
- Partials         8       10       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@GeorgeBatch
Copy link
Contributor Author

@shaneahmed, I will share a dummy slide with you as soon as I have it. Hopefully, this week.

@GeorgeBatch
Copy link
Contributor Author

@shaneahmed, I shared some samples through OneDrive with tialab@dcs.warwick.ac.uk. I made slides myself using flower petals so they can be shared without restrictions.

@GeorgeBatch
Copy link
Contributor Author

Should the argument ignore_is_tiled_tiff be also part of the __init__() method of the WSIReader class?

@shaneahmed
Copy link
Member

Should the argument ignore_is_tiled_tiff be also part of the __init__() method of the WSIReader class?

The best way would be automatically identify metadata from the file and then read. If that's not feasible then we can consider adding ignore_is_tiled_tiff as keyword argument. I have requested access to the files by email.

@shaneahmed
Copy link
Member

The test file is uploaded to https://tiatoolbox.dcs.warwick.ac.uk/sample_wsis/ventana_sample.tif

You can update https://github.com/TissueImageAnalytics/tiatoolbox/blob/develop/tiatoolbox/data/remote_samples.yaml to add this for tests.

`ventana_sample.tif` is a non-tiled tif file, which can be opened with `OpenSlideWSIReader`
@GeorgeBatch
Copy link
Contributor Author

GeorgeBatch commented May 1, 2024

@shaneahmed I added the file to the registry. I do not think Ventana scanners always output .tif files. I think it was just set up like that for us. So maybe it would be good to name it sample-ventana-tif

I have 2 questions about this code

if suffixes[-2:] in ([".ome", ".tiff"],):
return TIFFWSIReader(input_path, mpp=mpp, power=power)
if last_suffix in (".tif", ".tiff") and is_tiled_tiff(input_path):
try:
return OpenSlideWSIReader(input_path, mpp=mpp, power=power)
except openslide.OpenSlideError:
return TIFFWSIReader(input_path, mpp=mpp, power=power)

  1. What's the reason for not including .tif as a suffix to be processed with TIFFWSIReader on line 300?
  2. Why is OpenSlideWSIReader used as default instead of TIFFWSIReader, which is only called on if OpenSlideWSIReader fails?

I am unsure which of the cases to use if the flag ignore_is_tiled_tiff is not desirable.

“vendor” field in info is empty, so can’t use it for deciding which backend to use for WSIReader.

@GeorgeBatch
Copy link
Contributor Author

I tried adding the new slide to the fixture list with OpenSlideWSIreader as the expected reader:

        ...
        {
            "reader_class": OpenSlideWSIReader,
            "sample_key": "ventana-tif",
            "kwargs": {},
        },
        ...
    ids=[
        ...
        "OpenSlideReader (Ventana non-tiled tif)",
        ...

@pytest.fixture(
scope="module",
params=[
{
"reader_class": AnnotationStoreReader,
"sample_key": "annotation_store_svs_1",
"kwargs": {
"base_wsi_key": "svs-1-small",
"renderer": AnnotationRenderer(
"type",
COLOR_DICT,
),
"alpha": 0.5,
},
},
{
"reader_class": AnnotationStoreReader,
"sample_key": "annotation_store_svs_1",
"kwargs": {
"renderer": AnnotationRenderer(
"type",
COLOR_DICT,
blur_radius=3,
),
},
},
{
"reader_class": TIFFWSIReader,
"sample_key": "ome-brightfield-pyramid-1-small",
"kwargs": {},
},
{
"reader_class": DICOMWSIReader,
"sample_key": "dicom-1",
"kwargs": {},
},
{
"reader_class": NGFFWSIReader,
"sample_key": "ngff-1",
"kwargs": {},
},
{
"reader_class": OpenSlideWSIReader,
"sample_key": "svs-1-small",
"kwargs": {},
},
{
"reader_class": JP2WSIReader,
"sample_key": "jp2-omnyx-small",
"kwargs": {},
},
],
ids=[
"AnnotationReaderOverlaid",
"AnnotationReaderMaskOnly",
"TIFFReader",
"DICOMReader",
"NGFFWSIReader",
"OpenSlideWSIReader (Small SVS)",
"OmnyxJP2WSIReader",
],
)

But the test_base_open() test fails with

======================================================================================================================================== FAILURES ========================================================================================================================================
________________________________________________________________________________________________________________ test_base_open[OpenSlideReader (Ventana non-tiled tif)] _________________________________________________________________________________________________________________

wsi = <tiatoolbox.wsicore.wsireader.OpenSlideWSIReader object at 0x16e0c7a90>

    def test_base_open(wsi: WSIReader) -> None:
        """Checks that WSIReader.open detects the type correctly."""
        new_wsi = WSIReader.open(wsi.input_path)
>       assert type(new_wsi) is type(wsi)
E       AssertionError: assert <class 'tiatoolbox.wsicore.wsireader.VirtualWSIReader'> is <class 'tiatoolbox.wsicore.wsireader.OpenSlideWSIReader'>
E        +  where <class 'tiatoolbox.wsicore.wsireader.VirtualWSIReader'> = type(<tiatoolbox.wsicore.wsireader.VirtualWSIReader object at 0x3189f3050>)
E        +  and   <class 'tiatoolbox.wsicore.wsireader.OpenSlideWSIReader'> = type(<tiatoolbox.wsicore.wsireader.OpenSlideWSIReader object at 0x16e0c7a90>)

tests/test_wsireader.py:2611: AssertionError

because, unlike in test_wsireader_open(), I do not know how to pass the ignore_is_tiled_tiff argument within the pytest fixture (and I am not sure it should be passed), so the is_tiled_tiff check is performed, fails, and VirtualWSIReader is used.

    wsi = WSIReader.open(sample_ventana_tif, ignore_is_tiled_tiff=True)
    assert isinstance(wsi, wsireader.OpenSlideWSIReader)

@shaneahmed
Copy link
Member

@shaneahmed I added the file to the registry. I do not think Ventana scanners always output .tif files. I think it was just set up like that for us. So maybe it would be good to name it sample-ventana-tif

I have 2 questions about this code

if suffixes[-2:] in ([".ome", ".tiff"],):
return TIFFWSIReader(input_path, mpp=mpp, power=power)
if last_suffix in (".tif", ".tiff") and is_tiled_tiff(input_path):
try:
return OpenSlideWSIReader(input_path, mpp=mpp, power=power)
except openslide.OpenSlideError:
return TIFFWSIReader(input_path, mpp=mpp, power=power)

  1. What's the reason for not including .tif as a suffix to be processed with TIFFWSIReader on line 300?
  2. Why is OpenSlideWSIReader used as default instead of TIFFWSIReader, which is only called on if OpenSlideWSIReader fails?

I am unsure which of the cases to use if the flag ignore_is_tiled_tiff is not desirable.

“vendor” field in info is empty, so can’t use it for deciding which backend to use for WSIReader.

The answer to both your questions is the same. When we wrote the code tifffile had not good support for WSIs. It still has very limited documentation. OpenSlide is preferred library to read WSIs by researchers. So most researchers will find it easy to port their code to tiatoolbox and integrate into their pipelines. If OpenSlide fails then the fallback option is tifffile.

@shaneahmed
Copy link
Member

shaneahmed commented May 2, 2024

I tried adding the new slide to the fixture list with OpenSlideWSIreader as the expected reader:

        ...
        {
            "reader_class": OpenSlideWSIReader,
            "sample_key": "ventana-tif",
            "kwargs": {},
        },
        ...
    ids=[
        ...
        "OpenSlideReader (Ventana non-tiled tif)",
        ...

@pytest.fixture(
scope="module",
params=[
{
"reader_class": AnnotationStoreReader,
"sample_key": "annotation_store_svs_1",
"kwargs": {
"base_wsi_key": "svs-1-small",
"renderer": AnnotationRenderer(
"type",
COLOR_DICT,
),
"alpha": 0.5,
},
},
{
"reader_class": AnnotationStoreReader,
"sample_key": "annotation_store_svs_1",
"kwargs": {
"renderer": AnnotationRenderer(
"type",
COLOR_DICT,
blur_radius=3,
),
},
},
{
"reader_class": TIFFWSIReader,
"sample_key": "ome-brightfield-pyramid-1-small",
"kwargs": {},
},
{
"reader_class": DICOMWSIReader,
"sample_key": "dicom-1",
"kwargs": {},
},
{
"reader_class": NGFFWSIReader,
"sample_key": "ngff-1",
"kwargs": {},
},
{
"reader_class": OpenSlideWSIReader,
"sample_key": "svs-1-small",
"kwargs": {},
},
{
"reader_class": JP2WSIReader,
"sample_key": "jp2-omnyx-small",
"kwargs": {},
},
],
ids=[
"AnnotationReaderOverlaid",
"AnnotationReaderMaskOnly",
"TIFFReader",
"DICOMReader",
"NGFFWSIReader",
"OpenSlideWSIReader (Small SVS)",
"OmnyxJP2WSIReader",
],
)

But the test_base_open() test fails with

======================================================================================================================================== FAILURES ========================================================================================================================================
________________________________________________________________________________________________________________ test_base_open[OpenSlideReader (Ventana non-tiled tif)] _________________________________________________________________________________________________________________

wsi = <tiatoolbox.wsicore.wsireader.OpenSlideWSIReader object at 0x16e0c7a90>

    def test_base_open(wsi: WSIReader) -> None:
        """Checks that WSIReader.open detects the type correctly."""
        new_wsi = WSIReader.open(wsi.input_path)
>       assert type(new_wsi) is type(wsi)
E       AssertionError: assert <class 'tiatoolbox.wsicore.wsireader.VirtualWSIReader'> is <class 'tiatoolbox.wsicore.wsireader.OpenSlideWSIReader'>
E        +  where <class 'tiatoolbox.wsicore.wsireader.VirtualWSIReader'> = type(<tiatoolbox.wsicore.wsireader.VirtualWSIReader object at 0x3189f3050>)
E        +  and   <class 'tiatoolbox.wsicore.wsireader.OpenSlideWSIReader'> = type(<tiatoolbox.wsicore.wsireader.OpenSlideWSIReader object at 0x16e0c7a90>)

tests/test_wsireader.py:2611: AssertionError

because, unlike in test_wsireader_open(), I do not know how to pass the ignore_is_tiled_tiff argument within the pytest fixture (and I am not sure it should be passed), so the is_tiled_tiff check is performed, fails, and VirtualWSIReader is used.

    wsi = WSIReader.open(sample_ventana_tif, ignore_is_tiled_tiff=True)
    assert isinstance(wsi, wsireader.OpenSlideWSIReader)

After a bit of play around with your image. I think I have a more minimalistic solution which will not change the API. If you make the following change in the code, then we do not need a flag ignore_is_tiled_tiff.

If you change the line 309 with this code, tiatoolbox should work on ventanna scanners.

        if last_suffix in (".tif", ".tiff"):
            if openslide.OpenSlide.detect_format(input_path) is not None:
                return OpenSlideWSIReader(input_path, mpp=mpp, power=power)
            if is_tiled_tiff(input_path):
                return TIFFWSIReader(input_path, mpp=mpp, power=power)

If you still want to force TIFFWSIReader then there are two ways:

  1. Use TIFFWSIReader() to open the image.
  2. We change the API to allow specifying which class to open the file. But it would be redundant considering we can open an image directly by specifying a class.

Some tests may fail after this change but we can fix those easily, I think.

@GeorgeBatch
Copy link
Contributor Author

Just replacing the old code with your proposed code results in the following error:

========================================================================================== FAILURES ===========================================================================================
__________________________________________________________________________________ test_tiled_tiff_tifffile ___________________________________________________________________________________

remote_sample = <function remote_sample.<locals>.__remote_sample at 0x30d98fce0>

    def test_tiled_tiff_tifffile(remote_sample: Callable) -> None:
        """Test fallback to tifffile for files which openslide cannot read.
    
        E.G. tiled tiffs with JPEG XL compression.
    
        """
        sample_path = remote_sample("tiled-tiff-1-small-jp2k")
>       wsi = wsireader.WSIReader.open(sample_path)

tests/test_wsireader.py:2005: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tiatoolbox/wsicore/wsireader.py:305: in open
    return OpenSlideWSIReader(input_path, mpp=mpp, power=power)
tiatoolbox/wsicore/wsireader.py:1663: in __init__
    self.openslide_wsi = openslide.OpenSlide(filename=str(self.input_path))
/Users/gbatch/opt/miniconda3/envs/tiatoolbox-dev/lib/python3.11/site-packages/openslide/__init__.py:179: in __init__
    self._osr = lowlevel.open(str(filename))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

result = 5811949952, _func = <_FuncPtr object at 0x30c3041d0>
_args = ('/private/var/folders/lz/602r_tbj50jf1yw4jnmxbg9r0000gn/T/pytest-of-gbatch/pytest-17/data0/CMU-1-Small-Region.jp2k.tiff',)

    def _check_open(result, _func, _args):
        if result is None:
            raise OpenSlideUnsupportedFormatError("Unsupported or missing image file")
        slide = _OpenSlide(c_void_p(result))
        err = get_error(slide)
        if err is not None:
>           raise OpenSlideError(err)
E           openslide.lowlevel.OpenSlideError: Unsupported TIFF compression: 33004

/Users/gbatch/opt/miniconda3/envs/tiatoolbox-dev/lib/python3.11/site-packages/openslide/lowlevel.py:207: OpenSlideError
====================================================================================== warnings summary =======================================================================================
../../../../../opt/miniconda3/envs/tiatoolbox-dev/lib/python3.11/site-packages/_pytest/config/__init__.py:1439
  /Users/gbatch/opt/miniconda3/envs/tiatoolbox-dev/lib/python3.11/site-packages/_pytest/config/__init__.py:1439: PytestConfigWarning: Unknown config option: collect_ignore
  
    self._warn_or_fail_if_strict(f"Unknown config option: {key}\n")

tests/test_wsireader.py::test_convert_resolution_units
  /Users/gbatch/Developer/projects/current/comp-path/tiatoolbox/tiatoolbox/wsicore/wsireader.py:888: RuntimeWarning: divide by zero encountered in scalar divide
    output_dict["baseline"] = baseline_mpp[0] / output_dict["mpp"][0]

tests/test_wsireader.py::test_tissue_mask_otsu
  /Users/gbatch/opt/miniconda3/envs/tiatoolbox-dev/lib/python3.11/site-packages/defusedxml/__init__.py:30: DeprecationWarning: defusedxml.cElementTree is deprecated, import from defusedxml.ElementTree instead.
    from . import cElementTree

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=================================================================================== short test summary info ===================================================================================
FAILED tests/test_wsireader.py::test_tiled_tiff_tifffile - openslide.lowlevel.OpenSlideError: Unsupported TIFF compression: 33004

The image 'CMU-1-Small-Region.jp2k.tiff' passes the openslide.OpenSlide.detect_format(input_path) check, but openslide fails to open it.

            if openslide.OpenSlide.detect_format(input_path) is not None:
                return OpenSlideWSIReader(input_path, mpp=mpp, power=power)

To mitigate this, a try-except block can be used:

        if last_suffix in (".tif", ".tiff"):
            if openslide.OpenSlide.detect_format(input_path) is not None:
                try:
                    return OpenSlideWSIReader(input_path, mpp=mpp, power=power)
                except openslide.OpenSlideError:
                    pass
            if is_tiled_tiff(input_path):
                return TIFFWSIReader(input_path, mpp=mpp, power=power)

To preserve as much of the original behaviour as possible, these lines need to be outside of the except block.

            if is_tiled_tiff(input_path):
                return TIFFWSIReader(input_path, mpp=mpp, power=power)

@GeorgeBatch
Copy link
Contributor Author

GeorgeBatch commented May 3, 2024

All tests pass with this change. But this change resulted in some failed ruff checks - the WSIReader.open() becomes too complex. So I used git commit --no-verify so you can see the changes.

tiatoolbox/wsicore/wsireader.py:231:9: PLR0912 Too many branches (14 > 12)
tiatoolbox/wsicore/wsireader.py:231:9: C901 `open` is too complex (15 > 14)
Found 2 errors.

Should I add PLR0912 and C901 to the noqa of open? I know it's not a good strategy to ignore linters whenever they complain.
Now:

    def open(  # noqa: PLR0911

Can be:

    def open(  # noqa: PLR0911, PLR0912, C901

OpenSlideWSIReader is tried if OpenSlide can detect the format of an input path (no requirement for the tiff to be tiled before trying to open with openslide). For tiled tiff files, TIFFWSIReader is used as backup.
@shaneahmed
Copy link
Member

All tests pass with this change. But this change resulted in some failed ruff checks - the WSIReader.open() becomes too complex. So I used git commit --no-verify so you can see the changes.

tiatoolbox/wsicore/wsireader.py:231:9: PLR0912 Too many branches (14 > 12)
tiatoolbox/wsicore/wsireader.py:231:9: C901 `open` is too complex (15 > 14)
Found 2 errors.

Should I add PLR0912 and C901 to the noqa of open? I know it's not a good strategy to ignore linters whenever they complain. Now:

    def open(  # noqa: PLR0911

Can be:

    def open(  # noqa: PLR0911, PLR0912, C901

Please go ahead and add these. I can fix these later in a separate PR.

code complexity in `WSIReader.open()` should probably be addressed later
@shaneahmed
Copy link
Member

Just replacing the old code with your proposed code results in the following error:

========================================================================================== FAILURES ===========================================================================================
__________________________________________________________________________________ test_tiled_tiff_tifffile ___________________________________________________________________________________

remote_sample = <function remote_sample.<locals>.__remote_sample at 0x30d98fce0>

    def test_tiled_tiff_tifffile(remote_sample: Callable) -> None:
        """Test fallback to tifffile for files which openslide cannot read.
    
        E.G. tiled tiffs with JPEG XL compression.
    
        """
        sample_path = remote_sample("tiled-tiff-1-small-jp2k")
>       wsi = wsireader.WSIReader.open(sample_path)

tests/test_wsireader.py:2005: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tiatoolbox/wsicore/wsireader.py:305: in open
    return OpenSlideWSIReader(input_path, mpp=mpp, power=power)
tiatoolbox/wsicore/wsireader.py:1663: in __init__
    self.openslide_wsi = openslide.OpenSlide(filename=str(self.input_path))
/Users/gbatch/opt/miniconda3/envs/tiatoolbox-dev/lib/python3.11/site-packages/openslide/__init__.py:179: in __init__
    self._osr = lowlevel.open(str(filename))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

result = 5811949952, _func = <_FuncPtr object at 0x30c3041d0>
_args = ('/private/var/folders/lz/602r_tbj50jf1yw4jnmxbg9r0000gn/T/pytest-of-gbatch/pytest-17/data0/CMU-1-Small-Region.jp2k.tiff',)

    def _check_open(result, _func, _args):
        if result is None:
            raise OpenSlideUnsupportedFormatError("Unsupported or missing image file")
        slide = _OpenSlide(c_void_p(result))
        err = get_error(slide)
        if err is not None:
>           raise OpenSlideError(err)
E           openslide.lowlevel.OpenSlideError: Unsupported TIFF compression: 33004

/Users/gbatch/opt/miniconda3/envs/tiatoolbox-dev/lib/python3.11/site-packages/openslide/lowlevel.py:207: OpenSlideError
====================================================================================== warnings summary =======================================================================================
../../../../../opt/miniconda3/envs/tiatoolbox-dev/lib/python3.11/site-packages/_pytest/config/__init__.py:1439
  /Users/gbatch/opt/miniconda3/envs/tiatoolbox-dev/lib/python3.11/site-packages/_pytest/config/__init__.py:1439: PytestConfigWarning: Unknown config option: collect_ignore
  
    self._warn_or_fail_if_strict(f"Unknown config option: {key}\n")

tests/test_wsireader.py::test_convert_resolution_units
  /Users/gbatch/Developer/projects/current/comp-path/tiatoolbox/tiatoolbox/wsicore/wsireader.py:888: RuntimeWarning: divide by zero encountered in scalar divide
    output_dict["baseline"] = baseline_mpp[0] / output_dict["mpp"][0]

tests/test_wsireader.py::test_tissue_mask_otsu
  /Users/gbatch/opt/miniconda3/envs/tiatoolbox-dev/lib/python3.11/site-packages/defusedxml/__init__.py:30: DeprecationWarning: defusedxml.cElementTree is deprecated, import from defusedxml.ElementTree instead.
    from . import cElementTree

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=================================================================================== short test summary info ===================================================================================
FAILED tests/test_wsireader.py::test_tiled_tiff_tifffile - openslide.lowlevel.OpenSlideError: Unsupported TIFF compression: 33004

The image 'CMU-1-Small-Region.jp2k.tiff' passes the openslide.OpenSlide.detect_format(input_path) check, but openslide fails to open it.

            if openslide.OpenSlide.detect_format(input_path) is not None:
                return OpenSlideWSIReader(input_path, mpp=mpp, power=power)

To mitigate this, a try-except block can be used:

        if last_suffix in (".tif", ".tiff"):
            if openslide.OpenSlide.detect_format(input_path) is not None:
                try:
                    return OpenSlideWSIReader(input_path, mpp=mpp, power=power)
                except openslide.OpenSlideError:
                    pass
            if is_tiled_tiff(input_path):
                return TIFFWSIReader(input_path, mpp=mpp, power=power)

To preserve as much of the original behaviour as possible, these lines need to be outside of the except block.

            if is_tiled_tiff(input_path):
                return TIFFWSIReader(input_path, mpp=mpp, power=power)

I am OK with this solution. However, I think we should not pass

        if last_suffix in (".tif", ".tiff"):
            if openslide.OpenSlide.detect_format(input_path) is not None:
                try:
                    return OpenSlideWSIReader(input_path, mpp=mpp, power=power)
                except openslide.OpenSlideError:
                    pass
            if is_tiled_tiff(input_path):
                return TIFFWSIReader(input_path, mpp=mpp, power=power)
        if last_suffix in (".tif", ".tiff"):
            if openslide.OpenSlide.detect_format(input_path) is not None:
                try:
                    return OpenSlideWSIReader(input_path, mpp=mpp, power=power)
                except openslide.OpenSlideError:
                    if is_tiled_tiff(input_path):
                        return TIFFWSIReader(input_path, mpp=mpp, power=power)

@GeorgeBatch
Copy link
Contributor Author

I considered this option. My argument against was that it will make the logic different from what it was.

Before, to be opened with TIFFWSIReader, the file needed to satisfy

  1. last_suffix in (".tif", ".tiff")
  2. is_tiled_tiff(input_path)
  3. OpenSlideWSIReader failed with openslide.OpenSlide error

This behaviour is preserved in the current option with pass.

If we put

            if is_tiled_tiff(input_path):
                return TIFFWSIReader(input_path, mpp=mpp, power=power)

into the except statement instead of the pass, to be opened with TIFFWSIReader, the file will still need to satisfy the 3 criteria as before, but in addition will need to satisfy openslide.OpenSlide.detect_format(input_path) is not None.

So, for a slide that has a non-detectable format with OpenSlide (openslide.OpenSlide.detect_format(input_path)), we will not even try to open it with TIFFWSIReader.

@GeorgeBatch
Copy link
Contributor Author

GeorgeBatch commented May 3, 2024

Why is this check needed before trying OpenSlide?

            if openslide.OpenSlide.detect_format(input_path) is not None:

What do you think about the option below? This option leaves the same 3 requirements for using TIFFWSIReader as in the current version on the develop branch. Trying to open with OpenSlideWSIReader becomes easier since the file does not need to satisfy is_tiled_tiff(input_path).

        if last_suffix in (".tif", ".tiff"):
            try:
                return OpenSlideWSIReader(input_path, mpp=mpp, power=power)
            except openslide.OpenSlideError:
                if is_tiled_tiff(input_path):
                    return TIFFWSIReader(input_path, mpp=mpp, power=power)

This version passes all the existing tests.

@shaneahmed
Copy link
Member

shaneahmed commented May 3, 2024

if openslide.OpenSlide.detect_format(input_path) is not None:

OpenSlide will still be able to open regular tiff which is not a WSI. In this case, metadata will be missing and we may get unintentional errors which are not traceable. Regular tiff file should be opened by VirtualWSIReader which can deal with regular images.

Copy link
Member

@shaneahmed shaneahmed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @GeorgeBatch for your contribution. This looks good to me now.

There is an issue with test coverage which can be fulfilled by regular tiff files. I will create a separate PR for this. I will also create a separate PR for complexity issue.

@shaneahmed shaneahmed merged commit c3ae5d5 into TissueImageAnalytics:develop May 3, 2024
12 of 14 checks passed
@GeorgeBatch GeorgeBatch deleted the enhance-ignore-tiled-tiff-check branch May 3, 2024 18:32
@GeorgeBatch GeorgeBatch restored the enhance-ignore-tiled-tiff-check branch May 3, 2024 18:35
@GeorgeBatch GeorgeBatch deleted the enhance-ignore-tiled-tiff-check branch May 3, 2024 18:38
@shaneahmed shaneahmed mentioned this pull request Dec 10, 2024
@shaneahmed shaneahmed changed the title Add support for ignore_is_tiled_tiff in WSIReader.open() 👷 Add support for ignore_is_tiled_tiff in WSIReader.open() Dec 10, 2024
@shaneahmed shaneahmed changed the title 👷 Add support for ignore_is_tiled_tiff in WSIReader.open() 🚸 Add Support for ignore_is_tiled_tiff in WSIReader.open() Dec 10, 2024
shaneahmed added a commit that referenced this pull request Dec 12, 2024
## TIAToolbox v1.6.0 (2024-12-12)

### Major Updates and Feature Improvements

- **Foundation Models Support via `timm` API** (#856, contributed by @GeorgeBatch)
  - Introduced `TimmBackbone` for running additional PyTorch Image Models.
  - Tested models include `UNI`, `Prov-GigaPath`, and `H-optimus-0`.
  - Added an example notebook demonstrating feature extraction with foundation models.
  - `timm` added as a dependency.
- **Performance Enhancements with `torch.compile`** (#716)
  - Improved performance on newer GPUs using `torch.compile`.
- **Multichannel Input Support in `WSIReader`** (#742)
- **AnnotationStore Filtering for Patch Extraction** (#822)
- **Python 3.12 Support**
- **Deprecation of Python 3.8 Support**
- **CLI Response Time Improvements** (#795)

### API Changes

- **Device Specification Update** (#882)
  - Replaced `has_gpu` with `device` for specifying GPU or CPU usage, aligning with PyTorch's `Model.to()` functionality.
- **Windows Compatibility Enhancement** (#769)
  - Replaced `POWER` with explicit multiplication.

### Bug Fixes and Other Changes

- **TIFFWSIReader Bound Reading Adjustment** (#777)
  - Fixed `read_bound` to use adjusted bounds.
  - Reduced code complexity in `WSIReader` (#814).
- **Annotation Rendering Fixes** (#813)
  - Corrected rendering of annotations with holes.
- **Non-Tiled TIFF Support in `WSIReader`** (#807, contributed by @GeorgeBatch)
- **HoVer-Net Documentation Update** (#751)
  - Corrected class output information.
- **Citation File Fix for `cffconvert`** (#869, contributed by @Alon-Alexander)
- **Bokeh Compatibility Updates**
  - Updated `bokeh_app` for compatibility with `bokeh>=3.5.0`.
  - Switched from `size` to `radius` for `bokeh>3.4.0` compatibility (#796).
- **JSON Extraction Fixes** (#772)
  - Restructured SQL expression construction for JSON properties with dots in keys.
- **VahadaneExtractor Warning** (#871)
  - Added warning due to changes in `scikit-learn>0.23.0` dictionary learning (#382).
- **PatchExtractor Error Message Refinement** (#883)
- **Immutable Output Fix in `WSIReader`** (#850)

### Development-Related Changes

- **Mypy Checks Added**
  - Applied to `utils`, `tools`, `data`, `annotation`, and `cli/common`.
- **ReadTheDocs PDF Build Deprecation**
- **Formatter Update**
  - Replaced `black` with `ruff-format`.
- **Dependency Removal**
  - Removed `jinja2`.
- **Test Environment Update**
  - Updated to `Ubuntu 24.04`.
- **Conda Environment Workflow Update**
  - Implemented `micromamba` setup.
- **Codecov Reporting Fix** (#811)
  **Full Changelog:** v1.5.1...v1.6.0

---------

Co-authored-by: John Pocock <John-P@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Adam Shephard <39619155+adamshephard@users.noreply.github.com>
Co-authored-by: Mark Eastwood <20169086+measty@users.noreply.github.com>
Co-authored-by: Mostafa Jahanifar <74412979+mostafajahanifar@users.noreply.github.com>
Co-authored-by: Simon Graham <20071401+simongraham@users.noreply.github.com>
Co-authored-by: Abdol A <u2271662@live.warwick.ac.uk>
Co-authored-by: Jiaqi-Lv <60471431+Jiaqi-Lv@users.noreply.github.com>
Co-authored-by: Dmitrii Blaginin <blaginin@mbp.lan>
Co-authored-by: behnazelhaminia <30952176+behnazelhaminia@users.noreply.github.com>
Co-authored-by: George Batchkala <46561186+GeorgeBatch@users.noreply.github.com>
Co-authored-by: vqdang <24943262+vqdang@users.noreply.github.com>
Co-authored-by: Jiaqi Lv <lvjiaqi9@gmail.com>
Co-authored-by: Alon Alexander <alon008@gmail.com>
@shaneahmed shaneahmed mentioned this pull request Dec 12, 2024
shaneahmed added a commit that referenced this pull request Dec 12, 2024
## TIAToolbox v1.6.0 (2024-12-12)

### Major Updates and Feature Improvements

- **Foundation Models Support via `timm` API** (#856, contributed by @GeorgeBatch)
  - Introduced `TimmBackbone` for running additional PyTorch Image Models.
  - Tested models include `UNI`, `Prov-GigaPath`, and `H-optimus-0`.
  - Added an example notebook demonstrating feature extraction with foundation models.
  - `timm` added as a dependency.
- **Performance Enhancements with `torch.compile`** (#716)
  - Improved performance on newer GPUs using `torch.compile`.
- **Multichannel Input Support in `WSIReader`** (#742)
- **AnnotationStore Filtering for Patch Extraction** (#822)
- **Python 3.12 Support**
- **Deprecation of Python 3.8 Support**
- **CLI Response Time Improvements** (#795)

### API Changes

- **Device Specification Update** (#882)
  - Replaced `has_gpu` with `device` for specifying GPU or CPU usage, aligning with PyTorch's `Model.to()` functionality.
- **Windows Compatibility Enhancement** (#769)
  - Replaced `POWER` with explicit multiplication.

### Bug Fixes and Other Changes

- **TIFFWSIReader Bound Reading Adjustment** (#777)
  - Fixed `read_bound` to use adjusted bounds.
  - Reduced code complexity in `WSIReader` (#814).
- **Annotation Rendering Fixes** (#813)
  - Corrected rendering of annotations with holes.
- **Non-Tiled TIFF Support in `WSIReader`** (#807, contributed by @GeorgeBatch)
- **HoVer-Net Documentation Update** (#751)
  - Corrected class output information.
- **Citation File Fix for `cffconvert`** (#869, contributed by @Alon-Alexander)
- **Bokeh Compatibility Updates**
  - Updated `bokeh_app` for compatibility with `bokeh>=3.5.0`.
  - Switched from `size` to `radius` for `bokeh>3.4.0` compatibility (#796).
- **JSON Extraction Fixes** (#772)
  - Restructured SQL expression construction for JSON properties with dots in keys.
- **VahadaneExtractor Warning** (#871)
  - Added warning due to changes in `scikit-learn>0.23.0` dictionary learning (#382).
- **PatchExtractor Error Message Refinement** (#883)
- **Immutable Output Fix in `WSIReader`** (#850)

### Development-Related Changes

- **Mypy Checks Added**
  - Applied to `utils`, `tools`, `data`, `annotation`, and `cli/common`.
- **ReadTheDocs PDF Build Deprecation**
- **Formatter Update**
  - Replaced `black` with `ruff-format`.
- **Dependency Removal**
  - Removed `jinja2`.
- **Test Environment Update**
  - Updated to `Ubuntu 24.04`.
- **Conda Environment Workflow Update**
  - Implemented `micromamba` setup.
- **Codecov Reporting Fix** (#811)
  **Full Changelog:** v1.5.1...v1.6.0
mbasheer04 added a commit to mbasheer04/tiatoolbox that referenced this pull request Jan 24, 2025
commit d315a5f415542890f351ddb07c771d62c278c2f2
Merge: dab2693 1a27178
Author: Musraf Basheer <Musraf.Basheer@warwick.ac.uk>
Date:   Fri Jan 24 15:07:28 2025 +0000

    Merge branch 'sam-architecture' into develop

commit dab2693
Merge: ca37400 8ff4f5e
Author: mbasheer04 <78800844+mbasheer04@users.noreply.github.com>
Date:   Fri Jan 24 15:04:28 2025 +0000

    Merge branch 'TissueImageAnalytics:develop' into develop

commit 1a27178
Merge: 3b51acb 8ff4f5e
Author: mbasheer04 <78800844+mbasheer04@users.noreply.github.com>
Date:   Fri Jan 24 14:57:22 2025 +0000

    Merge branch 'TissueImageAnalytics:develop' into sam-architecture

commit 3b51acb
Author: Musraf Basheer <Musraf.Basheer@warwick.ac.uk>
Date:   Fri Jan 24 14:53:06 2025 +0000

    Improved Engine

commit 8ff4f5e
Author: Mark Eastwood <20169086+measty@users.noreply.github.com>
Date:   Thu Jan 23 10:03:43 2025 +0000

    📌 Pin `zarr<3.0.0` (TissueImageAnalytics#905)

    - `zarr>3.0.0` is not compatible yet

commit 46d30f2
Merge: 1e136c5 ca37400
Author: Musraf Basheer <Musraf.Basheer@warwick.ac.uk>
Date:   Fri Jan 17 14:22:18 2025 +0000

    Merge branch 'develop' into sam-architecture

commit ca37400
Merge: 32cae0b f385ced
Author: mbasheer04 <78800844+mbasheer04@users.noreply.github.com>
Date:   Fri Jan 17 14:18:47 2025 +0000

    Merge pull request #1 from TissueImageAnalytics/develop

    Merge develop

commit 1e136c5
Merge: 47a2190 bb9399d
Author: Musraf Basheer <Musraf.Basheer@warwick.ac.uk>
Date:   Fri Jan 17 14:12:52 2025 +0000

    Merge branch 'sam-architecture' of https://github.com/mbasheer04/tiatoolbox into sam-architecture

commit 47a2190
Author: Musraf Basheer <Musraf.Basheer@warwick.ac.uk>
Date:   Fri Jan 17 14:08:11 2025 +0000

    Improved engine & added unit tests

commit f385ced
Author: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date:   Fri Jan 10 12:04:52 2025 +0000

    :technologist: pre-commit autoupdate (TissueImageAnalytics#902)

    * 🧑‍💻 pre-commit autoupdate

    updates:
    - [github.com/executablebooks/mdformat: 0.7.19 → 0.7.21](hukkin/mdformat@0.7.19...0.7.21)
    - [github.com/astral-sh/ruff-pre-commit: v0.8.2 → v0.8.6](astral-sh/ruff-pre-commit@v0.8.2...v0.8.6)

    * [pre-commit.ci] auto fixes from pre-commit.com hooks

    for more information, see https://pre-commit.ci

    ---------

    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

commit 0ddd2b1
Author: Shan E Ahmed Raza <13048456+shaneahmed@users.noreply.github.com>
Date:   Thu Dec 12 14:45:39 2024 +0000

    🔖 Release 1.6.0 (TissueImageAnalytics#898)

    ## TIAToolbox v1.6.0 (2024-12-12)

    ### Major Updates and Feature Improvements

    - **Foundation Models Support via `timm` API** (TissueImageAnalytics#856, contributed by @GeorgeBatch)
      - Introduced `TimmBackbone` for running additional PyTorch Image Models.
      - Tested models include `UNI`, `Prov-GigaPath`, and `H-optimus-0`.
      - Added an example notebook demonstrating feature extraction with foundation models.
      - `timm` added as a dependency.
    - **Performance Enhancements with `torch.compile`** (TissueImageAnalytics#716)
      - Improved performance on newer GPUs using `torch.compile`.
    - **Multichannel Input Support in `WSIReader`** (TissueImageAnalytics#742)
    - **AnnotationStore Filtering for Patch Extraction** (TissueImageAnalytics#822)
    - **Python 3.12 Support**
    - **Deprecation of Python 3.8 Support**
    - **CLI Response Time Improvements** (TissueImageAnalytics#795)

    ### API Changes

    - **Device Specification Update** (TissueImageAnalytics#882)
      - Replaced `has_gpu` with `device` for specifying GPU or CPU usage, aligning with PyTorch's `Model.to()` functionality.
    - **Windows Compatibility Enhancement** (TissueImageAnalytics#769)
      - Replaced `POWER` with explicit multiplication.

    ### Bug Fixes and Other Changes

    - **TIFFWSIReader Bound Reading Adjustment** (TissueImageAnalytics#777)
      - Fixed `read_bound` to use adjusted bounds.
      - Reduced code complexity in `WSIReader` (TissueImageAnalytics#814).
    - **Annotation Rendering Fixes** (TissueImageAnalytics#813)
      - Corrected rendering of annotations with holes.
    - **Non-Tiled TIFF Support in `WSIReader`** (TissueImageAnalytics#807, contributed by @GeorgeBatch)
    - **HoVer-Net Documentation Update** (TissueImageAnalytics#751)
      - Corrected class output information.
    - **Citation File Fix for `cffconvert`** (TissueImageAnalytics#869, contributed by @Alon-Alexander)
    - **Bokeh Compatibility Updates**
      - Updated `bokeh_app` for compatibility with `bokeh>=3.5.0`.
      - Switched from `size` to `radius` for `bokeh>3.4.0` compatibility (TissueImageAnalytics#796).
    - **JSON Extraction Fixes** (TissueImageAnalytics#772)
      - Restructured SQL expression construction for JSON properties with dots in keys.
    - **VahadaneExtractor Warning** (TissueImageAnalytics#871)
      - Added warning due to changes in `scikit-learn>0.23.0` dictionary learning (TissueImageAnalytics#382).
    - **PatchExtractor Error Message Refinement** (TissueImageAnalytics#883)
    - **Immutable Output Fix in `WSIReader`** (TissueImageAnalytics#850)

    ### Development-Related Changes

    - **Mypy Checks Added**
      - Applied to `utils`, `tools`, `data`, `annotation`, and `cli/common`.
    - **ReadTheDocs PDF Build Deprecation**
    - **Formatter Update**
      - Replaced `black` with `ruff-format`.
    - **Dependency Removal**
      - Removed `jinja2`.
    - **Test Environment Update**
      - Updated to `Ubuntu 24.04`.
    - **Conda Environment Workflow Update**
      - Implemented `micromamba` setup.
    - **Codecov Reporting Fix** (TissueImageAnalytics#811)
      **Full Changelog:** TissueImageAnalytics/tiatoolbox@v1.5.1...v1.6.0

commit a38d95f
Author: Shan E Ahmed Raza <13048456+shaneahmed@users.noreply.github.com>
Date:   Thu Dec 5 17:14:20 2024 +0000

    [skip ci] 🐛 Fix `benchmarks/annotation_store.ipynb` (TissueImageAnalytics#894)

    - Fix `benchmarks/annotation_store.ipynb` errors

commit 6b214fe
Author: adamshephard <39619155+adamshephard@users.noreply.github.com>
Date:   Tue Dec 3 14:09:33 2024 +0000

    📝 Add Example Notebook for Foundation Models (TissueImageAnalytics#887)

    - Add Example Notebook to explain how to use Foundation Models from `timm` module in TIAToolbox.

    ---------

    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
    Co-authored-by: Shan E Ahmed Raza <13048456+shaneahmed@users.noreply.github.com>

commit 442bd3f
Author: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date:   Tue Dec 3 09:40:40 2024 +0000

    :technologist: pre-commit autoupdate (TissueImageAnalytics#891)

    <!--pre-commit.ci start-->
    updates:
    - [github.com/executablebooks/mdformat: 0.7.18 → 0.7.19](hukkin/mdformat@0.7.18...0.7.19)

    ---------

    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
    Co-authored-by: Shan E Ahmed Raza <13048456+shaneahmed@users.noreply.github.com>

commit 741463c
Author: Shan E Ahmed Raza <13048456+shaneahmed@users.noreply.github.com>
Date:   Mon Dec 2 22:45:05 2024 +0000

    :pushpin: Update `ruff` Version to `v0.8.1` (TissueImageAnalytics#890)

    - Update `ruff` Version to `v0.8.1`

    ---------

    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

commit 9a62c10
Author: Shan E Ahmed Raza <13048456+shaneahmed@users.noreply.github.com>
Date:   Mon Dec 2 17:11:39 2024 +0000

    [skip ci] :memo: Update Jupyter Notebooks for Release `v1.6.0` (TissueImageAnalytics#885)

    - Update Jupyter Notebooks for the New Release
    - Fix issues with API changes e.g., device instead of ON_GPU flag.

commit 4a1940d
Author: Shan E Ahmed Raza <13048456+shaneahmed@users.noreply.github.com>
Date:   Fri Nov 29 16:13:37 2024 +0000

    :technologist: `torch.compile` is not compatible with Windows. (TissueImageAnalytics#888)

    - `torch.compile` is not currently compatible with Windows. See pytorch/pytorch#122094

commit 5f1cecb
Author: Jiaqi-Lv <60471431+Jiaqi-Lv@users.noreply.github.com>
Date:   Fri Nov 29 14:37:39 2024 +0000

    🧑‍💻 Refine `PatchExtractor` Error Message (TissueImageAnalytics#883)

    - Fix Misleading error message TissueImageAnalytics#881

commit 5beb119
Author: Musraf Basheer <Musraf.Basheer@warwick.ac.uk>
Date:   Tue Nov 26 18:47:14 2024 +0000

    Initialised SAM Engine

commit bb9399d
Author: mbasheer04 <78800844+mbasheer04@users.noreply.github.com>
Date:   Fri Nov 22 19:26:45 2024 +0000

    Created using Colab

commit ca13e7f
Author: Shan E Ahmed Raza <13048456+shaneahmed@users.noreply.github.com>
Date:   Thu Nov 21 22:28:44 2024 +0000

    ♻️ Update Changes from New Engine Design (TissueImageAnalytics#882)

    - Add changes from New engine design TissueImageAnalytics#578. This will not only simplify the PR but also keep the main repo up to date.
    - Refactor `model_to` to `model_abc`
    - Instead of `on_gpu` use `device` as an input in line with `PyTorch`.
    - `infer_batch` uses `device` as an input instead of `on_gpu`

commit 91ca877
Merge: 1e27436 32cae0b
Author: mbasheer04 <bmusraf1@gmail.com>
Date:   Thu Nov 21 21:03:41 2024 +0000

    Merge branch 'develop' of https://github.com/TissueImageAnalytics/tiatoolbox into sam-architecture

commit 1e27436
Author: mbasheer04 <bmusraf1@gmail.com>
Date:   Thu Nov 21 21:00:34 2024 +0000

    Implementing architecture for full-image segmentation

commit 32cae0b
Author: Abdol <a@fkrtech.com>
Date:   Fri Nov 15 20:29:34 2024 +0000

    ⚡️Add `torch.compile` Functionality (TissueImageAnalytics#716)

    - Integrates PyTorch 2.0's [torch.compile](https://pytorch.org/docs/stable/generated/torch.compile.html) functionality to demonstrate performance improvements in torch code. This PR focuses on adding `torch.compile` to `PatchPredictor`.

    **Notes:**
    - According to the [documentation](https://pytorch.org/tutorials/intermediate/torch_compile_tutorial.html), noticeable performance can be achieved when using modern NVIDIA GPUs (H100, A100, or V100)

    **TODO:**
    - [x] Resolve compilation errors related to using `torch.compile` in running models
    - [x] Initial config
    - [x] Add to patch predictor
    - [x] Add to registration
    - [x] Add to segmentation
    - [x] Test on custom models
    - [x] Test on `torch.compile` compatible GPUs

    ---------

    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
    Co-authored-by: Shan E Ahmed Raza <13048456+shaneahmed@users.noreply.github.com>
    Co-authored-by: Jiaqi-Lv <60471431+Jiaqi-Lv@users.noreply.github.com>

commit e1a57c6
Author: mbasheer04 <bmusraf1@gmail.com>
Date:   Fri Nov 15 17:29:44 2024 +0000

    Created Jupyter Notebook for SAM architecture

commit 9113996
Author: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date:   Fri Nov 15 17:18:16 2024 +0000

    :technologist: pre-commit autoupdate (TissueImageAnalytics#880)

    * 🧑‍💻 pre-commit autoupdate

    updates:
    - [github.com/astral-sh/ruff-pre-commit: v0.7.0 → v0.7.2](astral-sh/ruff-pre-commit@v0.7.0...v0.7.2)

    * 📌 Update `ruff` version.

    ---------

    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
    Co-authored-by: Shan E Ahmed Raza <13048456+shaneahmed@users.noreply.github.com>

commit c980eec
Author: George Batchkala <46561186+GeorgeBatch@users.noreply.github.com>
Date:   Fri Nov 15 16:31:42 2024 +0000

    🆕 Integrate Foundation Models Available VIA `timm`: `UNI`, `Prov-GigaPath`, `H-optimus-0` (TissueImageAnalytics#856)

    - Integrates pre-trained foundation models from other labs into tiatoolbox.models.architecture.vanilla.py.

    Currently, the `_get_architecture()` function allows the use of models from `torchvision.models`.

    A new function `_get_timm_architecture()` has been incorporated to support foundation models which are available from `timm` with weights on HuggingFace Hub.

    - All the models from `timm` that used require users to sign the licence agreement with the authors.
    - The users can add new models by modifying `_get_timm_architecture()`

    ---------

    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
    Co-authored-by: Shan E Ahmed Raza <13048456+shaneahmed@users.noreply.github.com>

commit 7fb9926
Author: Mostafa Jahanifar <74412979+mostafajahanifar@users.noreply.github.com>
Date:   Fri Nov 8 17:25:02 2024 +0000

    🐛 Add Warning for `VahadaneExtractor` Algorithm Instability (TissueImageAnalytics#871)

    - Adds a warning to the `VahadaneExtractor` to inform users about the algorithm's instability due to changes in the dictionary learning algorithm in `scikit-learn versions > 0.23.0 (see issue TissueImageAnalytics#382)`.
    - The docstrings are updated accordingly to reflect this warning.
    - No other functionality is altered.

    ---------

    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

commit f4f2fa6
Author: mbasheer04 <bmusraf1@gmail.com>
Date:   Sun Nov 3 23:41:50 2024 +0000

    Initial setup of SAM architecture

commit 12d435e
Author: Shan E Ahmed Raza <13048456+shaneahmed@users.noreply.github.com>
Date:   Thu Oct 24 16:40:56 2024 +0100

    :pushpin: Pin `numpy<2.0.0` (TissueImageAnalytics#876)

    - `numpy>=2.0` breaks the tests.

commit 76f02f8
Author: Mark Eastwood <20169086+measty@users.noreply.github.com>
Date:   Fri Oct 18 14:53:49 2024 +0100

    🆕 Use Annotations as a Filter for Patch Extraction (TissueImageAnalytics#822)

    - Adds the ability to get patches filtered by class or label using AnnotationStore.
    - Allows the user to provide a path to an annotation store as the mask.
      - By default the mask will then be built out of all the annotations, but the user can also provide any filter that works in the annotation store, and have only those annotations make the mask.

    For example, if the user have some pathologist annotations with some regions, and they would only want to extract patches which have some overlap with regions labelled 'tumor' or any other class, they would just need to provide the appropriate string ("props['label'] == 'tumor'" for example).

    ---------

    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

commit 0b857c7
Author: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date:   Fri Oct 18 12:00:04 2024 +0100

    :technologist: `pre-commit` autoupdate (TissueImageAnalytics#868)

    * [pre-commit.ci] pre-commit autoupdate

    updates:
    - [github.com/pre-commit/pre-commit-hooks: v4.6.0 → v5.0.0](pre-commit/pre-commit-hooks@v4.6.0...v5.0.0)
    - [github.com/astral-sh/ruff-pre-commit: v0.6.5 → v0.6.9](astral-sh/ruff-pre-commit@v0.6.5...v0.6.9)

    * 🐛 Fix pre-commit yaml

    * 🧑‍💻 Change to monthly schedule.

    * [pre-commit.ci] pre-commit autoupdate

    updates:
    - [github.com/executablebooks/mdformat: 0.7.17 → 0.7.18](hukkin/mdformat@0.7.17...0.7.18)
    - [github.com/pre-commit/pre-commit-hooks: v4.6.0 → v5.0.0](pre-commit/pre-commit-hooks@v4.6.0...v5.0.0)
    - [github.com/astral-sh/ruff-pre-commit: v0.6.5 → v0.6.9](astral-sh/ruff-pre-commit@v0.6.5...v0.6.9)

    * 🔀 Merge online and local copies

    * 📌 Pin dependencies

    * 📌 Pin `ruff` version

    ---------

    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
    Co-authored-by: Shan E Ahmed Raza <13048456+shaneahmed@users.noreply.github.com>

commit 52792bc
Author: Alon Alexander <alon008@gmail.com>
Date:   Wed Oct 2 12:51:52 2024 +0300

    🐛 Fix `CITATION.cff` to Make it Compatible with `cffconvert`

    - To cite this repository using `cffconvert`, the conversion fails as the citation file was invalid.
    - This PR fixes the citation file to a valid ORCID.

commit 3714ef7
Author: Shan E Ahmed Raza <13048456+shaneahmed@users.noreply.github.com>
Date:   Wed Oct 2 10:22:26 2024 +0100

    :pushpin: Pin `bokeh` version to less than 3.6.0 (TissueImageAnalytics#870)

    - Pin `bokeh` version to less than `3.6.0`
    - `bokeh` 3.6.0 has breaking changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.tif file from Ventana scanner is not parsed properly with WSIReader; openslide works well on its own
3 participants