modify Sequential doc, test=develop (#27608)

my_2.0rc
wanghuancoder 5 years ago committed by GitHub
parent 7698e19928
commit 7ca66f1e06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -34,27 +34,26 @@ class Sequential(Layer):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid import paddle
import numpy as np import numpy as np
data = np.random.uniform(-1, 1, [30, 10]).astype('float32') data = np.random.uniform(-1, 1, [30, 10]).astype('float32')
with fluid.dygraph.guard(): data = paddle.to_tensor(data)
data = fluid.dygraph.to_variable(data) # create Sequential with iterable Layers
# create Sequential with iterable Layers model1 = paddle.nn.Sequential(
model1 = fluid.dygraph.Sequential( paddle.nn.Linear(10, 1), paddle.nn.Linear(1, 2)
fluid.Linear(10, 1), fluid.Linear(1, 2) )
) model1[0] # access the first layer
model1[0] # access the first layer res1 = model1(data) # sequential execution
res1 = model1(data) # sequential execution
# create Sequential with name Layer pairs
# create Sequential with name Layer pairs model2 = paddle.nn.Sequential(
model2 = fluid.dygraph.Sequential( ('l1', paddle.nn.Linear(10, 2)),
('l1', fluid.Linear(10, 2)), ('l2', paddle.nn.Linear(2, 3))
('l2', fluid.Linear(2, 3)) )
) model2['l1'] # access l1 layer
model2['l1'] # access l1 layer model2.add_sublayer('l3', paddle.nn.Linear(3, 3)) # add sublayer
model2.add_sublayer('l3', fluid.Linear(3, 3)) # add sublayer res2 = model2(data) # sequential execution
res2 = model2(data) # sequential execution
""" """

Loading…
Cancel
Save