class paddle.nn. Unfold ( kernel_sizes, dilations=1, paddings=0, strides=1, name=None ) [source]

Returns a col buffer of sliding local blocks of input x, also known as im2col for batched 2D image tensors. For each block under the convolution filter, all element will be rearranged as a column. While the convolution filter sliding over the input feature map, a series of such columns will be formed.

For each input \(x\) with shape [N, C, H, W], the output shape [N, Cout, Lout] can be calculated as following.

See paddle.nn.functional.unfold for more details.

  • 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


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

>>> x = paddle.randn((100, 3, 224, 224))
>>> unfold = nn.Unfold(kernel_sizes=[3, 3])
>>> result = unfold(x)
>>> print(result.shape)
[100, 27, 49284]
forward ( input )


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

  • *inputs (tuple) – unpacked tuple arguments

  • **kwargs (dict) – unpacked dict arguments

extra_repr ( )


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