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 defaults and tensor conversion #6058

Merged
merged 28 commits into from
Mar 14, 2023

Conversation

drbeh
Copy link
Member

@drbeh drbeh commented Feb 23, 2023

Fixes #6056

Description

This PR enable to instantiate WSIReader classes with default values for mode and dtype. It also accepts torch.dtype as dtype and if torch.dtype is provided, the output will be a torch.Tensor to avoid additional step to convert the output for inference.

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • New tests added to cover the changes.
  • Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick --unittests --disttests.
  • In-line docstrings updated.

@drbeh drbeh force-pushed the fix-6056-wsireader-defaults branch from 5fc3b15 to d48d3c9 Compare March 1, 2023 21:56
@drbeh drbeh marked this pull request as ready for review March 6, 2023 17:05
@drbeh drbeh requested review from wyli, KumoLiu and Nic-Ma March 6, 2023 17:06
monai/data/wsi_reader.py Show resolved Hide resolved
monai/data/wsi_reader.py Show resolved Hide resolved
monai/data/wsi_reader.py Show resolved Hide resolved
monai/data/wsi_reader.py Show resolved Hide resolved
@Nic-Ma
Copy link
Contributor

Nic-Ma commented Mar 7, 2023

/black

@Nic-Ma
Copy link
Contributor

Nic-Ma commented Mar 8, 2023

/build

@drbeh
Copy link
Member Author

drbeh commented Mar 8, 2023

@Nic-Ma it seems that blossom test has failed but I cannot see what has happened. How can I get the visibility on that? Thanks

@Nic-Ma
Copy link
Contributor

Nic-Ma commented Mar 8, 2023

Hi @drbeh ,

I think the error is as below:

2023-03-08T02:13:10.5286648Z [2023-03-08T02:12:42.239Z] ======================================================================
2023-03-08T02:13:10.5287076Z [2023-03-08T02:12:42.239Z] FAIL: test_read_region_device_1__home_jenkins_agent_workspace_MONAI_premerge_monai_tests_testing_data_temp_CMU_1_tiff_tiff (tests.test_wsireader.TestCuCIM)
2023-03-08T02:13:10.5287345Z [2023-03-08T02:12:42.239Z] ----------------------------------------------------------------------
2023-03-08T02:13:10.5287547Z [2023-03-08T02:12:42.239Z] Traceback (most recent call last):
2023-03-08T02:13:10.5287895Z [2023-03-08T02:12:42.239Z]   File "/opt/conda/lib/python3.8/site-packages/parameterized/parameterized.py", line 533, in standalone_func
2023-03-08T02:13:10.5288106Z [2023-03-08T02:12:42.239Z]     return func(*(a + p.args), **p.kwargs)
2023-03-08T02:13:10.5288467Z [2023-03-08T02:12:42.239Z]   File "/home/jenkins/agent/workspace/MONAI-premerge/monai/tests/test_wsireader.py", line 562, in test_read_region_device
2023-03-08T02:13:10.5288715Z [2023-03-08T02:12:42.239Z]     self.assertEqual(img.device, torch.device(device))
2023-03-08T02:13:10.5289093Z [2023-03-08T02:12:42.239Z] AssertionError: device(type='cuda', index=0) != device(type='cuda')
2023-03-08T02:13:10.5289226Z [2023-03-08T02:12:42.239Z] 
2023-03-08T02:13:10.5289452Z [2023-03-08T02:12:42.239Z] ======================================================================
2023-03-08T02:13:10.5289868Z [2023-03-08T02:12:42.239Z] FAIL: test_read_region_device_3__home_jenkins_agent_workspace_MONAI_premerge_monai_tests_testing_data_temp_CMU_1_tiff_tiff (tests.test_wsireader.TestCuCIM)
2023-03-08T02:13:10.5290134Z [2023-03-08T02:12:42.239Z] ----------------------------------------------------------------------
2023-03-08T02:13:10.5290336Z [2023-03-08T02:12:42.239Z] Traceback (most recent call last):
2023-03-08T02:13:10.5290683Z [2023-03-08T02:12:42.239Z]   File "/opt/conda/lib/python3.8/site-packages/parameterized/parameterized.py", line 533, in standalone_func
2023-03-08T02:13:10.5290898Z [2023-03-08T02:12:42.239Z]     return func(*(a + p.args), **p.kwargs)
2023-03-08T02:13:10.5291260Z [2023-03-08T02:12:42.239Z]   File "/home/jenkins/agent/workspace/MONAI-premerge/monai/tests/test_wsireader.py", line 559, in test_read_region_device
2023-03-08T02:13:10.5291465Z [2023-03-08T02:12:42.239Z]     assert_allclose(img, expected_img)
2023-03-08T02:13:10.5291790Z [2023-03-08T02:12:42.239Z]   File "/home/jenkins/agent/workspace/MONAI-premerge/monai/tests/utils.py", line 124, in assert_allclose
2023-03-08T02:13:10.5292123Z [2023-03-08T02:12:42.239Z]     np.testing.assert_equal(isinstance(actual, np.ndarray), isinstance(desired, np.ndarray), "numpy type")
2023-03-08T02:13:10.5292448Z [2023-03-08T02:12:42.239Z]   File "/opt/conda/lib/python3.8/site-packages/numpy/testing/_private/utils.py", line 425, in assert_equal
2023-03-08T02:13:10.5292642Z [2023-03-08T02:12:42.239Z]     raise AssertionError(msg)
2023-03-08T02:13:10.5292811Z [2023-03-08T02:12:42.239Z] AssertionError: 
2023-03-08T02:13:10.5293009Z [2023-03-08T02:12:42.239Z] Items are not equal: numpy type
2023-03-08T02:13:10.5293226Z [2023-03-08T02:12:42.239Z]  ACTUAL: True
2023-03-08T02:13:10.5293378Z [2023-03-08T02:12:42.239Z]  DESIRED: False
2023-03-08T02:13:10.5293508Z [2023-03-08T02:12:42.239Z] 
2023-03-08T02:13:10.5293734Z [2023-03-08T02:12:42.239Z] ======================================================================
2023-03-08T02:13:10.5294158Z [2023-03-08T02:12:42.239Z] FAIL: test_read_region_device_5__home_jenkins_agent_workspace_MONAI_premerge_monai_tests_testing_data_temp_CMU_1_tiff_tiff (tests.test_wsireader.TestCuCIM)
2023-03-08T02:13:10.5294426Z [2023-03-08T02:12:42.239Z] ----------------------------------------------------------------------
2023-03-08T02:13:10.5294627Z [2023-03-08T02:12:42.239Z] Traceback (most recent call last):
2023-03-08T02:13:10.5294973Z [2023-03-08T02:12:42.239Z]   File "/opt/conda/lib/python3.8/site-packages/parameterized/parameterized.py", line 533, in standalone_func
2023-03-08T02:13:10.5295222Z [2023-03-08T02:12:42.239Z]     return func(*(a + p.args), **p.kwargs)
2023-03-08T02:13:10.5295583Z [2023-03-08T02:12:42.239Z]   File "/home/jenkins/agent/workspace/MONAI-premerge/monai/tests/test_wsireader.py", line 559, in test_read_region_device
2023-03-08T02:13:10.5295788Z [2023-03-08T02:12:42.239Z]     assert_allclose(img, expected_img)
2023-03-08T02:13:10.5296115Z [2023-03-08T02:12:42.239Z]   File "/home/jenkins/agent/workspace/MONAI-premerge/monai/tests/utils.py", line 124, in assert_allclose
2023-03-08T02:13:10.5296447Z [2023-03-08T02:12:42.239Z]     np.testing.assert_equal(isinstance(actual, np.ndarray), isinstance(desired, np.ndarray), "numpy type")
2023-03-08T02:13:10.5296772Z [2023-03-08T02:12:42.239Z]   File "/opt/conda/lib/python3.8/site-packages/numpy/testing/_private/utils.py", line 425, in assert_equal
2023-03-08T02:13:10.5296954Z [2023-03-08T02:12:42.239Z]     raise AssertionError(msg)
2023-03-08T02:13:10.5297121Z [2023-03-08T02:12:42.239Z] AssertionError: 
2023-03-08T02:13:10.5297316Z [2023-03-08T02:12:42.239Z] Items are not equal: numpy type
2023-03-08T02:13:10.5297469Z [2023-03-08T02:12:42.239Z]  ACTUAL: True
2023-03-08T02:13:10.5297632Z [2023-03-08T02:12:42.239Z]  DESIRED: False
2023-03-08T02:13:10.5297764Z [2023-03-08T02:12:42.239Z] 
2023-03-08T02:13:10.5297991Z [2023-03-08T02:12:42.239Z] ======================================================================
2023-03-08T02:13:10.5298418Z [2023-03-08T02:12:42.239Z] FAIL: test_read_region_device_1__home_jenkins_agent_workspace_MONAI_premerge_monai_tests_testing_data_temp_CMU_1_tiff_tiff (tests.test_wsireader.TestTiffFile)
2023-03-08T02:13:10.5298686Z [2023-03-08T02:12:42.239Z] ----------------------------------------------------------------------
2023-03-08T02:13:10.5298884Z [2023-03-08T02:12:42.239Z] Traceback (most recent call last):
2023-03-08T02:13:10.5299224Z [2023-03-08T02:12:42.239Z]   File "/opt/conda/lib/python3.8/site-packages/parameterized/parameterized.py", line 533, in standalone_func
2023-03-08T02:13:10.5299437Z [2023-03-08T02:12:42.239Z]     return func(*(a + p.args), **p.kwargs)
2023-03-08T02:13:10.5299787Z [2023-03-08T02:12:42.239Z]   File "/home/jenkins/agent/workspace/MONAI-premerge/monai/tests/test_wsireader.py", line 562, in test_read_region_device
2023-03-08T02:13:10.5300030Z [2023-03-08T02:12:42.239Z]     self.assertEqual(img.device, torch.device(device))
2023-03-08T02:13:10.5300291Z [2023-03-08T02:12:42.239Z] AssertionError: device(type='cuda', index=0) != device(type='cuda')
2023-03-08T02:13:10.5300423Z [2023-03-08T02:12:42.239Z] 
2023-03-08T02:13:10.5300648Z [2023-03-08T02:12:42.239Z] ======================================================================
2023-03-08T02:13:10.5301075Z [2023-03-08T02:12:42.239Z] FAIL: test_read_region_device_3__home_jenkins_agent_workspace_MONAI_premerge_monai_tests_testing_data_temp_CMU_1_tiff_tiff (tests.test_wsireader.TestTiffFile)
2023-03-08T02:13:10.5301337Z [2023-03-08T02:12:42.239Z] ----------------------------------------------------------------------
2023-03-08T02:13:10.5301540Z [2023-03-08T02:12:42.239Z] Traceback (most recent call last):
2023-03-08T02:13:10.5301928Z [2023-03-08T02:12:42.239Z]   File "/opt/conda/lib/python3.8/site-packages/parameterized/parameterized.py", line 533, in standalone_func
2023-03-08T02:13:10.5302136Z [2023-03-08T02:12:42.239Z]     return func(*(a + p.args), **p.kwargs)
2023-03-08T02:13:10.5302494Z [2023-03-08T02:12:42.239Z]   File "/home/jenkins/agent/workspace/MONAI-premerge/monai/tests/test_wsireader.py", line 559, in test_read_region_device
2023-03-08T02:13:10.5302698Z [2023-03-08T02:12:42.239Z]     assert_allclose(img, expected_img)
2023-03-08T02:13:10.5303022Z [2023-03-08T02:12:42.239Z]   File "/home/jenkins/agent/workspace/MONAI-premerge/monai/tests/utils.py", line 124, in assert_allclose
2023-03-08T02:13:10.5303354Z [2023-03-08T02:12:42.239Z]     np.testing.assert_equal(isinstance(actual, np.ndarray), isinstance(desired, np.ndarray), "numpy type")
2023-03-08T02:13:10.5303711Z [2023-03-08T02:12:42.239Z]   File "/opt/conda/lib/python3.8/site-packages/numpy/testing/_private/utils.py", line 425, in assert_equal
2023-03-08T02:13:10.5303910Z [2023-03-08T02:12:42.239Z]     raise AssertionError(msg)
2023-03-08T02:13:10.5304076Z [2023-03-08T02:12:42.239Z] AssertionError: 
2023-03-08T02:13:10.5304273Z [2023-03-08T02:12:42.239Z] Items are not equal: numpy type
2023-03-08T02:13:10.5304428Z [2023-03-08T02:12:42.239Z]  ACTUAL: True
2023-03-08T02:13:10.5304588Z [2023-03-08T02:12:42.239Z]  DESIRED: False
2023-03-08T02:13:10.5304718Z [2023-03-08T02:12:42.239Z] 
2023-03-08T02:13:10.5304942Z [2023-03-08T02:12:42.239Z] ======================================================================
2023-03-08T02:13:10.5305369Z [2023-03-08T02:12:42.239Z] FAIL: test_read_region_device_5__home_jenkins_agent_workspace_MONAI_premerge_monai_tests_testing_data_temp_CMU_1_tiff_tiff (tests.test_wsireader.TestTiffFile)
2023-03-08T02:13:10.5305632Z [2023-03-08T02:12:42.239Z] ----------------------------------------------------------------------
2023-03-08T02:13:10.5305832Z [2023-03-08T02:12:42.239Z] Traceback (most recent call last):
2023-03-08T02:13:10.5306178Z [2023-03-08T02:12:42.239Z]   File "/opt/conda/lib/python3.8/site-packages/parameterized/parameterized.py", line 533, in standalone_func
2023-03-08T02:13:10.5306382Z [2023-03-08T02:12:42.239Z]     return func(*(a + p.args), **p.kwargs)
2023-03-08T02:13:10.5306737Z [2023-03-08T02:12:42.239Z]   File "/home/jenkins/agent/workspace/MONAI-premerge/monai/tests/test_wsireader.py", line 559, in test_read_region_device
2023-03-08T02:13:10.5306941Z [2023-03-08T02:12:42.239Z]     assert_allclose(img, expected_img)
2023-03-08T02:13:10.5307272Z [2023-03-08T02:12:42.239Z]   File "/home/jenkins/agent/workspace/MONAI-premerge/monai/tests/utils.py", line 124, in assert_allclose
2023-03-08T02:13:10.5307602Z [2023-03-08T02:12:42.239Z]     np.testing.assert_equal(isinstance(actual, np.ndarray), isinstance(desired, np.ndarray), "numpy type")
2023-03-08T02:13:10.5307925Z [2023-03-08T02:12:42.239Z]   File "/opt/conda/lib/python3.8/site-packages/numpy/testing/_private/utils.py", line 425, in assert_equal
2023-03-08T02:13:10.5308117Z [2023-03-08T02:12:42.239Z]     raise AssertionError(msg)
2023-03-08T02:13:10.5308286Z [2023-03-08T02:12:42.239Z] AssertionError: 
2023-03-08T02:13:10.5308477Z [2023-03-08T02:12:42.239Z] Items are not equal: numpy type
2023-03-08T02:13:10.5308632Z [2023-03-08T02:12:42.239Z]  ACTUAL: True
2023-03-08T02:13:10.5308791Z [2023-03-08T02:12:42.239Z]  DESIRED: False
2023-03-08T02:13:10.5308922Z [2023-03-08T02:12:42.239Z] 
2023-03-08T02:13:10.5309182Z [2023-03-08T02:12:42.239Z] ----------------------------------------------------------------------
2023-03-08T02:13:10.5309366Z [2023-03-08T02:12:42.239Z] Ran 12302 tests in 1393.784s
2023-03-08T02:13:10.5309496Z [2023-03-08T02:12:42.239Z] 
2023-03-08T02:13:10.5309693Z [2023-03-08T02:12:42.239Z] FAILED (failures=6, skipped=521)

Thanks.

Signed-off-by: Behrooz <[email protected]>
@Nic-Ma
Copy link
Contributor

Nic-Ma commented Mar 8, 2023

/build

drbeh added 4 commits March 8, 2023 11:26
Signed-off-by: Behrooz <[email protected]>
Signed-off-by: Behrooz <[email protected]>
Signed-off-by: Behrooz <[email protected]>
@drbeh
Copy link
Member Author

drbeh commented Mar 8, 2023

@Nic-Ma I am making few changes. Please hold on a bit. Thanks

@drbeh
Copy link
Member Author

drbeh commented Mar 9, 2023

@Nic-Ma it is ready, and has passed all the tests locally. Thanks

@Nic-Ma
Copy link
Contributor

Nic-Ma commented Mar 9, 2023

/build

@drbeh
Copy link
Member Author

drbeh commented Mar 10, 2023

@Nic-Ma @wyli it seems that the issue with blossom has fixed. Can we run blossom tests again here?

@wyli
Copy link
Contributor

wyli commented Mar 10, 2023

/build

@wyli wyli enabled auto-merge (squash) March 10, 2023 19:16
@wyli wyli disabled auto-merge March 10, 2023 20:53
@drbeh drbeh enabled auto-merge (squash) March 13, 2023 14:24
@drbeh drbeh disabled auto-merge March 13, 2023 15:43
@drbeh
Copy link
Member Author

drbeh commented Mar 13, 2023

@Nic-Ma @wyli @ericspod do you have any idea why quick-py3 (ubuntu-latest) are getting cancelled?
https://github.com/Project-MONAI/MONAI/actions/runs/4406004944/jobs/7717649759#step:12:17631

The only thing that I can think of is memory limit since TiffFile loads the entire image unlike other backends (cucim and openslide).

However, the same test are going well on Mac quick-py3 (macOS-latest):
https://github.com/Project-MONAI/MONAI/actions/runs/4406004944/jobs/7717649413#step:12:17755

Do we have different memory limits on the instances that Mac and Ubuntu quick tests are running?

monai/data/wsi_reader.py Outdated Show resolved Hide resolved
@drbeh
Copy link
Member Author

drbeh commented Mar 13, 2023

@Nic-Ma @wyli the issue with quick tests on ubuntu is resolved. As I expected, it was due to memory limitation and reducing the image size for that test case helped not to face that issue again.
Please let's finally merge this if you don't have any other comments.

@wyli
Copy link
Contributor

wyli commented Mar 14, 2023

/build

@wyli wyli merged commit 01b6d70 into Project-MONAI:dev Mar 14, 2023
@wyli
Copy link
Contributor

wyli commented Mar 14, 2023

it seems the memory issue is still here https://github.com/Project-MONAI/MONAI/actions/runs/4418529796/jobs/7745780000 could you please have a look soon @drbeh it might block 1.2rc releases... cc @Nic-Ma @KumoLiu

@drbeh
Copy link
Member Author

drbeh commented Mar 14, 2023

@wyli I'll make a PR to make all the test to use the lowest resolution so we can save memory and time.

@drbeh drbeh deleted the fix-6056-wsireader-defaults branch March 14, 2023 18:12
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

Successfully merging this pull request may close these issues.

WSIReader defaults at initialization
4 participants