-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add function in monai.transforms.utils.py #7712
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
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
a78c5a6
Fixes #6704
ytl0623 4797043
Merge branch 'Project-MONAI:dev' into fix-issue-6704
ytl0623 f04a29e
Update monai/transforms/utils.py
ytl0623 7a31661
Add a unittest and modify few codes.
ytl0623 e66ae71
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] df0f0d0
Merge branch 'Project-MONAI:dev' into fix-issue-6704
ytl0623 a06511b
Apply suggestions from code review
ytl0623 30d4876
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 535675d
Update monai/transforms/utils.py
ytl0623 656f56a
import copy
ytl0623 32c888d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 9602d3a
import copy
ytl0623 12e5881
remove backup file :")
ytl0623 e2641d4
problem solved: Imports are incorrectly sorted and/or formatted.
ytl0623 639022c
Reformat utils.py
ytl0623 eeae642
solve utils.py line: 388 too long.
ytl0623 8ba5c7e
Solved import error.
ytl0623 d3ba184
Add function in _init_.py
ytl0623 f1f9a80
Update monai/transforms/utils.py
ytl0623 4ec2b64
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] dbc86e4
Reformatted utils.py
ytl0623 7a8c7cd
Merge branch 'dev' into fix-issue-6704
ytl0623 f599cbe
20240516
ytl0623 2259678
Merge branch 'dev' into fix-issue-6704
ytl0623 e394797
Merge branch 'dev' into fix-issue-6704
ytl0623 943708e
Update utils.py
ytl0623 58ea019
Update utils.py
ytl0623 317fc06
Fix long line
ytl0623 6ba0a04
Merge branch 'dev' into fix-issue-6704
ytl0623 53f472b
Merge branch 'dev' into fix-issue-6704
KumoLiu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,87 @@ | ||
# 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. | ||
|
||
from __future__ import annotations | ||
|
||
import unittest | ||
from copy import deepcopy | ||
|
||
import numpy as np | ||
from parameterized import parameterized | ||
|
||
from monai.transforms import map_and_generate_sampling_centers | ||
from monai.utils.misc import set_determinism | ||
from tests.utils import TEST_NDARRAYS, assert_allclose | ||
|
||
TEST_CASE_1 = [ | ||
# test Argmax data | ||
{ | ||
"label": (np.array([[[0, 1, 2], [2, 0, 1], [1, 2, 0]]])), | ||
"spatial_size": [2, 2, 2], | ||
"num_samples": 2, | ||
"label_spatial_shape": [3, 3, 3], | ||
"num_classes": 3, | ||
"image": None, | ||
"ratios": [0, 1, 2], | ||
"image_threshold": 0.0, | ||
}, | ||
tuple, | ||
2, | ||
3, | ||
] | ||
|
||
TEST_CASE_2 = [ | ||
{ | ||
"label": ( | ||
np.array( | ||
[ | ||
[[1, 0, 0], [0, 1, 0], [0, 0, 1]], | ||
[[0, 1, 0], [0, 0, 1], [1, 0, 0]], | ||
[[0, 0, 1], [1, 0, 0], [0, 1, 0]], | ||
] | ||
) | ||
), | ||
"spatial_size": [2, 2, 2], | ||
"num_samples": 1, | ||
"ratios": None, | ||
"label_spatial_shape": [3, 3, 3], | ||
"image": None, | ||
"image_threshold": 0.0, | ||
}, | ||
tuple, | ||
1, | ||
3, | ||
] | ||
|
||
|
||
ytl0623 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
class TestMapAndGenerateSamplingCenters(unittest.TestCase): | ||
|
||
@parameterized.expand([TEST_CASE_1, TEST_CASE_2]) | ||
def test_map_and_generate_sampling_centers(self, input_data, expected_type, expected_count, expected_shape): | ||
results = [] | ||
for p in TEST_NDARRAYS + (None,): | ||
input_data = deepcopy(input_data) | ||
if p is not None: | ||
input_data["label"] = p(input_data["label"]) | ||
set_determinism(0) | ||
result = map_and_generate_sampling_centers(**input_data) | ||
self.assertIsInstance(result, expected_type) | ||
self.assertEqual(len(result), expected_count) | ||
self.assertEqual(len(result[0]), expected_shape) | ||
# check for consistency between numpy, torch and torch.cuda | ||
results.append(result) | ||
if len(results) > 1: | ||
for x, y in zip(result[0], result[-1]): | ||
assert_allclose(x, y, type_test=False) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.