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 3d4699eb690296220eba86d07d5f5c0ca46e8087..991d111120e75598ce7f63cf1e5670db5d9079e0 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 b6fb77dfc50d1ddcfe8c0251f55a8f0fdb26c9b5..3f12bee15eaafbef38034a5700d1c5f85324eb5c 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 ec3149aa993374469a5fc597ab3eef962fd3e349..86927b2bbe7d0a761b5820754ded294c9c92fb4c 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 d2e819c7a2f916259747633b822d5cfc68e28762..0aabd18dd229ea319544ecc2305f716b6fdcfbef 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 7b8eb851431df2bd282b72774b52879f0acee473..4c1330cebf11a0d0d5fde486abf32e7b2cf1d182 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 9b6006778cb884c6b371c62bcce38a4457d9dae0..f9794eb1539bfb39423ef67d291bd7701f41286b 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)