-
Notifications
You must be signed in to change notification settings - Fork 1.6k
1651 globalnet #1729
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
1651 globalnet #1729
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5b08bb2
1651 implement RegUNet
kate-sann5100 cc51f26
1651 reformat code
kate-sann5100 ea5780c
Merge branch 'master' into 1651-regunet
kate-sann5100 7a5a508
1651 reformat code
kate-sann5100 6979a67
Merge remote-tracking branch 'origin/1651-regunet' into 1651-regunet
kate-sann5100 e67bc79
1651 add globalnet
kate-sann5100 6980584
1651 reformat code
kate-sann5100 52893f1
1651 reformat code
kate-sann5100 43bcf3e
Merge remote-tracking branch 'Project-MONAI/master' into 1651-globalnet
kate-sann5100 7a5fff1
1651 reformat code
kate-sann5100 f706dce
Merge remote-tracking branch 'Project-MONAI/master' into 1651-globalnet
kate-sann5100 343e393
1651 reformat code
kate-sann5100 d1ee2ad
Merge branch 'master' into 1651-globalnet
kate-sann5100 ada6620
1651 fix device bug
kate-sann5100 df3fe69
Merge remote-tracking branch 'Project-MONAI/master' into 1651-globalnet
kate-sann5100 5f1b942
Merge remote-tracking branch 'origin/1651-globalnet' into 1651-globalnet
kate-sann5100 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
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,79 @@ | ||
| import unittest | ||
|
|
||
| import numpy as np | ||
| import torch | ||
| from parameterized import parameterized | ||
|
|
||
| from monai.networks import eval_mode | ||
| from monai.networks.nets import GlobalNet | ||
| from monai.networks.nets.regunet import AffineHead | ||
| from tests.utils import test_script_save | ||
|
|
||
| TEST_CASES_AFFINE_TRANSFORM = [ | ||
| [ | ||
| {"spatial_dims": 3, "image_size": (2, 2, 2), "decode_size": (2, 2, 2), "in_channels": 1}, | ||
| torch.ones(2, 12), | ||
| torch.tensor([[[1, 2], [2, 3]], [[2, 3], [3, 4]]]).unsqueeze(0).unsqueeze(0).expand(2, 3, 2, 2, 2), | ||
| ], | ||
| [ | ||
| {"spatial_dims": 3, "image_size": (2, 2, 2), "decode_size": (2, 2, 2), "in_channels": 1}, | ||
| torch.arange(1, 13).reshape(1, 12).to(torch.float), | ||
| torch.tensor( | ||
| [ | ||
| [[[4.0, 7.0], [6.0, 9.0]], [[5.0, 8.0], [7.0, 10.0]]], | ||
| [[[8.0, 15.0], [14.0, 21.0]], [[13.0, 20.0], [19.0, 26.0]]], | ||
| [[[12.0, 23.0], [22.0, 33.0]], [[21.0, 32.0], [31.0, 42.0]]], | ||
| ] | ||
| ).unsqueeze(0), | ||
| ], | ||
| ] | ||
|
|
||
|
|
||
| TEST_CASES_GLOBAL_NET = [ | ||
| [ | ||
| { | ||
| "image_size": (16, 16), | ||
| "spatial_dims": 2, | ||
| "in_channels": 1, | ||
| "num_channel_initial": 16, | ||
| "depth": 1, | ||
| "out_kernel_initializer": "kaiming_uniform", | ||
| "out_activation": None, | ||
| "pooling": True, | ||
| "concat_skip": True, | ||
| "encode_kernel_sizes": 3, | ||
| }, | ||
| (1, 1, 16, 16), | ||
| (1, 2, 16, 16), | ||
| ] | ||
| ] | ||
|
|
||
|
|
||
| class TestAffineHead(unittest.TestCase): | ||
| @parameterized.expand(TEST_CASES_AFFINE_TRANSFORM) | ||
| def test_shape(self, input_param, theta, expected_val): | ||
| layer = AffineHead(**input_param) | ||
| result = layer.affine_transform(theta) | ||
| np.testing.assert_allclose(result.cpu().numpy(), expected_val.cpu().numpy(), rtol=1e-4, atol=1e-4) | ||
|
|
||
|
|
||
| device = "cuda" if torch.cuda.is_available() else "cpu" | ||
|
|
||
|
|
||
| class TestGlobalNet(unittest.TestCase): | ||
| @parameterized.expand(TEST_CASES_GLOBAL_NET) | ||
| def test_shape(self, input_param, input_shape, expected_shape): | ||
| net = GlobalNet(**input_param).to(device) | ||
| with eval_mode(net): | ||
| result = net(torch.randn(input_shape).to(device)) | ||
| self.assertEqual(result.shape, expected_shape) | ||
|
|
||
| def test_script(self): | ||
| input_param, input_shape, _ = TEST_CASES_GLOBAL_NET[0] | ||
| net = GlobalNet(**input_param) | ||
| test_data = torch.randn(input_shape) | ||
| test_script_save(net, test_data) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
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.