class paddle.nn. Unflatten ( axis, shape, name=None ) [source]

This interface is used to construct a callable object of the Unflatten class. For more details, refer to code examples. It a certain dimension of the input x Tensor into a desired shape.

  • axis (int) – axis to be unflattened, specified as an index into x.shape.

  • shape (list|tuple|Tensor) – Unflatten shape on the specified axis. At most one dimension of the target shape can be -1. If the input shape does not contain -1 , the product of all elements in shape should be equal to x.shape[axis]. The data type is int . If shape is a list or tuple, the elements of it should be integers or Tensors with shape []. If shape is an Tensor, it should be an 1-D Tensor.

  • name (str, optional) – For details, please refer to Name. Generally, no setting is required. Default: None.




import paddle

x = paddle.randn(shape=[4, 6, 8])
shape = [2, 3]
axis = 1
unflatten = paddle.nn.Unflatten(axis, shape)
res = unflatten(x)
# [4, 2, 3, 8]
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.