class paddle.fluid.dygraph.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.


*layers (tuple) – Layers or iterable name Layer pairs.


import paddle.fluid as fluid
import numpy as np

data = np.random.uniform(-1, 1, [30, 10]).astype('float32')
with fluid.dygraph.guard():
    data = fluid.dygraph.to_variable(data)
    # create Sequential with iterable Layers
    model1 = fluid.dygraph.Sequential(
        fluid.Linear(10, 1), fluid.Linear(1, 2)
    model1[0]  # access the first layer
    res1 = model1(data)  # sequential execution

    # create Sequential with name Layer pairs
    model2 = fluid.dygraph.Sequential(
        ('l1', fluid.Linear(10, 2)),
        ('l2', fluid.Linear(2, 3))
    model2['l1']  # access l1 layer
    model2.add_sublayer('l3', fluid.Linear(3, 3))  # add sublayer
    res2 = model2(data)  # sequential execution

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

  • *inputs (tuple) – unpacked tuple arguments

  • **kwargs (dict) – unpacked dict arguments