Fold

class paddle.nn. Fold ( output_sizes, kernel_sizes, dilations=1, paddings=0, strides=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
  • output_sizes (list) – 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, optional) – 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, 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 decriabled above.

Examples

>>> import paddle
>>> import paddle.nn as nn

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

forward

Defines the computation performed at every call. Should be overridden by all subclasses.

Parameters
  • *inputs (tuple) – unpacked tuple arguments

  • **kwargs (dict) – unpacked dict arguments

extra_repr ( )

extra_repr

Extra representation of this layer, you can have custom implementation of your own layer.