Skip to content

Instantly share code, notes, and snippets.

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