Flatten

class paddle.nn. Flatten ( start_axis=1, stop_axis=- 1 ) [source]

This interface is used to construct a callable object of the FLatten class. For more details, refer to code examples. It implements flatten a contiguous range of dims into a tensor.

Parameters
  • start_axis (int) – first dim to flatten (default = 1)

  • stop_axis (int) – last dim to flatten (default = -1).

Returns

None

Examples

import paddle
import numpy as np

inp_np = np.ones([5, 2, 3, 4]).astype('float32')
inp_np = paddle.to_tensor(inp_np)
flatten = paddle.nn.Flatten(start_axis=1, stop_axis=2)
flatten_res = flatten(inp_np)
forward ( input )

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

Parameters
  • *inputs (tuple) – unpacked tuple arguments

  • **kwargs (dict) – unpacked dict arguments