diff --git a/python/paddle/fluid/framework.py b/python/paddle/fluid/framework.py index 2c9e9a12b058bcd72ae0548f80ba1cbde681bc39..24df6db84290eb2813bd437be3281bd91fbe3f9c 100644 --- a/python/paddle/fluid/framework.py +++ b/python/paddle/fluid/framework.py @@ -5400,7 +5400,7 @@ def default_main_program(): This API can be used to get ``default main program`` which store the descriptions of Ops and tensors. - For example ``z = paddle.fluid.layers.elementwise_add(x, y)`` will create a new ``elementwise_add`` + For example ``z = paddle.add(x, y)`` will create a new ``add`` Op and a new ``z`` tensor, and they will be recorded in ``default main program`` . The ``default main program`` is the default value for ``Program`` parameter in @@ -5416,36 +5416,17 @@ def default_main_program(): .. code-block:: python import paddle - + paddle.enable_static() # Sample Network: - data = paddle.static.data(name='image', shape=[None, 3, 224, 224], dtype='float32') - label = paddle.static.data(name='label', shape=[None, 1], dtype='int64') - - conv1 = paddle.static.nn.conv2d(data, 4, 5, 1, act=None) - bn1 = paddle.static.nn.batch_norm(conv1, act='relu') - pool1 = paddle.fluid.layers.pool2d(bn1, 2, 'max', 2) - conv2 = paddle.static.nn.conv2d(pool1, 16, 5, 1, act=None) - bn2 = paddle.static.nn.batch_norm(conv2, act='relu') - pool2 = paddle.fluid.layers.pool2d(bn2, 2, 'max', 2) - - fc1 = paddle.static.nn.fc(x=pool2, size=50, activation='relu') - fc2 = paddle.static.nn.fc(x=fc1, size=102, activation='softmax') - - loss = paddle.nn.functional.loss.cross_entropy(input=fc2, label=label) - loss = paddle.mean(loss) - opt = paddle.optimizer.Momentum( - learning_rate=0.1, - momentum=0.9, - weight_decay=paddle.regularizer.L2Decay(1e-4)) - opt.minimize(loss) - - #print the number of blocks in the program, 1 in this case - print(paddle.static.default_main_program().num_blocks) #[1] + x = paddle.static.data(name='x', shape=[100, 100], dtype='float32') + y = paddle.static.data(name='x', shape=[100, 100], dtype='float32') + out = paddle.add(x, y) - #print the description of variable 'image' + #print the number of blocks in the program, 1 in this case + print(paddle.static.default_main_program().num_blocks) # 1 + #print the default_main_program print(paddle.static.default_main_program()) - """ return _main_program_