未验证 提交 0fa1b2f3 编写于 作者: L littletomatodonkey 提交者: GitHub

fix initalization and regularization docs (#23492)

上级 17133308
......@@ -133,14 +133,16 @@ class ConstantInitializer(Initializer):
Args:
value (float32): constant value to initialize the variable
force_cpu (bool): place for initialization, if set true, initialization will
be forced on CPU even if executor is set on CUDA. default false.
Examples:
.. code-block:: python
import paddle.fluid as fluid
x = fluid.data(name="data", shape=[8, 32, 32], dtype="float32")
x = fluid.data(name="data", shape=[32, 32], dtype="float32")
fc = fluid.layers.fc(input=x, size=10,
param_attr=fluid.initializer.Constant(value=2.0))
param_attr=fluid.initializer.ConstantInitializer(value=2.0))
"""
......@@ -744,15 +746,16 @@ class BilinearInitializer(Initializer):
.. code-block:: python
import paddle.fluid as fluid
import math
factor = 2
C = 2
B = 8
H = W = 32
w_attr = fluid.param_attr.ParamAttr(
learning_rate=0.,
learning_rate=0.,
regularizer=fluid.regularizer.L2Decay(0.),
initializer=fluid.initializer.Bilinear())
x = fluid.data(name="data", shape=[B, 3, H, W],
x = fluid.data(name="data", shape=[B, 3, H, W],
dtype="float32")
conv_up = fluid.layers.conv2d_transpose(
input=x,
......
......@@ -134,8 +134,8 @@ class L2DecayRegularizer(WeightDecayRegularizer):
main_prog = fluid.Program()
startup_prog = fluid.Program()
with fluid.program_guard(main_prog, startup_prog):
data = fluid.layers.data(name='image', shape=[3, 28, 28], dtype='float32')
label = fluid.layers.data(name='label', shape=[1], dtype='int64')
data = fluid.data(name='image', shape=[256, 3, 28, 28], dtype='float32')
label = fluid.data(name='label', shape=[256, 1], dtype='int64')
hidden = fluid.layers.fc(input=data, size=128, act='relu')
prediction = fluid.layers.fc(input=hidden, size=10, act='softmax')
loss = fluid.layers.cross_entropy(input=prediction, label=label)
......@@ -213,8 +213,8 @@ class L1DecayRegularizer(WeightDecayRegularizer):
main_prog = fluid.Program()
startup_prog = fluid.Program()
with fluid.program_guard(main_prog, startup_prog):
data = fluid.layers.data(name='image', shape=[3, 28, 28], dtype='float32')
label = fluid.layers.data(name='label', shape=[1], dtype='int64')
data = fluid.data(name='image', shape=[256, 3, 28, 28], dtype='float32')
label = fluid.data(name='label', shape=[256, 1], dtype='int64')
hidden = fluid.layers.fc(input=data, size=128, act='relu')
prediction = fluid.layers.fc(input=hidden, size=10, act='softmax')
loss = fluid.layers.cross_entropy(input=prediction, label=label)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册