ConvTranspose3d

class ConvTranspose3d(in_channels, out_channels, kernel_size, stride=1, padding=0, output_padding=0, dilation=1, groups=1, bias=True)[source]

Applies a 3D transposed convolution over an input tensor.

Only support the case that groups = 1 and conv_mode = “cross_correlation”.

ConvTranspose3d can be seen as the gradient of Conv3d operation with respect to its input.

Convolution3D usually reduces the size of input, while transposed convolution3d 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, int]]) – size of weight on spatial dimensions. If kernel_size is an int, the actual kernel size would be (kernel_size, kernel_size, kernel_size).

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

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

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

  • dilation (Union[int, tuple[int, int, int]]) – dilation of the 3D 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, depth, height, width). Default: 1.

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

Shape:
  • Input: \((N, C_{in}, D_{in}, H_{in}, W_{in})\) or \((C_{in}, D_{in}, H_{in}, W_{in})\)

  • Output: \((N, C_{out}, D_{out}, H_{out}, W_{out})\) or \((C_{out}, D_{out}, H_{out}, W_{out})\), where

\[D_{out} = (D_{in} - 1) \times \text{stride}[0] - 2 \times \text{padding}[0] + \text{dilation}[0] \times (\text{kernel\_size}[0] - 1) + \text{output\_padding}[0] + 1\]
\[H_{out} = (H_{in} - 1) \times \text{stride}[1] - 2 \times \text{padding}[1] + \text{dilation}[1] \times (\text{kernel\_size}[1] - 1) + \text{output\_padding}[1] + 1\]
\[W_{out} = (W_{in} - 1) \times \text{stride}[2] - 2 \times \text{padding}[2] + \text{dilation}[2] \times (\text{kernel\_size}[2] - 1) + \text{output\_padding}[2] + 1\]
Returns

module. The instance of the ConvTranspose3d module.

Return type

Return type

Examples

>>> import torch
>>> import megengine
>>> conv_transpose = megengine.module.conv.ConvTranspose3d(3, 64, 3, stride=2, padding=1)
>>> input = megengine.tensor(torch.randn(16, 3, 32, 32, 32))
>>> output = conv_transpose.forward(input)
>>> print(output.numpy().shape)
(16, 64, 63, 63, 63)

Note

  • weight usually has shape (in_channels, out_channels, depth, height, width) .

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