Conv3DTranspose¶
- class paddle.nn. Conv3DTranspose ( in_channels, out_channels, kernel_size, stride=1, padding=0, output_padding=0, dilation=1, groups=1, weight_attr=None, bias_attr=None, data_format='NCDHW' ) [source]
-
Convlution3D transpose layer The convolution3D transpose layer calculates the output based on the input, filter, and dilations, strides, paddings. Input(Input) and output(Output) are in NCDHW format. Where N is batch size, C is the number of channels, D is the depth of the feature, H is the height of the feature, and W is the width of the feature. Parameters(dilations, strides, paddings) are two elements. These two elements represent height and width, respectively. The details of convolution transpose layer, please refer to the following explanation and references therein. If bias attribution and activation type are provided, bias is added to the output of the convolution, and the corresponding activation function is applied to the final result. For each input \(X\), the equation is:
\[Out = \sigma (W \ast X + b)\]In the above equation:
\(X\): Input value, a tensor with NCDHW format.
\(W\): Filter value, a tensor with CMDHW format.
\(\ast\): Convolution operation.
\(b\): Bias value, a 1-D tensor with shape [M].
\(\sigma\): Activation function.
\(Out\): Output value, the shape of \(Out\) and \(X\) may be different.
Note
The conv3d_transpose can be seen as the backward of the conv3d. For conv3d, when stride > 1, conv3d maps multiple input shape to the same output shape, so for conv3d_transpose, when stride > 1, input shape maps multiple output shape. If output_size is None, \(H_{out} = H^\prime_{out}, W_{out} = W^\prime_{out}\); else, the \(D_{out}\) of the output size must between \(D^\prime_{out}\) and \(D^\prime_{out} + strides[0]\), the \(H_{out}\) of the output size must between \(H^\prime_{out}\) and \(H^\prime_{out} + strides[1]\), and the \(W_{out}\) of the output size must between \(W^\prime_{out}\) and \(W^\prime_{out} + strides[2]\), conv3d_transpose can compute the kernel size automatically.
- Parameters
-
in_channels (int) – The number of channels in the input image.
out_channels (int) – The number of channels produced by the convolution.
kernel_size (int|list|tuple) – The kernel size. If kernel_size is a list/tuple, it must contain three integers, (kernel_size_D, kernel_size_H, kernel_size_W). Otherwise, the kernel will be a square.
stride (int|list|tuple, optional) – The stride size. It means the stride in transposed convolution. If stride is a list/tuple, it must contain three integers, (stride_depth, stride_height, stride_width). Otherwise, stride_depth = stride_height = stride_width = stride. Default: 1.
padding (int|str|tuple|list, optional) – The padding size. Padding coule be in one of the following forms. 1. a string in [‘valid’, ‘same’]. 2. an int, which means each spartial dimension(depth, height, width) is zero paded by size of padding 3. a list[int] or tuple[int] whose length is the number of spartial dimensions, which contains the amount of padding on each side for each spartial dimension. It has the form [pad_d1, pad_d2, …]. 4. a list[int] or tuple[int] whose length is 2 * number of spartial dimensions. It has the form [pad_before, pad_after, pad_before, pad_after, …] for all spartial dimensions. 5. a list or tuple of pairs of ints. It has the form [[pad_before, pad_after], [pad_before, pad_after], …]. Note that, the batch dimension and channel dimension are also included. Each pair of integers correspond to the amount of padding for a dimension of the input. Padding in batch dimension and channel dimension should be [0, 0] or (0, 0). Default: 0.
output_padding (int|list|tuple, optional) – Additional size added to one side of each dimension in the output shape. Default: 0.
dilation (int|list|tuple, optional) – The dilation size. If dilation is a list/tuple, it must contain three integers, (dilation_D, dilation_H, dilation_W). Otherwise, the dilation_D = dilation_H = dilation_W = dilation. Default: 1.
groups (int, optional) – The groups number of the Conv3D transpose layer. Inspired by grouped convolution in Alex Krizhevsky’s Deep CNN paper, in which when groups = 2, the first half of the filters is only connected to the first half of the input channels, while the second half of the filters is only connected to the second half of the input channels. Default: 1.
weight_attr (ParamAttr, optional) – The parameter attribute for learnable parameters/weights of conv3d_transpose. If it is set to None or one attribute of ParamAttr, conv3d_transpose will create ParamAttr as param_attr. If the Initializer of the param_attr is not set, the parameter is initialized with Xavier. Default: None.
bias_attr (ParamAttr|bool, optional) – The parameter attribute for the bias of conv3d_transpose. If it is set to False, no bias will be added to the output units. If it is set to None or one attribute of ParamAttr, conv3d_transpose will create ParamAttr as bias_attr. If the Initializer of the bias_attr is not set, the bias is initialized zero. Default: None.
data_format (str, optional) – Data format that specifies the layout of input. It can be “NCDHW” or “NDHWC”. Default: “NCDHW”.
Attribute:
weight (Parameter): the learnable weights of filters of this layer.
bias (Parameter): the learnable bias of this layer.
Shape:
x: \((N, C_{in}, D_{in}, H_{in}, W_{in})\)
weight: \((C_{in}, C_{out}, K_{d}, K_{h}, K_{w})\)
bias: \((C_{out})\)
output: \((N, C_{out}, D_{out}, H_{out}, W_{out})\)
Where
\[ \begin{align}\begin{aligned}D^\prime_{out} &= (D_{in} - 1) * strides[0] - 2 * paddings[0] + dilations[0] * (kernel\_size[0] - 1) + 1\\H^\prime_{out} &= (H_{in} - 1) * strides[1] - 2 * paddings[1] + dilations[1] * (kernel\_size[1] - 1) + 1\\W^\prime_{out} &= (W_{in} - 1) * strides[2] - 2 * paddings[2] + dilations[2] * (kernel\_size[2] - 1) + 1\end{aligned}\end{align} \]Examples
>>> import paddle >>> import paddle.nn as nn >>> paddle.disable_static() >>> x_var = paddle.uniform((2, 4, 8, 8, 8), dtype='float32', min=-1., max=1.) >>> conv = nn.Conv3DTranspose(4, 6, (3, 3, 3)) >>> y_var = conv(x_var) >>> print(y_var.shape) [2, 6, 10, 10, 10]
-
forward
(
x,
output_size=None
)
forward¶
-
Defines the computation performed at every call. Should be overridden by all subclasses.
- Parameters
-
*inputs (tuple) – unpacked tuple arguments
**kwargs (dict) – unpacked dict arguments