提交 93de124c 编写于 作者: A AIFollowers 提交者: chengduo

modify some initializer api (#17301)

* test=develop modify some initializer api

* test=develop modify API.spec

* test=develop modify API.spec

* test=develop modify API.spec

* test=develop modify API.spec
上级 d5239109
...@@ -68,8 +68,8 @@ paddle.fluid.initializer.TruncatedNormalInitializer.__init__ (ArgSpec(args=['sel ...@@ -68,8 +68,8 @@ paddle.fluid.initializer.TruncatedNormalInitializer.__init__ (ArgSpec(args=['sel
paddle.fluid.initializer.XavierInitializer.__init__ (ArgSpec(args=['self', 'uniform', 'fan_in', 'fan_out', 'seed'], varargs=None, keywords=None, defaults=(True, None, None, 0)), ('document', '6adf97f83acf6453d4a6a4b1070f3754')) paddle.fluid.initializer.XavierInitializer.__init__ (ArgSpec(args=['self', 'uniform', 'fan_in', 'fan_out', 'seed'], varargs=None, keywords=None, defaults=(True, None, None, 0)), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
paddle.fluid.initializer.BilinearInitializer.__init__ (ArgSpec(args=['self'], varargs=None, keywords=None, defaults=None), ('document', 'd389912dc079cbef432335a00017cec0')) paddle.fluid.initializer.BilinearInitializer.__init__ (ArgSpec(args=['self'], varargs=None, keywords=None, defaults=None), ('document', 'd389912dc079cbef432335a00017cec0'))
paddle.fluid.initializer.MSRAInitializer.__init__ (ArgSpec(args=['self', 'uniform', 'fan_in', 'seed'], varargs=None, keywords=None, defaults=(True, None, 0)), ('document', '53c757bed9345f2ad3361902531e7cf5')) paddle.fluid.initializer.MSRAInitializer.__init__ (ArgSpec(args=['self', 'uniform', 'fan_in', 'seed'], varargs=None, keywords=None, defaults=(True, None, 0)), ('document', '53c757bed9345f2ad3361902531e7cf5'))
paddle.fluid.initializer.force_init_on_cpu (ArgSpec(args=[], varargs=None, keywords=None, defaults=None), ('document', '6d0f3e22c90d9d500d36ff57daf056ee')) paddle.fluid.initializer.force_init_on_cpu (ArgSpec(args=[], varargs=None, keywords=None, defaults=None), ('document', '2c6748c1dd1d85f800462869ea7a747f'))
paddle.fluid.initializer.init_on_cpu (ArgSpec(args=[], varargs=None, keywords=None, defaults=None), ('document', 'a6d7011ca3d8c0d454dac3a56eae0c29')) paddle.fluid.initializer.init_on_cpu (ArgSpec(args=[], varargs=None, keywords=None, defaults=None), ('document', '280b581f5a77e746e47decbc57a7b30a'))
paddle.fluid.initializer.NumpyArrayInitializer.__init__ (ArgSpec(args=['self', 'value'], varargs=None, keywords=None, defaults=None), ('document', '6adf97f83acf6453d4a6a4b1070f3754')) paddle.fluid.initializer.NumpyArrayInitializer.__init__ (ArgSpec(args=['self', 'value'], varargs=None, keywords=None, defaults=None), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
paddle.fluid.layers.fc (ArgSpec(args=['input', 'size', 'num_flatten_dims', 'param_attr', 'bias_attr', 'act', 'is_test', 'name'], varargs=None, keywords=None, defaults=(1, None, None, None, False, None)), ('document', '424e898365195e3ccbc2e7dc8b63605e')) paddle.fluid.layers.fc (ArgSpec(args=['input', 'size', 'num_flatten_dims', 'param_attr', 'bias_attr', 'act', 'is_test', 'name'], varargs=None, keywords=None, defaults=(1, None, None, None, False, None)), ('document', '424e898365195e3ccbc2e7dc8b63605e'))
paddle.fluid.layers.embedding (ArgSpec(args=['input', 'size', 'is_sparse', 'is_distributed', 'padding_idx', 'param_attr', 'dtype'], varargs=None, keywords=None, defaults=(False, False, None, None, 'float32')), ('document', '6f9f96d2a1517cd1affebc960c3526f7')) paddle.fluid.layers.embedding (ArgSpec(args=['input', 'size', 'is_sparse', 'is_distributed', 'padding_idx', 'param_attr', 'dtype'], varargs=None, keywords=None, defaults=(False, False, None, None, 'float32')), ('document', '6f9f96d2a1517cd1affebc960c3526f7'))
......
...@@ -42,8 +42,9 @@ def force_init_on_cpu(): ...@@ -42,8 +42,9 @@ def force_init_on_cpu():
.. code-block:: python .. code-block:: python
if force_init_on_cpu(): if fluid.initializer.force_init_on_cpu():
create_op('force_cpu': force_init_on_cpu()) step = fluid.layers.create_global_var(
shape=[2,3], value=1.0, dtype='float32')
""" """
return _force_init_on_cpu_ return _force_init_on_cpu_
...@@ -57,8 +58,9 @@ def init_on_cpu(): ...@@ -57,8 +58,9 @@ def init_on_cpu():
Examples: Examples:
.. code-block:: python .. code-block:: python
with init_on_cpu(): with fluid.initializer.init_on_cpu():
step = layers.create_global_var() step = fluid.layers.create_global_var(
shape=[2,3], value=1.0, dtype='float32')
""" """
global _force_init_on_cpu_ global _force_init_on_cpu_
...@@ -131,8 +133,10 @@ class ConstantInitializer(Initializer): ...@@ -131,8 +133,10 @@ class ConstantInitializer(Initializer):
Examples: Examples:
.. code-block:: python .. code-block:: python
x = fluid.layers.data(name="data", shape=[32, 32], dtype="float32")
fc = fluid.layers.fc(input=x, size=10, fc = fluid.layers.fc(input=x, size=10,
param_attr=fluid.initializer.Constant(value=2.0)) param_attr=fluid.initializer.Constant(value=2.0))
""" """
def __init__(self, value=0.0, force_cpu=False): def __init__(self, value=0.0, force_cpu=False):
...@@ -288,8 +292,10 @@ class NormalInitializer(Initializer): ...@@ -288,8 +292,10 @@ class NormalInitializer(Initializer):
Examples: Examples:
.. code-block:: python .. code-block:: python
x = fluid.layers.data(name="data", shape=[32, 32], dtype="float32")
fc = fluid.layers.fc(input=x, size=10, fc = fluid.layers.fc(input=x, size=10,
param_attr=fluid.initializer.Normal(loc=0.0, scale=2.0)) param_attr=fluid.initializer.Normal(loc=0.0, scale=2.0))
""" """
def __init__(self, loc=0.0, scale=1.0, seed=0): def __init__(self, loc=0.0, scale=1.0, seed=0):
...@@ -602,9 +608,10 @@ class MSRAInitializer(Initializer): ...@@ -602,9 +608,10 @@ class MSRAInitializer(Initializer):
Examples: Examples:
.. code-block:: python .. code-block:: python
fc = fluid.layers.fc( x = fluid.layers.data(name="data", shape=[32, 32], dtype="float32")
input=queries, size=10, fc = fluid.layers.fc(input=x, size=10,
param_attr=fluid.initializer.MSRA(uniform=False)) param_attr=fluid.initializer.MSRA(uniform=False))
""" """
def __init__(self, uniform=True, fan_in=None, seed=0): def __init__(self, uniform=True, fan_in=None, seed=0):
...@@ -704,14 +711,19 @@ class BilinearInitializer(Initializer): ...@@ -704,14 +711,19 @@ class BilinearInitializer(Initializer):
.. code-block:: python .. code-block:: python
factor = 2 factor = 2
w_attr = ParamAttr(learning_rate=0., regularizer=L2Decay(0.), C = 2
initializer=Bilinear()) w_attr = fluid.initializer.ParamAttr(
learning_rate=0.,
regularizer=fluid.regularizer.L2Decay(0.),
initializer=fluid.initializer.Bilinear())
x = fluid.layers.data(name="data", shape=[3, 32, 32],
dtype="float32")
conv_up = fluid.layers.conv2d_transpose( conv_up = fluid.layers.conv2d_transpose(
input, input=x,
num_filters=C, num_filters=C,
output_size=None, output_size=None,
filter_size=2 * factor - factor % 2, filter_size=2 * factor - factor % 2,
padding=ceil((factor - 1) / 2.), padding=int(math.ceil((factor - 1) / 2.)),
stride=factor, stride=factor,
groups=C, groups=C,
param_attr=w_attr, param_attr=w_attr,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册