|
|
|
|
@ -42,8 +42,9 @@ def force_init_on_cpu():
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
if force_init_on_cpu():
|
|
|
|
|
create_op('force_cpu': force_init_on_cpu())
|
|
|
|
|
if fluid.initializer.force_init_on_cpu():
|
|
|
|
|
step = fluid.layers.create_global_var(
|
|
|
|
|
shape=[2,3], value=1.0, dtype='float32')
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
return _force_init_on_cpu_
|
|
|
|
|
@ -57,8 +58,9 @@ def init_on_cpu():
|
|
|
|
|
Examples:
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
with init_on_cpu():
|
|
|
|
|
step = layers.create_global_var()
|
|
|
|
|
with fluid.initializer.init_on_cpu():
|
|
|
|
|
step = fluid.layers.create_global_var(
|
|
|
|
|
shape=[2,3], value=1.0, dtype='float32')
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
global _force_init_on_cpu_
|
|
|
|
|
@ -131,8 +133,10 @@ class ConstantInitializer(Initializer):
|
|
|
|
|
Examples:
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
fc = fluid.layers.fc(input=x, size=10,
|
|
|
|
|
param_attr=fluid.initializer.Constant(value=2.0))
|
|
|
|
|
x = fluid.layers.data(name="data", shape=[32, 32], dtype="float32")
|
|
|
|
|
fc = fluid.layers.fc(input=x, size=10,
|
|
|
|
|
param_attr=fluid.initializer.Constant(value=2.0))
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def __init__(self, value=0.0, force_cpu=False):
|
|
|
|
|
@ -208,7 +212,7 @@ class UniformInitializer(Initializer):
|
|
|
|
|
import paddle.fluid as fluid
|
|
|
|
|
x = fluid.layers.data(name='x', shape=[1], dtype='float32')
|
|
|
|
|
fc = fluid.layers.fc(input=x, size=10,
|
|
|
|
|
param_attr=fluid.initializer.Uniform(low=-0.5, high=0.5))
|
|
|
|
|
param_attr=fluid.initializer.Uniform(low=-0.5, high=0.5))
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def __init__(self, low=-1.0, high=1.0, seed=0):
|
|
|
|
|
@ -288,8 +292,10 @@ class NormalInitializer(Initializer):
|
|
|
|
|
Examples:
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
fc = fluid.layers.fc(input=x, size=10,
|
|
|
|
|
param_attr=fluid.initializer.Normal(loc=0.0, scale=2.0))
|
|
|
|
|
x = fluid.layers.data(name="data", shape=[32, 32], dtype="float32")
|
|
|
|
|
fc = fluid.layers.fc(input=x, size=10,
|
|
|
|
|
param_attr=fluid.initializer.Normal(loc=0.0, scale=2.0))
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def __init__(self, loc=0.0, scale=1.0, seed=0):
|
|
|
|
|
@ -601,10 +607,11 @@ class MSRAInitializer(Initializer):
|
|
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
x = fluid.layers.data(name="data", shape=[32, 32], dtype="float32")
|
|
|
|
|
fc = fluid.layers.fc(input=x, size=10,
|
|
|
|
|
param_attr=fluid.initializer.MSRA(uniform=False))
|
|
|
|
|
|
|
|
|
|
fc = fluid.layers.fc(
|
|
|
|
|
input=queries, size=10,
|
|
|
|
|
param_attr=fluid.initializer.MSRA(uniform=False))
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def __init__(self, uniform=True, fan_in=None, seed=0):
|
|
|
|
|
@ -703,19 +710,24 @@ class BilinearInitializer(Initializer):
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
factor = 2
|
|
|
|
|
w_attr = ParamAttr(learning_rate=0., regularizer=L2Decay(0.),
|
|
|
|
|
initializer=Bilinear())
|
|
|
|
|
conv_up = fluid.layers.conv2d_transpose(
|
|
|
|
|
input,
|
|
|
|
|
num_filters=C,
|
|
|
|
|
output_size=None,
|
|
|
|
|
filter_size=2 * factor - factor % 2,
|
|
|
|
|
padding=ceil((factor - 1) / 2.),
|
|
|
|
|
stride=factor,
|
|
|
|
|
groups=C,
|
|
|
|
|
param_attr=w_attr,
|
|
|
|
|
bias_attr=False)
|
|
|
|
|
factor = 2
|
|
|
|
|
C = 2
|
|
|
|
|
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(
|
|
|
|
|
input=x,
|
|
|
|
|
num_filters=C,
|
|
|
|
|
output_size=None,
|
|
|
|
|
filter_size=2 * factor - factor % 2,
|
|
|
|
|
padding=int(math.ceil((factor - 1) / 2.)),
|
|
|
|
|
stride=factor,
|
|
|
|
|
groups=C,
|
|
|
|
|
param_attr=w_attr,
|
|
|
|
|
bias_attr=False)
|
|
|
|
|
|
|
|
|
|
Where, `num_filters=C` and `groups=C` means this is channel-wise transposed
|
|
|
|
|
convolution. The filter shape will be (C, 1, K, K) where K is `filer_size`,
|
|
|
|
|
|