conv1d_transpose¶

The 1-D convolution transpose layer calculates the output based on the input, filter, and dilation, stride, padding. Input(Input) and output(Output) are in ‘NCL’ format or ‘NLC’ where N is batch size, C is the number of channels, L is the length of the feature. 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)$

Where:

• $$X$$: Input value, a 3-D Tensor with ‘NCL’ format or ‘NLC’ format.

• $$W$$: Filter value, a 3-D Tensor with ‘MCK’ format.

• $$\\ast$$: Convolution operation.

• $$b$$: Bias value, a 2-D Tensor with shape [M, 1].

• $$\\sigma$$: Activation function.

• $$Out$$: Output value, a 3-D Tensor with data format ‘NCL’ or ‘NLC’, the shape of $$Out$$ and $$X$$ may be different.

Example

• Input:

Input shape: $$(N, C_{in}, L_{in})$$

Filter shape: $$(C_{in}, C_{out}, L_f)$$

• Output:

Output shape: $$(N, C_{out}, L_{out})$$

Where

$\begin{split}L^\prime_{out} &= (L_{in} - 1) * stride - 2 * padding + dilation * (L_f - 1) + 1 \\ L_{out} &\in [ L^\prime_{out}, L^\prime_{out} + stride ]\end{split}$

Note

The conv1d_transpose can be seen as the backward of the conv1d. For conv1d, when stride > 1, conv1d maps multiple input shape to the same output shape, so for conv1d_transpose, when stride > 1, input shape maps multiple output shape. If output_size is None, $$L_{out} = L^\prime_{out}$$; else, the $$L_{out}$$ of the output size must between $$L^\prime_{out}$$ and $$L^\prime_{out} + stride$$.

Parameters
• x (Tensor) – 3-D tensor with [N, C, L] or [N, L, C] format, its data type is float32 or float64.

• weight (Tensor) – The convolution kernel, a Tensor with shape [C, M/g, K], where M is the number of output channels(filters), g is the number of groups, K is the size of the kernel.

• bias (Tensor, optional) – The bias, a Tensor with shape [M, ].

• stride (int|tuple|list, optional) – The stride size. It means the stride in transposed convolution. If stride is a list/tuple, it must contain one integer, (stride_size). Default: stride = 1.

• output_padding (int|list|tuple, optional) – The count of zeros to be added to tail of each dimension. If it is a list/tuple, it must contain one integer. Default: 0.

• groups (int, optional) – The groups number of the conv1d transpose function. Inspired by grouped convolution in Alex Krizhevsky’s Deep CNN paper, in which when group=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: groups = 1.

• dilation (int|tuple|list, optional) – The dilation size. It means the spacing between the kernel points. If dilation is a list/tuple, it must contain one integer, (dilation_size). Default: dilation = 1.

• output_size (int|tuple|list, optional) – The output image size. If output size is a tuple/list, it must contain one integer, (feature_length). None if use filter_size(shape of weight), padding, and stride to calculate output_size.

• data_format (str, optional) – Specify the data format of the input, and the data format of the output will be consistent with that of the input. An optional string from: “NCL”, “NLC”. The default is “NCL”. When it is “NCL”, the data is stored in the order of: [batch_size, input_channels, input_length].

• name (str, optional) – For detailed information, please refer to Name. Usually name is no need to set and None by default.

Returns

A tensor representing the result of 1-D transpose convolution, whose data type is the same with input. And its shape is (num_batches, channels, length) when data_format is “NCL” and (num_batches, length, channels) when data_format is “NLC”.

Examples

>>> import paddle