-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: torch module output shape calculator
- Loading branch information
1 parent
8f6802d
commit f333b60
Showing
2 changed files
with
73 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,28 @@ | ||
import torch | ||
from torch import nn | ||
|
||
from todd.utils.torch import Shape | ||
|
||
|
||
class TestShapePytest: | ||
|
||
def test_conv(self): | ||
module = nn.Conv1d(3, 6, 3, padding=1) | ||
x = torch.randn(2, 3, 4) | ||
assert Shape.conv(module, x) == (2, 6, 4) | ||
|
||
module = nn.Conv2d(3, 6, 3, padding=1) | ||
x = torch.randn(2, 3, 4, 4) | ||
assert Shape.conv(module, x) == (2, 6, 4, 4) | ||
|
||
module = nn.Conv2d(1, 1, 3, padding=1) | ||
x = torch.randn(1, 1, 5, 5) | ||
assert Shape.conv(module, x) == (1, 1, 5, 5) | ||
|
||
module = nn.Conv2d(3, 2, 3, padding=1) | ||
x = torch.randn(1, 3, 6, 6) | ||
assert Shape.conv(module, x) == (1, 2, 6, 6) | ||
|
||
module = nn.Conv2d(1, 1, 1) | ||
x = torch.randn(1, 1, 10, 10) | ||
assert Shape.conv(module, x) == (1, 1, 10, 10) |
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