forked from Project-MONAI/MONAI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split transform (Project-MONAI#4153)
* Redesign whole slide image reading (Project-MONAI#4107) * Redesign BaseWSIReader, WSIReader, CuCIMWSIReader Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> * Add unittests for WSIReader Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> * Add image mode for output validation Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> * Update docs Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> * Update references to new WSIReader Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> * Remove legacy WSIReader Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> * Update unittests Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> * Update docs Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> * sort imports Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> * Clean up imports Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> * Update docstrings Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> * Update docs and docstrings Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix a typo Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> * Remove redundant checking Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> * Update read and other methods Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> * Update wsireader to support multi image and update docstrings Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> * Make workaround for CuImage objects Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> * Add unittests for multi image reading Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> * Update a note about cucim Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> * Update type hints and docstrings Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> * Implement Split transform Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> * Add unittests Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> * Update formatting Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> * Implement SplitDict Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> * Add unittests for SplitDict Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> * Add docs Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> * Remove images from docs Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> * Address all comments Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> * Add example and size check Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> * Update docs Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> * Revert references to new wsireader Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> * Add missing comma Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com>
- Loading branch information
Showing
6 changed files
with
331 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Copyright (c) MONAI Consortium | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import unittest | ||
|
||
import torch | ||
from parameterized import parameterized | ||
|
||
from monai.transforms import GridSplit | ||
from tests.utils import TEST_NDARRAYS, assert_allclose | ||
|
||
A11 = torch.randn(3, 2, 2) | ||
A12 = torch.randn(3, 2, 2) | ||
A21 = torch.randn(3, 2, 2) | ||
A22 = torch.randn(3, 2, 2) | ||
|
||
A1 = torch.cat([A11, A12], 2) | ||
A2 = torch.cat([A21, A22], 2) | ||
A = torch.cat([A1, A2], 1) | ||
|
||
TEST_CASE_0 = [{"grid": (2, 2)}, A, torch.stack([A11, A12, A21, A22])] | ||
TEST_CASE_1 = [{"grid": (2, 1)}, A, torch.stack([A1, A2])] | ||
TEST_CASE_2 = [{"grid": (1, 2)}, A1, torch.stack([A11, A12])] | ||
TEST_CASE_3 = [{"grid": (1, 2)}, A2, torch.stack([A21, A22])] | ||
TEST_CASE_4 = [{"grid": (1, 1), "size": (2, 2)}, A, torch.stack([A11])] | ||
TEST_CASE_5 = [{"grid": (1, 1), "size": 4}, A, torch.stack([A])] | ||
TEST_CASE_6 = [{"grid": (2, 2), "size": 2}, A, torch.stack([A11, A12, A21, A22])] | ||
TEST_CASE_7 = [{"grid": (1, 1)}, A, torch.stack([A])] | ||
TEST_CASE_8 = [ | ||
{"grid": (2, 2), "size": 2}, | ||
torch.arange(12).reshape(1, 3, 4).to(torch.float32), | ||
torch.Tensor([[[[0, 1], [4, 5]]], [[[2, 3], [6, 7]]], [[[4, 5], [8, 9]]], [[[6, 7], [10, 11]]]]).to(torch.float32), | ||
] | ||
|
||
TEST_SINGLE = [] | ||
for p in TEST_NDARRAYS: | ||
TEST_SINGLE.append([p, *TEST_CASE_0]) | ||
TEST_SINGLE.append([p, *TEST_CASE_1]) | ||
TEST_SINGLE.append([p, *TEST_CASE_2]) | ||
TEST_SINGLE.append([p, *TEST_CASE_3]) | ||
TEST_SINGLE.append([p, *TEST_CASE_4]) | ||
TEST_SINGLE.append([p, *TEST_CASE_5]) | ||
TEST_SINGLE.append([p, *TEST_CASE_6]) | ||
TEST_SINGLE.append([p, *TEST_CASE_7]) | ||
TEST_SINGLE.append([p, *TEST_CASE_8]) | ||
|
||
TEST_CASE_MC_0 = [{"grid": (2, 2)}, [A, A], [torch.stack([A11, A12, A21, A22]), torch.stack([A11, A12, A21, A22])]] | ||
TEST_CASE_MC_1 = [{"grid": (2, 1)}, [A] * 5, [torch.stack([A1, A2])] * 5] | ||
TEST_CASE_MC_2 = [{"grid": (1, 2)}, [A1, A2], [torch.stack([A11, A12]), torch.stack([A21, A22])]] | ||
|
||
TEST_MULTIPLE = [] | ||
for p in TEST_NDARRAYS: | ||
TEST_MULTIPLE.append([p, *TEST_CASE_MC_0]) | ||
TEST_MULTIPLE.append([p, *TEST_CASE_MC_1]) | ||
TEST_MULTIPLE.append([p, *TEST_CASE_MC_2]) | ||
|
||
|
||
class TestGridSplit(unittest.TestCase): | ||
@parameterized.expand(TEST_SINGLE) | ||
def test_split_patch_single_call(self, in_type, input_parameters, image, expected): | ||
input_image = in_type(image) | ||
splitter = GridSplit(**input_parameters) | ||
output = splitter(input_image) | ||
assert_allclose(output, expected, type_test=False) | ||
|
||
@parameterized.expand(TEST_MULTIPLE) | ||
def test_split_patch_multiple_call(self, in_type, input_parameters, img_list, expected_list): | ||
splitter = GridSplit(**input_parameters) | ||
for image, expected in zip(img_list, expected_list): | ||
input_image = in_type(image) | ||
output = splitter(input_image) | ||
assert_allclose(output, expected, type_test=False) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Oops, something went wrong.