-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add resnet 3d implementation (based on torchvision)
- Loading branch information
1 parent
54fa6e1
commit a4060d4
Showing
2 changed files
with
402 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import unittest | ||
import torch | ||
|
||
|
||
class TestResNet3d(unittest.TestCase): | ||
def _test_net(self, net, shape): | ||
x = torch.rand(*shape, requires_grad=True) | ||
y = net(x) | ||
expected_shape = (shape[0], net.out_channels) | ||
self.assertEqual(y.shape, expected_shape) | ||
loss = y.sum() | ||
loss.backward() | ||
|
||
def test_resnet18(self): | ||
from torch_em.model.resnet3d import resnet3d_18 | ||
|
||
# test model with 1 input channel and 1 output channels | ||
net = resnet3d_18(in_channels=1, out_channels=1) | ||
self._test_net(net, (1, 1, 64, 64, 64)) | ||
|
||
# test model with 2 input channel and 9 output channels | ||
net = resnet3d_18(in_channels=2, out_channels=9) | ||
self._test_net(net, (4, 2, 64, 64, 64)) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Oops, something went wrong.