fold

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

This Op is used to 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.

\[H_out &= output_size[0] W_out &= output_size[1] C_out &= C_in / kernel\_sizes[0] / kernel\_sizes[1]\]
Parameters
  • x (Tensor) – 3-D Tensor, input tensor of format [N, C, L], data type can be float32 or float64

  • output_sizes (int|list|tuple) – The size of output size, should be [output_size_h, output_size_w] or an interger 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) – The strides, should be [stride_h, stride_w] or an integer stride treated as [sride, stride]. For default, strides will be [1, 1].

  • paddings (int|list|tuple) – 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) – 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 decriabled 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)
# y.shape = [2,3,4,5]