未验证 提交 215804b8 编写于 作者: Z zhupengyang 提交者: GitHub

leaky_relu and LeakyReLU doc (#2373)

上级 77f99a1e
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_nn_leaky_relu: .. _api_nn_leaky_relu:
leaky_relu leaky_relu
------------------------------- ----------
:doc_source: paddle.fluid.layers.leaky_relu
.. autofunction:: paddle.nn.functional.leaky_relu
:noindex:
...@@ -2,19 +2,25 @@ ...@@ -2,19 +2,25 @@
LeakyReLU LeakyReLU
------------------------------- -------------------------------
.. py:class:: paddle.nn.LeakyReLU(alpha=0.01, name=None) .. py:class:: paddle.nn.LeakyReLU(negative_slope=0.01, name=None)
ReLU (Rectified Linear Unit)激活层 LeakyReLU 激活层
.. math:: .. math::
\\Out = max(x, alpha*x)\\ LeakyReLU(x)=
\left\{
\begin{aligned}
&x, & & if \ x >= 0 \\
&negative\_slope * x, & & otherwise \\
\end{aligned}
\right. \\
其中,:math:`x` 为输入的 Tensor 其中,:math:`x` 为输入的 Tensor
参数 参数
:::::::::: ::::::::::
- alpha (float,可选) - :math:`x < 0` 时的斜率。默认值为0.01。 - negative_slope (float,可选) - :math:`x < 0` 时的斜率。默认值为0.01。
- name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 - name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。
形状: 形状:
...@@ -29,8 +35,8 @@ ReLU (Rectified Linear Unit)激活层 ...@@ -29,8 +35,8 @@ ReLU (Rectified Linear Unit)激活层
import paddle import paddle
import numpy as np import numpy as np
paddle.enable_imperative() paddle.disable_static()
lrelu = paddle.nn.LeakyReLU() m = paddle.nn.LeakyReLU()
x = paddle.imperative.to_variable(np.array([-2, 0, 1], 'float32')) x = paddle.to_tensor(np.array([-2, 0, 1], 'float32'))
out = lrelu(x) # [-0.02, 0, 1] out = m(x) # [-0.02, 0., 1.]
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
hardshrink hardshrink
------------------------------- -------------------------------
.. py:functional:: paddle.nn.functional.hardshrink(x, threshold=0.5, name=None) .. py:function:: paddle.nn.functional.hardshrink(x, threshold=0.5, name=None)
hardshrink激活层。计算公式如下: hardshrink激活层。计算公式如下:
......
...@@ -2,6 +2,42 @@ ...@@ -2,6 +2,42 @@
leaky_relu leaky_relu
------------------------------- -------------------------------
:doc_source: paddle.fluid.layers.leaky_relu .. py:function:: paddle.nn.functional.leaky_relu(x, negative_slope=0.01, name=None)
leaky_relu激活层。计算公式如下:
.. math::
LeakyReLU(x)=
\left\{
\begin{aligned}
&x, & & if \ x >= 0 \\
&negative\_slope * x, & & otherwise \\
\end{aligned}
\right. \\
其中,:math:`x` 为输入的 Tensor
参数
::::::::::
- x (Tensor) - 输入的Tensor,数据类型为:float32、float64。
- negative_slope (float,可选) - :math:`x < 0` 时的斜率。默认值为0.01。
- name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。
返回
::::::::::
``Tensor`` ,数据类型和形状同 ``x`` 一致。
代码示例
::::::::::
.. code-block:: python
import paddle
import paddle.nn.functional as F
import numpy as np
paddle.disable_static()
x = paddle.to_tensor(np.array([-2, 0, 1], 'float32'))
out = F.leaky_relu(x) # [-0.02, 0., 1.]
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册