diff --git a/doc/fluid/api_cn/layers_cn/gaussian_random_cn.rst b/doc/fluid/api_cn/layers_cn/gaussian_random_cn.rst index 9fbdaf15752fc1fdbc4f227e50f144981d94ac9c..dc4b2e36cc454873d7634f5b5f8d32865020b03d 100644 --- a/doc/fluid/api_cn/layers_cn/gaussian_random_cn.rst +++ b/doc/fluid/api_cn/layers_cn/gaussian_random_cn.rst @@ -5,30 +5,62 @@ gaussian_random .. py:function:: paddle.fluid.layers.gaussian_random(shape, mean=0.0, std=1.0, seed=0, dtype='float32') -gaussian_random算子。 - -用于使用高斯随机生成器初始化张量(Tensor)。 +生成数据符合高斯随机分布的张量。 参数: - - **shape** (tuple | list)- (vector )随机张量的维数 - - **mean** (Float)- (默认值0.0)随机张量的均值 - - **std** (Float)- (默认值为1.0)随机张量的std - - **seed** (Int)- (默认值为 0)生成器随机生成种子。0表示使用系统范围的种子。注意如果seed不为0,则此算子每次将始终生成相同的随机数 - - **dtype** (np.dtype | core.VarDesc.VarType | str)- 输出的数据类型。 + - **shape** (Tuple[int] | List[int])- 生成张量的形状。 + - **mean** (float)- 随机张量的均值,默认值为 0.0。 + - **std** (float)- 随机张量的标准差,默认值为 1.0。 + - **seed** (int)- 随机数种子,默认值为0。注:seed 设置为 0 表示使用系统的随机数种子。注意如果 seed 不为 0,则此算子每次将始终生成相同的随机数。 + - **dtype** (np.dtype,core.VarDesc.VarType,str)- 输出张量的数据类型,可选值为 float32,float64。 -返回: 输出高斯随机运算矩阵 +返回: -返回类型: 输出(Variable) + - 符合高斯分布的随机张量。形状为 shape,数据类型为 dtype。 -**代码示例:** +返回类型: -.. code-block:: python + - Variable - import paddle.fluid as fluid - import paddle.fluid.layers as layers - out = layers.gaussian_random(shape=[20, 30]) +**代码示例:** + +.. code-block:: python + + # 静态图使用 + import numpy as np + from paddle import fluid + + x = fluid.layers.gaussian_random((2, 3), std=2., seed=10) + + place = fluid.CPUPlace() + exe = fluid.Executor(place) + start = fluid.default_startup_program() + main = fluid.default_main_program() + + exe.run(start) + x_np, = exe.run(main, feed={}, fetch_list=[x]) + + x_np + # array([[2.3060477, 2.676496 , 3.9911983], + # [0.9990833, 2.8675377, 2.2279181]], dtype=float32) + + +.. code-block:: python + # 动态图使用 + import numpy as np + from paddle import fluid + import paddle.fluid.dygraph as dg + + place = fluid.CPUPlace() + with dg.guard(place) as g: + x = fluid.layers.gaussian_random((2, 4), mean=2., dtype="float32", seed=10) + x_np = x.numpy() + + x_np + # array([[2.3060477 , 2.676496 , 3.9911983 , 0.9990833 ], + # [2.8675377 , 2.2279181 , 0.79029655, 2.8447366 ]], dtype=float32) diff --git a/doc/fluid/api_cn/layers_cn/swish_cn.rst b/doc/fluid/api_cn/layers_cn/swish_cn.rst index 6d1556f62affbb4be0db346c064274831546b09d..8e94d6ab15f3696e1a7b7b3618821ec28da12d33 100644 --- a/doc/fluid/api_cn/layers_cn/swish_cn.rst +++ b/doc/fluid/api_cn/layers_cn/swish_cn.rst @@ -5,27 +5,67 @@ swish .. py:function:: paddle.fluid.layers.swish(x, beta=1.0, name=None) -Swish 激活函数 +逐元素计算 Swish 激活函数,参考 `Searching for Activation Functions `_ 。 .. math:: - out = \frac{x}{1 + e^{- beta x}} + out = \frac{x}{1 + e^{- beta * x}} 参数: - - **x** (Variable) - Swish operator 的输入 - - **beta** (float|1.0) - Swish operator 的常量beta - - **name** (str|None) - 这个层的名称(可选)。如果设置为None,该层将被自动命名。 + - **x** (Variable) - 多维 Tensor,数据类型为 float32,float64。 + - **beta** (float) - Swish operator 的常量 beta,默认值为 1.0。 + - **name** (str,可选) – 具体用法请参见 :ref:`cn_api_fluid_ParamAttr` ,一般无需设置,默认值为None。 -返回: Swish operator 的输出 +返回: + - Swish op 的结果,多维 Tensor。数据类型为 float32 或 float64 的 Tensor,数据类型以及形状和输入 x 一致。 -返回类型: output(Variable) +返回类型: + - Variable **代码示例:** +.. code-block:: python + + # 静态图使用 + import numpy as np + from paddle import fluid + + x = fluid.layers.data(name="x", shape=(3,), dtype="float32") + y = fluid.layers.swish(x, beta=2.0) + + place = fluid.CPUPlace() + exe = fluid.Executor(place) + start = fluid.default_startup_program() + main = fluid.default_main_program() + + data = np.random.randn(2, 3).astype("float32") + exe.run(start) + y_np, = exe.run(main, feed={"x": data}, fetch_list=[y]) + + data + # array([[-1.1239197 , 1.3391294 , 0.03921051], + # [ 1.1970421 , 0.02440812, 1.2055548 ]], dtype=float32) + y_np + # array([[-0.2756806 , 1.0610548 , 0.01998957], + # [ 0.9193261 , 0.01235299, 0.9276883 ]], dtype=float32) + .. code-block:: python - import paddle.fluid as fluid - x = fluid.layers.data(name="x", shape=[3,10,32,32], dtype="float32") - y = fluid.layers.swish(x, beta=2.0) - + # 动态图使用 + import numpy as np + from paddle import fluid + import paddle.fluid.dygraph as dg + + data = np.random.randn(2, 3).astype("float32") + with dg.guard(place) as g: + x = dg.to_variable(data) + y = fluid.layers.swish(x) + y_np = y.numpy() + data + # array([[-0.0816701 , 1.1603649 , -0.88325626], + # [ 0.7522361 , 1.0978601 , 0.12987892]], dtype=float32) + y_np + # array([[-0.03916847, 0.8835007 , -0.25835553], + # [ 0.51126915, 0.82324016, 0.06915068]], dtype=float32) + diff --git a/doc/fluid/api_cn/layers_cn/thresholded_relu_cn.rst b/doc/fluid/api_cn/layers_cn/thresholded_relu_cn.rst index a4945d90cb371726f8128951d3b7b1b694e10652..a59234c4110969868e57887e722e5a3b12069cf6 100644 --- a/doc/fluid/api_cn/layers_cn/thresholded_relu_cn.rst +++ b/doc/fluid/api_cn/layers_cn/thresholded_relu_cn.rst @@ -5,7 +5,7 @@ thresholded_relu .. py:function:: paddle.fluid.layers.thresholded_relu(x,threshold=None) -ThresholdedRelu激活函数 +逐元素计算 ThresholdedRelu激活函数。 .. math:: @@ -15,18 +15,63 @@ ThresholdedRelu激活函数 \end{matrix}\right. 参数: -- **x** -ThresholdedRelu激活函数的输入 -- **threshold** (FLOAT)-激活函数threshold的位置。[默认1.0]。 + - **x** (Variable) -ThresholdedRelu 激活函数的输入,多维 Tensor,数据类型为 float32,float64。 + - **threshold** (float,可选)-激活函数的 threshold 值,如 threshold 值为 None,则其值为 1.0。 -返回:ThresholdedRelu激活函数的输出 +返回: + - 多维 Tensor, 数据类型为 float32 或 float64, 和输入 x 的数据类型相同,形状和输入 x 相同。 + +返回类型: + - Variable **代码示例**: .. code-block:: python - import paddle.fluid as fluid - data = fluid.layers.data(name="input", shape=[1]) - result = fluid.layers.thresholded_relu(data, threshold=0.4) + + # 静态图使用 + import numpy as np + from paddle import fluid + + x = fluid.layers.data(name="x", shape=(3,), dtype="float32") + y = fluid.layers.thresholded_relu(x, beta=0.1) + + place = fluid.CPUPlace() + exe = fluid.Executor(place) + start = fluid.default_startup_program() + main = fluid.default_main_program() + + data = np.random.randn(2, 3).astype("float32") + exe.run(start) + y_np, = exe.run(main, feed={"x": data}, fetch_list=[y]) + + data + # array([[ 1.2734995 , 1.4534163 , 1.1058378 ], + # [ 0.84823716, 0.03892502, -0.80151445]], dtype=float32) + y_np + # array([[ 1.2734995 , 1.4534163 , 1.1058378 ], + # [ 0.84823716, 0. , -0. ]], dtype=float32) + +.. code-block:: python + + # 动态图使用 + import numpy as np + from paddle import fluid + import paddle.fluid.dygraph as dg + + data = np.random.randn(2, 3).astype("float32") + + place = fluid.CPUPlace() + with dg.guard(place) as g: + x = dg.to_variable(data) + y = fluid.layers.thresholded_relu(x, threshold=0.1) + y_np = y.numpy() + data + # array([[ 0.21134382, -1.1805999 , 0.32876605], + # [-1.2210793 , -0.7365624 , 1.0013918 ]], dtype=float32) + y_np + # array([[ 0.21134382, -0. , 0.32876605], + # [-0. , -0. , 1.0013918 ]], dtype=float32)