From 404ca8d44200fde1ddac3b73afe50e03fd819526 Mon Sep 17 00:00:00 2001 From: ceci3 <592712189@qq.com> Date: Thu, 16 Apr 2020 14:52:38 +0000 Subject: [PATCH] sync ch sample to eng --- doc/fluid/api_cn/layers_cn/batch_norm_cn.rst | 15 +++-------- doc/fluid/api_cn/layers_cn/cos_sim_cn.rst | 12 ++------- doc/fluid/api_cn/layers_cn/dropout_cn.rst | 11 ++------ .../api_cn/layers_cn/instance_norm_cn.rst | 15 +++-------- doc/fluid/api_cn/layers_cn/npair_loss_cn.rst | 25 ++++++------------- .../api_cn/nets_cn/img_conv_group_cn.rst | 9 +------ 6 files changed, 19 insertions(+), 68 deletions(-) diff --git a/doc/fluid/api_cn/layers_cn/batch_norm_cn.rst b/doc/fluid/api_cn/layers_cn/batch_norm_cn.rst index 3d4699eb6..991d11112 100644 --- a/doc/fluid/api_cn/layers_cn/batch_norm_cn.rst +++ b/doc/fluid/api_cn/layers_cn/batch_norm_cn.rst @@ -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 diff --git a/doc/fluid/api_cn/layers_cn/cos_sim_cn.rst b/doc/fluid/api_cn/layers_cn/cos_sim_cn.rst index b6fb77dfc..3f12bee15 100644 --- a/doc/fluid/api_cn/layers_cn/cos_sim_cn.rst +++ b/doc/fluid/api_cn/layers_cn/cos_sim_cn.rst @@ -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) diff --git a/doc/fluid/api_cn/layers_cn/dropout_cn.rst b/doc/fluid/api_cn/layers_cn/dropout_cn.rst index ec3149aa9..86927b2bb 100644 --- a/doc/fluid/api_cn/layers_cn/dropout_cn.rst +++ b/doc/fluid/api_cn/layers_cn/dropout_cn.rst @@ -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) diff --git a/doc/fluid/api_cn/layers_cn/instance_norm_cn.rst b/doc/fluid/api_cn/layers_cn/instance_norm_cn.rst index d2e819c7a..0aabd18dd 100644 --- a/doc/fluid/api_cn/layers_cn/instance_norm_cn.rst +++ b/doc/fluid/api_cn/layers_cn/instance_norm_cn.rst @@ -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) diff --git a/doc/fluid/api_cn/layers_cn/npair_loss_cn.rst b/doc/fluid/api_cn/layers_cn/npair_loss_cn.rst index 7b8eb8514..4c1330ceb 100644 --- a/doc/fluid/api_cn/layers_cn/npair_loss_cn.rst +++ b/doc/fluid/api_cn/layers_cn/npair_loss_cn.rst @@ -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) diff --git a/doc/fluid/api_cn/nets_cn/img_conv_group_cn.rst b/doc/fluid/api_cn/nets_cn/img_conv_group_cn.rst index 9b6006778..f9794eb15 100644 --- a/doc/fluid/api_cn/nets_cn/img_conv_group_cn.rst +++ b/doc/fluid/api_cn/nets_cn/img_conv_group_cn.rst @@ -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) -- GitLab