Skip to content

Instantly share code, notes, and snippets.

@FrancescoSaverioZuppichini
Created July 23, 2022 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FrancescoSaverioZuppichini/c499d53431d243e9fc811f394f95aa05 to your computer and use it in GitHub Desktop.
Save FrancescoSaverioZuppichini/c499d53431d243e9fc811f394f95aa05 to your computer and use it in GitHub Desktop.
Test
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