Sequential

class paddle.nn. Sequential ( *layers ) [source]

Sequential container. Sub layers will be added to this container in the order of argument in the constructor. The argument passed to the constructor can be iterable Layers or iterable name Layer pairs.

Parameters

layers (Layer|list|tuple) – Layer or list/tuple of iterable name Layer pair.

Returns

None.

Examples

>>> import paddle

>>> data = paddle.uniform(shape=[30, 10], dtype='float32')
>>> # create Sequential with iterable Layers
>>> model1 = paddle.nn.Sequential(
...     paddle.nn.Linear(10, 1), paddle.nn.Linear(1, 2)
>>> )
>>> model1[0]  # access the first layer
>>> res1 = model1(data)  # sequential execution

>>> # create Sequential with name Layer pairs
>>> model2 = paddle.nn.Sequential(
...     ('l1', paddle.nn.Linear(10, 2)),
...     ('l2', paddle.nn.Linear(2, 3))
>>> )
>>> model2['l1']  # access l1 layer
>>> model2.add_sublayer('l3', paddle.nn.Linear(3, 3))  # add sublayer
>>> res2 = model2(data)  # sequential execution
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

Used in the guide/tutorials