ConvTranspose2d#

class ConvTranspose2d(in_channels, out_channels, kernel_size, stride=1, padding=0, output_padding=0, dilation=1, groups=1, bias=True, conv_mode='cross_correlation', compute_mode='default', **kwargs)[source]#

Applies a 2D transposed convolution over an input tensor.

This module is also known as a deconvolution or a fractionally-strided convolution. ConvTranspose2d can be seen as the gradient of Conv2d operation with respect to its input.

Convolution usually reduces the size of input, while transposed convolution works the opposite way, transforming a smaller input to a larger output while preserving the connectivity pattern.

Parameters:
  • in_channels (int) – number of input channels.

  • out_channels (int) – number of output channels.

  • kernel_size (Union[int, Tuple[int, int]]) – size of weight on spatial dimensions. If kernel_size is an int, the actual kernel size would be (kernel_size, kernel_size).

  • stride (Union[int, Tuple[int, int]]) – stride of the 2D convolution operation. Default: 1

  • padding (Union[int, Tuple[int, int]]) – size of the paddings added to the input on both sides of its spatial dimensions. Only zero-padding is supported. Default: 0

  • output_padding (Union[int, Tuple[int, int]]) – size of paddings appended to output. Default: 0

  • dilation (Union[int, Tuple[int, int]]) – dilation of the 2D convolution operation. Default: 1

  • groups (int) – number of groups into which the input and output channels are divided, so as to perform a grouped convolution. When groups is not 1, in_channels and out_channels must be divisible by groups, and the shape of weight should be (groups, in_channels // groups, out_channels // groups, height, width). Default: 1

  • bias (bool) – wether to add a bias onto the result of convolution. Default: True conv_mode: Supports cross_correlation. Default: cross_correlation

  • compute_mode (str) – When set to “default”, no special requirements will be placed on the precision of intermediate results. When set to “float32”, “float32” would be used for accumulator and intermediate result, but only effective when input and output are of float16 dtype.

Note

  • weight usually has shape (in_channels, out_channels, height, width) , if groups is not 1, shape will be (groups, in_channels // groups, out_channels // groups, height, width)

  • bias usually has shape (1, out_channels, *1)