Skip to content

Instantly share code, notes, and snippets.

@sicongzhao
Created April 25, 2020 07:19
Show Gist options
  • Save sicongzhao/d26462c674d968364c141cab8856d881 to your computer and use it in GitHub Desktop.
Save sicongzhao/d26462c674d968364c141cab8856d881 to your computer and use it in GitHub Desktop.
Demystify Transposed Convolutional Layer
# Create a TCL layer with kernel_size=2, stride=2, dilation=2
transConv5 = nn.ConvTranspose2d(1, 1, 2, stride=2, dilation=2, bias=False)
# Set kernel weights to be 1
transConv5.weight.data = torch.ones(1,1,2,2)
# Calculate
transConv5(input_data)
# Output:
# tensor([[[[ 1., 0., 3., 0., 2.],
# [ 0., 0., 0., 0., 0.],
# [ 4., 0., 10., 0., 6.],
# [ 0., 0., 0., 0., 0.],
# [ 3., 0., 7., 0., 4.]]]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment