![]() |
VOOZH | about |
A transposed convolutional layer is an upsampling layer that generates the output feature map greater than the input feature map. It is similar to a deconvolutional layer. A deconvolutional layer reverses the layer to a standard convolutional layer. If the output of the standard convolution layer is deconvolved with the deconvolutional layer then the output will be the same as the original value, While in transposed convolutional value will not be the same, it can reverse to the same dimension,
Transposed convolutional layers are used in a variety of tasks, including image generation, image super-resolution, and image segmentation. They are particularly useful for tasks that involve upsampling the input data, such as converting a low-resolution image to a high-resolution one or generating an image from a set of noise vectors.
The operation of a transposed convolutional layer is similar to that of a normal convolutional layer, except that it performs the convolution operation in the opposite direction. Instead of sliding the kernel over the input and performing element-wise multiplication and summation, a transposed convolutional layer slides the input over the kernel and performs element-wise multiplication and summation. This results in an output that is larger than the input, and the size of the output can be controlled by the stride and padding parameters of the layer.
In a transposed convolutional layer, the input is a feature map of size , where and are the height and width of the input and the kernel size is , where and are the height and width of the kernel.
If the stride shape is and the padding is p, The stride of the transposed convolutional layer determines the step size for the input indices p and q, and the padding determines the number of pixels to add to the edges of the input before performing the convolution. Then the output of the transposed convolutional layer will be
where and are the height and width of the output.
Suppose we have a grayscale image of size 2 X 2, and we want to upsample it using a transposed convolutional layer with a kernel size of 2 x 2, a stride of 1, and zero padding (or no padding). The input image and the kernel for the transposed convolutional layer would be as follows:
The output will be:
Code Explanations:
Output:
<tf.Tensor: shape=(3, 3), dtype=float64, numpy= array([[ 0., 4., 1.], [ 8., 16., 6.], [ 4., 12., 9.]])>
The output shape can be calculated as :
Code Explanations:
Output:
tensor([[[[ 0., 4., 1.], [ 8., 16., 6.], [ 4., 12., 9.]]]], grad_fn=<ConvolutionBackward0>)
Transposed convolutional layers are often used in conjunction with other types of layers, such as pooling layers and fully connected layers, to build deep convolutional networks for various tasks.
In valid padding, no extra layer of zeros will be added.
Output:
(1, 9, 9, 1)
In same padding, an Extra layer of zeros (known as the padding layer) will be added.
Output:
(1, 8, 8, 1)