fold

paddle.nn.functional. fold ( x, output_sizes, kernel_sizes, strides=1, paddings=0, dilations=1, name=None ) [source]

Combines an array of sliding local blocks into a large containing tensor. also known as col2im when operated on batched 2D image tensor. Fold calculates each combined value in the resulting large tensor by summing all values from all containing blocks.

For each input \(x\) with shape [N, C_in , L], the output shape [N, C_out, H_out, W_out] can be calculated as following.

\[\begin{split}H_{out} &= output\_size[0] \\ W_{out} &= output\_size[1] \\ C_{out} &= \frac{C_{in}}{kernel\_sizes[0]\times kernel\_sizes[1]} \\\end{split}\]
Parameters
  • x (Tensor) – 3-D Tensor, input tensor of format [N, C, L], data type can be float32, float64, complex64 or complex128

  • output_sizes (int|list|tuple) – The size of output size, should be [output_size_h, output_size_w] or an integer o treated as [o, o].

  • kernel_sizes (int|list|tuple) – The size of convolution kernel, should be [k_h, k_w] or an integer k treated as [k, k].

  • strides (int|list|tuple, optional) – The strides, should be [stride_h, stride_w] or an integer stride treated as [stride, stride]. For default, strides will be [1, 1].

  • paddings (int|list|tuple, optional) – The paddings of each dimension, should be [padding_top, padding_left, padding_bottom, padding_right] or [padding_h, padding_w] or an integer padding. If [padding_h, padding_w] was given, it will expanded to [padding_h, padding_w, padding_h, padding_w]. If an integer padding was given, [padding, padding, padding, padding] will be used. For default, paddings will be [0, 0, 0, 0]

  • dilations (int|list|tuple, optional) – the dilations of convolution kernel, should be [dilation_h, dilation_w], or an integer dilation treated as [dilation, dilation]. For default, it will be [1, 1].

  • name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name

Returns

The tensor formed by combining a group of sliding local blocks The output shape is [N, Cout, H, W] as described above.

Examples

>>> import paddle
>>> import paddle.nn.functional as F

>>> x = paddle.randn([2,3*2*2,12])
>>> y = F.fold(x, output_sizes=[4, 5], kernel_sizes=2)
>>> x = paddle.randn([2,3*2*2,12])
>>> y = F.fold(x, output_sizes=[4, 5], kernel_sizes=2)
>>> print(y.shape)
[2, 3, 4, 5]