提交 a25de3e0 编写于 作者: W Wang Huan

modify Sequential doc, test=develop

上级 09f19532
...@@ -34,27 +34,26 @@ class Sequential(Layer): ...@@ -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
""" """
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册