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

WSIReader, cucim , tifffile, performance regressions #5580

Closed
myron opened this issue Nov 24, 2022 · 2 comments · Fixed by #6089
Closed

WSIReader, cucim , tifffile, performance regressions #5580

myron opened this issue Nov 24, 2022 · 2 comments · Fixed by #6089
Assignees
Labels
Pathology/Microscopy Digital Pathology and Microscopy related

Comments

@myron
Copy link
Collaborator

myron commented Nov 24, 2022

with pathology MIL classification tutorial, as an example
https://github.com/Project-MONAI/tutorials/blob/main/pathology/multiple_instance_learning/panda_mil_train_evaluate_pytorch_gpu.py

WSIReader is now imported from from monai.data.wsi_reader import WSIReader. If changing the import to the old way (now deprecated) from monai.data.image_reader import WSIReader, and setting backend=tifffile, then training is ~10% faster. seems like a performance regression.

Training time on 8gpu, 1 epoch

  • from monai.data.wsi_reader import WSIReader, (backend=cucim) 313 seconds
  • from monai.data.wsi_reader import WSIReader, (backend=tiffile) 303 seconds
  • from monai.data.image_reader import WSIReader, (backend=tiffile) 283 seconds
@drbeh drbeh added the Pathology/Microscopy Digital Pathology and Microscopy related label Nov 28, 2022
@drbeh drbeh added this to the Pathology Misc Improvements milestone Nov 28, 2022
@drbeh drbeh self-assigned this Mar 1, 2023
@drbeh
Copy link
Member

drbeh commented Mar 1, 2023

Hi @myron, thank you very much for reporting this. I have investigated this issue and realized that the root cause is an "unnecessary" array copy in the wsi_reader.WSIReader. After fixing this, wsi_reader.WSIReader seems to be faster than image_reader.WSIReader (see blow). I will submit the PR momentarily. It would be great if you can check the run time of MIL tutorial after the PR is merged. Thanks

from monai.data.wsi_reader import WSIReader
from monai.data.image_reader import WSIReader as WSIReader2

filename = "temp_CMU-1.tiff"
reader1 = WSIReader(backend="TiffFile")
reader2 = WSIReader2(backend="TiffFile")
obj1 = reader1.read(filename)
obj2 = reader2.read(filename)
%%timeit
reader1.get_data(obj1, level=1)

current performance: 2.32 s ± 97.7
after fixing the issue: 1.45 s ± 12.9 ms

%%timeit
reader2.get_data(obj2, level=1)

current performance: 1.97 s ± 50.2 ms
after fixing the issue:. 1.93 s ± 141 ms

drbeh added a commit that referenced this issue Mar 2, 2023
Fixes #5580 

### Description
This PR remove an "unnecessary" array copy in WSITiffFileReader, which
was causing an slow down in loading whole slide images.

### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).

Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com>
@myron
Copy link
Collaborator Author

myron commented Mar 2, 2023

okay, there was a very short time window for me to test it before merging. but since it's already merged, I'll just test it a bit later, when I get to it. But thank you for debugging and fixing it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Pathology/Microscopy Digital Pathology and Microscopy related
Projects
Status: 💯 Complete
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants