Created
July 23, 2022 09:20
-
-
Save FrancescoSaverioZuppichini/c499d53431d243e9fc811f394f95aa05 to your computer and use it in GitHub Desktop.
Test
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
with torch.no_grad(): | |
x = torch.randn((1,2,3,3)) | |
identity_conv = nn.Conv2d(2,2,kernel_size=3, padding=1, bias=False) | |
identity_conv.weight.zero_() | |
print(identity_conv.weight.shape) | |
in_channels = identity_conv.in_channels | |
for i in range(in_channels): | |
identity_conv.weight[i, i % in_channels, 1, 1] = 1 | |
print(identity_conv.weight) | |
out = identity_conv(x) | |
assert torch.allclose(x, out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment