From a25de3e0605101a4a264ad5a73fa0ffac8e951fe Mon Sep 17 00:00:00 2001 From: Wang Huan Date: Sun, 27 Sep 2020 06:53:30 +0000 Subject: [PATCH] modify Sequential doc, test=develop --- python/paddle/fluid/dygraph/container.py | 35 ++++++++++++------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/python/paddle/fluid/dygraph/container.py b/python/paddle/fluid/dygraph/container.py index 8a8787da3a5..dc43062aa9f 100644 --- a/python/paddle/fluid/dygraph/container.py +++ b/python/paddle/fluid/dygraph/container.py @@ -34,27 +34,26 @@ class Sequential(Layer): Examples: .. code-block:: python - import paddle.fluid as fluid + import paddle 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 + data = paddle.to_tensor(data) + # 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 """ -- GitLab