mindspore.ops.Conv3DTranspose
- class mindspore.ops.Conv3DTranspose(*args, **kwargs)[source]
Computes a 3D transposed convolution, which is also known as a deconvolution (although it is not an actual deconvolution).
Input is typically of shape \((N, C, D, H, W)\), where \(N\) is batch size, \(C\) is channel number, \(D\) is depth, \(H\) is height, \(W\) is width.
If the ‘pad_mode’ is set to be “pad”, the depth, height and width of output are defined as:
\[ \begin{align}\begin{aligned}D_{out} = (D_{in} - 1) \times \text{stride_d} - 2 \times \text{padding_d} + \text{dilation_d} \times (\text{kernel_size_d} - 1) + \text{output_padding_d} + 1\\H_{out} = (H_{in} - 1) \times \text{stride_h} - 2 \times \text{padding_h} + \text{dilation_h} \times (\text{kernel_size_h} - 1) + \text{output_padding_h} + 1\\W_{out} = (W_{in} - 1) \times \text{stride_w} - 2 \times \text{padding_w} + \text{dilation_w} \times (\text{kernel_size_w} - 1) + \text{output_padding_w} + 1\end{aligned}\end{align} \]Where \(kernel_size_d\) is kernel size of depth, \(kernel_size_h\) is kernel size of height and \(kernel_size_w\) is kernel size of width. The same below: \(dialtion\) is Spacing between kernel elements, \(stride\) is The step length of each step, \(padding\) is zero-padding added to both sides of the input.
- Parameters
in_channel (int) – The channel of the input x.
out_channel (int) – The channel of the weight x.
kernel_size (Union[int, tuple[int]]) – The kernel size of the 3D convolution.
mode (int) – Modes for different convolutions. Default is 1. It is currently not used.
pad_mode (str) –
Specifies padding mode. The optional values are “same”, “valid”, “pad”. Default: “valid”.
same: Adopts the way of completion. The depth, height and width of the output will be the same as the input. The total number of padding will be calculated in depth, horizontal and vertical directions and evenly distributed to head and tail, top and bottom, left and right if possible. Otherwise, the last extra padding will be done from the tail, bottom and the right side. If this mode is set, pad and output_padding must be 0.
valid: Adopts the way of discarding. The possible largest depth, height and width of output will be returned without padding. Extra pixels will be discarded. If this mode is set, pad and output_padding must be 0.
pad: Implicit paddings on both sides of the input in depth, height, width. The number of pad will be padded to the input Tensor borders. pad must be greater than or equal to 0.
pad (Union(int, tuple[int])) – The pad value to be filled. Default: 0. If pad is an integer, the paddings of head, tail, top, bottom, left and right are the same, equal to pad. If pad is a tuple of six integers, the padding of head, tail, top, bottom, left and right equal to pad[0], pad[1], pad[2], pad[3], pad[4] and pad[5] correspondingly.
stride (Union(int, tuple[int])) – The stride to be applied to the convolution filter. Default: 1.
dilation (Union(int, tuple[int])) – Specifies the space to use between kernel elements. Default: 1.
group (int) – Splits input into groups. Default: 1. Only 1 is currently supported.
output_padding (Union(int, tuple[int])) – Add extra size to each dimension of the output. Default: 0.
data_format (str) – The optional value for data format. Currently only ‘NCDHW’ is supported.
- Inputs:
dout (Tensor) - the gradients with respect to the output of the convolution. The shape conforms to the default. data_format \((N, C_{in}, D_{out}, H_{out}, W_{out})\). Currently dout data type only supports float16 and float32.
weight (Tensor) - Set size of kernel is \((K_d, K_h, K_w)\), then the shape is \((C_{in}, C_{out}//group, K_d, K_h, K_w)\). Where \(group\) is the Args parameter. Currently weight data type only supports float16 and float32.
bias (Tensor) - Tensor of shape \(C_{out}\). Currently, only support none.
- Outputs:
Tensor, the gradients with respect to the input of convolution 3D. Tensor of shape math:(N, C_{out}//group, D_{out}, H_{out}, W_{out}), where \(group\) is the Args parameter.
- Supported Platforms:
Ascend
- Raises
TypeError – If in_channel, out_channel or group is not an int.
TypeError – If kernel_size, stride, pad , dilation or output_padding is neither an int not a tuple.
ValueError – If in_channel, out_channel, kernel_size, stride or dilation is less than 1.
ValueError – If pad is less than 0.
ValueError – If pad_mode is not one of ‘same’, ‘valid’, ‘pad’.
ValueError – If pad is a tuple whose length is not equal to 6.
ValueError – If pad_mode is not equal to ‘pad’ and pad is not equal to (0, 0, 0, 0, 0, 0).
ValueError – If data_format is not ‘NCDHW’.
TypeError – If dout and weight data type is not float16.
ValueError – If bias is not none. The rank of dout and weight is not 5.
Examples
>>> import numpy as np >>> from mindspore import Tensor >>> from mindspore.common import dtype as mstype >>> import mindspore.ops as ops >>> input_x = Tensor(np.ones([32, 16, 10, 32, 32]), mstype.float16) >>> weight = Tensor(np.ones([16, 3, 4, 6, 2]), mstype.float16) >>> conv3d_transpose = ops.Conv3DTranspose(in_channel=16, out_channel=3, kernel_size=(4, 6, 2)) >>> output = conv3d_transpose(input_x, weight) >>> print(output.shape) (32, 3, 13, 37, 33)