Skip to content

Instantly share code, notes, and snippets.

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