mindspore.nn.Conv1dTranspose
- class mindspore.nn.Conv1dTranspose(in_channels, out_channels, kernel_size, stride=1, pad_mode='same', padding=0, dilation=1, group=1, has_bias=False, weight_init='normal', bias_init='zeros')[source]
1D transposed convolution layer.
Compute a 1D transposed convolution, which is also known as a deconvolution (although it is not an actual deconvolution).
x is typically of shape \((N, C, W)\), where \(N\) is batch size and \(C\) is channel number.
If the ‘pad_mode’ is set to be “pad”, the width of output is defined as:
\[W_{out} = (W_{in} - 1) \times \text{stride} - 2 \times \text{padding} + \text{dilation} \times (\text{ks_w} - 1) + 1\]where \(\text{ks_w}\) is the width of the convolution kernel.
- Parameters
in_channels (int) – The number of channels in the input space.
out_channels (int) – The number of channels in the output space.
kernel_size (int) – int, which specifies the width of the 1D convolution window.
stride (int) – The distance of kernel moving, an int number that represents the width of movement. Default: 1.
pad_mode (str) –
Select the mode of the pad. The optional values are “pad”, “same”, “valid”. Default: “same”.
pad: Implicit paddings on both sides of the input x.
same: Adopted the way of completion.
valid: Adopted the way of discarding.
padding (int) – Implicit paddings on both sides of the input x. Default: 0.
dilation (int) – The data type is int. Specifies the dilation rate to use for dilated convolution. If set to be \(k > 1\), there will be \(k - 1\) pixels skipped for each sampling location. Its value must be greater or equal to 1 and bounded by the width of the input x. Default: 1.
group (int) – Splits filter into groups, in_channels and out_channels must be divisible by the number of groups. This is not support for Davinci devices when group > 1. Default: 1.
has_bias (bool) – Specifies whether the layer uses a bias vector. Default: False.
weight_init (Union[Tensor, str, Initializer, numbers.Number]) – Initializer for the convolution kernel. It can be a Tensor, a string, an Initializer or a numbers.Number. When a string is specified, values from ‘TruncatedNormal’, ‘Normal’, ‘Uniform’, ‘HeUniform’ and ‘XavierUniform’ distributions as well as constant ‘One’ and ‘Zero’ distributions are possible. Alias ‘xavier_uniform’, ‘he_uniform’, ‘ones’ and ‘zeros’ are acceptable. Uppercase and lowercase are both acceptable. Refer to the values of Initializer for more details. Default: ‘normal’.
bias_init (Union[Tensor, str, Initializer, numbers.Number]) – Initializer for the bias vector. Possible Initializer and string are the same as ‘weight_init’. Refer to the values of Initializer for more details. Default: ‘zeros’.
- Inputs:
x (Tensor) - Tensor of shape \((N, C_{in}, W_{in})\).
- Outputs:
Tensor of shape \((N, C_{out}, W_{out})\).
- Raises
TypeError – If in_channels, out_channels, kernel_size, stride, padding or dilation is not an int.
ValueError – If in_channels, out_channels, kernel_size, stride or dilation is less than 1.
ValueError – If padding is less than 0.
ValueError – If pad_mode is not one of ‘same’, ‘valid’, ‘pad’.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> net = nn.Conv1dTranspose(3, 64, 4, has_bias=False, weight_init='normal', pad_mode='pad') >>> x = Tensor(np.ones([1, 3, 50]), mindspore.float32) >>> output = net(x).shape >>> print(output) (1, 64, 53)