What Is Transposed Convolutional Layer - by Aqeel Anwar - Towards Data Science
What Is Transposed Convolutional Layer - by Aqeel Anwar - Towards Data Science
Save
The transposed convolutional layer does exactly what a standard convolutional layer
does but on a modified input feature map. Before explaining the similarity, let's first
have a look at how does a standard convolutional layer works.
Padding (p): The number of zeros padded around the original input increasing
the size to (i+2*p)x(i+2*p)
https://towardsdatascience.com/what-is-transposed-convolutional-layer-40e5e6e31c11 1/6
11/11/22, 6:50 AM What is Transposed Convolutional Layer? | by Aqeel Anwar | Towards Data Science
Stride (s): The amount by which the kernel is shifted when sliding across the
Get unlimited access Open in app
input image.
The figure below shows how a convolutional layer works as a two-step process.
In the first step, the input image is padded with zeros, while in the second step the
kernel is placed on the padded input and slid across generating the output pixels as
dot products of the kernel and the overlapped input region. The kernel is slid across
the padded input by taking jumps of size defined by the stride. The convolutional
layer usually does a down-sampling i.e. the spatial dimensions of the output are less
than that of the input.
The animations below explain the working of convolutional layers for different
values of stride and padding.
For a given size of the input (i), kernel (k), padding (p), and stride (s), the size of the
output feature map (o) generated is given by
https://towardsdatascience.com/what-is-transposed-convolutional-layer-40e5e6e31c11 2/6
11/11/22, 6:50 AM What is Transposed Convolutional Layer? | by Aqeel Anwar | Towards Data Science
Step 2: Between each row and columns of the input, insert z number of zeros.
This increases the size of the input to (2*i-1)x(2*i-1)
Step 4: Carry out standard convolution on the image generated from step 3 with
a stride length of 1
Image By Author
The animations below explain the working of convolutional layers for different
values of stride and padding.
https://towardsdatascience.com/what-is-transposed-convolutional-layer-40e5e6e31c11 3/6
11/11/22, 6:50 AM What is Transposed Convolutional Layer? | by Aqeel Anwar | Towards Data Science
For a given size of the input (i), kernel (k), padding (p), and stride (s), the size of the
output feature map (o) generated is given by
Summary:
The table below summarizes the two convolutions, standard and transposed.
The stride and padding do not correspond to the number of zeros added around
the image and the amount of shift in the kernel when sliding it across the input,
as they would in a standard convolution operation.
Python Code:
https://towardsdatascience.com/what-is-transposed-convolutional-layer-40e5e6e31c11 4/6
11/11/22, 6:50 AM What is Transposed Convolutional Layer? | by Aqeel Anwar | Towards Data Science
The gifs were generated using python. The complete code can be found at
Get unlimited access Open in app
https://github.com/aqeelanwar/conv_layers_animation
Bonus:
Compact cheat sheets for this topic and many other important topics in Machine
Learning can be found in the link below
If this article was helpful to you, feel free to clap, share and respond to it. If you
want to learn more about Machine Learning and Data Science, follow me @
Aqeel Anwar or connect with me on LinkedIn.
304 7
Every Thursday, the Variable delivers the very best of Towards Data Science: from hands-on tutorials and cutting-
edge research to original features you don't want to miss. Take a look.
https://towardsdatascience.com/what-is-transposed-convolutional-layer-40e5e6e31c11 5/6
11/11/22, 6:50 AM What is Transposed Convolutional Layer? | by Aqeel Anwar | Towards Data Science
https://towardsdatascience.com/what-is-transposed-convolutional-layer-40e5e6e31c11 6/6