提交 404ca8d4 编写于 作者: C ceci3

sync ch sample to eng

上级 634b8c50
......@@ -67,18 +67,9 @@ moving_mean和moving_var是训练过程中统计得到的全局均值和方差
.. code-block:: python
import paddle.fluid as fluid
import numpy as np
x = fluid.layers.data(name='x', shape=[3, 7, 3, 7], dtype='float32', append_batch_size=False)
hidden1 = fluid.layers.fc(input=x, size=200)
param_attr = fluid.ParamAttr(name='batch_norm_w', initializer=fluid.initializer.Constant(value=1.0))
bias_attr = fluid.ParamAttr(name='batch_norm_b', initializer=fluid.initializer.Constant(value=0.0))
hidden2 = fluid.layers.batch_norm(input=hidden1, param_attr = param_attr, bias_attr = bias_attr)
place = fluid.CPUPlace()
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())
np_x = np.random.random(size=(3, 7, 3, 7)).astype('float32')
output = exe.run(feed={"x": np_x}, fetch_list = [hidden2])
print(output)
x = fluid.data(name='x', shape=[3, 7, 3, 7], dtype='float32', append_batch_size=False)
hidden1 = fluid.layers.fc(input=x, size=200, param_attr='fc1.w')
hidden2 = fluid.layers.batch_norm(input=hidden1)
.. code-block:: python
......
......@@ -28,17 +28,9 @@ cos_sim
.. code-block:: python
import paddle.fluid as fluid
import numpy as np
x = fluid.layers.data(name='x', shape=[3, 7], dtype='float32', append_batch_size=False)
y = fluid.layers.data(name='y', shape=[1, 7], dtype='float32', append_batch_size=False)
x = fluid.data(name='x', shape=[3, 7], dtype='float32')
y = fluid.data(name='y', shape=[1, 7], dtype='float32')
out = fluid.layers.cos_sim(x, y)
place = fluid.CPUPlace()
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())
np_x = np.random.random(size=(3, 7)).astype('float32')
np_y = np.random.random(size=(1, 7)).astype('float32')
output = exe.run(feed={"x": np_x, "y": np_y}, fetch_list = [out])
print(output)
......@@ -46,13 +46,6 @@ dropout操作符可以从程序中移除,使程序变得高效。
.. code-block:: python
import paddle.fluid as fluid
import numpy as np
x = fluid.layers.data(name="x", shape=[32, 32], dtype="float32")
droped = fluid.layers.dropout(x, dropout_prob=0.5)
place = fluid.CPUPlace()
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())
np_x = np.random.random(size=(32, 32)).astype('float32')
output = exe.run(feed={"x": np_x}, fetch_list = [droped])
print(output)
x = fluid.data(name="data", shape=[None, 32, 32], dtype="float32")
dropped = fluid.layers.dropout(x, dropout_prob=0.5)
......@@ -39,16 +39,7 @@ NCHW[batch,in_channels,in_height,in_width]
.. code-block:: python
import paddle.fluid as fluid
import numpy as np
x = fluid.layers.data(name='x', shape=[3, 7, 3, 7], dtype='float32', append_batch_size=False)
hidden1 = fluid.layers.fc(input=x, size=200)
param_attr = fluid.ParamAttr(name='instance_norm_w', initializer=fluid.initializer.Constant(value=1.0))
bias_attr = fluid.ParamAttr(name='instance_norm_b', initializer=fluid.initializer.Constant(value=0.0))
hidden2 = fluid.layers.instance_norm(input=hidden1, param_attr = param_attr, bias_attr = bias_attr)
place = fluid.CPUPlace()
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())
np_x = np.random.random(size=(3, 7, 3, 7)).astype('float32')
output = exe.run(feed={"x": np_x}, fetch_list = [hidden2])
print(output)
x = fluid.data(name='x', shape=[3, 7, 3, 7], dtype='float32')
hidden1 = fluid.layers.fc(input=x, size=200, param_attr='fc1.w')
hidden2 = fluid.layers.instance_norm(input=hidden1)
......@@ -26,23 +26,14 @@ NPair损失需要成对的数据。NPair损失分为两部分:第一部分是
.. code-block:: python
import paddle.fluid as fluid
import numpy as np
anchor = fluid.layers.data(
name = 'anchor', shape = [18, 6], dtype = 'float32', append_batch_size=False)
positive = fluid.layers.data(
name = 'positive', shape = [18, 6], dtype = 'float32', append_batch_size=False)
labels = fluid.layers.data(
name = 'labels', shape = [18], dtype = 'float32', append_batch_size=False)
res = fluid.layers.npair_loss(anchor, positive, labels, l2_reg = 0.002)
place = fluid.CPUPlace()
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())
a = np.random.rand(18, 6).astype("float32")
p = np.random.rand(18, 6).astype("float32")
l = np.random.rand(18).astype("float32")
output = exe.run(feed={"anchor": a, "positive": p, "labels": l}, fetch_list=[res])
print(output)
anchor = fluid.data(
name = 'anchor', shape = [18, 6], dtype = 'float32', append_batch_size=False)
positive = fluid.data(
name = 'positive', shape = [18, 6], dtype = 'float32', append_batch_size=False)
labels = fluid.data(
name = 'labels', shape = [18], dtype = 'float32', append_batch_size=False)
npair_loss = fluid.layers.npair_loss(anchor, positive, labels, l2_reg = 0.002)
......
......@@ -32,8 +32,7 @@ Image Convolution Group由Convolution2d,BatchNorm,DropOut和Pool2d组成。
.. code-block:: python
import paddle.fluid as fluid
import numpy as np
img = fluid.layers.data(name='img', shape=[1, 28, 28], dtype='float32')
img = fluid.data(name='img', shape=[None, 1, 28, 28], dtype='float32')
conv_pool = fluid.nets.img_conv_group(input=img,
conv_padding=1,
conv_num_filter=[3, 3],
......@@ -41,12 +40,6 @@ Image Convolution Group由Convolution2d,BatchNorm,DropOut和Pool2d组成。
conv_act="relu",
pool_size=2,
pool_stride=2)
place = fluid.CPUPlace()
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())
np_x = np.random.random(size=(1, 1, 28, 28)).astype('float32')
output = exe.run(feed={"img": np_x}, fetch_list = [conv_pool])
print(output)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册