未验证 提交 49369fb9 编写于 作者: H hong19860320 提交者: GitHub

Update ReLU6, Tanhshrink, SELU, Softplus, Softshrink and Softsign (#2446)

上级 77570ace
...@@ -155,7 +155,7 @@ paddle.nn ...@@ -155,7 +155,7 @@ paddle.nn
nn/ssd_loss.rst nn/ssd_loss.rst
nn/swish.rst nn/swish.rst
nn/switch_case.rst nn/switch_case.rst
nn/tanh_shrink.rst nn/tanhshrink.rst
nn/target_assign.rst nn/target_assign.rst
nn/teacher_student_sigmoid_loss.rst nn/teacher_student_sigmoid_loss.rst
nn/temporal_shift.rst nn/temporal_shift.rst
......
...@@ -10,7 +10,13 @@ activation ...@@ -10,7 +10,13 @@ activation
activation/Hardshrink.rst activation/Hardshrink.rst
activation/Tanh.rst activation/Tanh.rst
activation/Hardtanh.rst activation/Hardtanh.rst
activation/LogSigmoid.rst
activation/PReLU.rst activation/PReLU.rst
activation/ReLU.rst activation/ReLU.rst
activation/LogSigmoid.rst activation/ReLU6.rst
activation/Softmax.rst activation/SELU.rst
\ No newline at end of file activation/Softmax.rst
activation/Softplus.rst
activation/Softshrink.rst
activation/Softsign.rst
activation/Tanhshrink.rst
.. _api_nn_activation_ReLU6:
ReLU6
---------
.. autoclass:: paddle.nn.ReLU6
:noindex:
.. _api_nn_activation_SELU:
SELU
---------
.. autoclass:: paddle.nn.SELU
:noindex:
.. _api_nn_activation_Softplus:
Softplus
---------
.. autoclass:: paddle.nn.Softplus
:noindex:
.. _api_nn_activation_Softshrink:
Softshrink
----------
.. autoclass:: paddle.nn.Softshrink
:noindex:
.. _api_nn_activation_Softsign:
Softsign
---------
.. autoclass:: paddle.nn.Softsign
:noindex:
.. _api_nn_activation_Tanhshrink:
Tanhshrink
----------
.. autoclass:: paddle.nn.Tanhshrink
:noindex:
.. _api_nn_relu6: .. _api_nn_relu6:
relu6 relu6
------------------------------- ----------
:doc_source: paddle.fluid.layers.relu6
.. autofunction:: paddle.nn.functional.relu6
:noindex:
.. _api_nn_selu: .. _api_nn_selu:
selu selu
------------------------------- ----------
:doc_source: paddle.fluid.layers.selu
.. autofunction:: paddle.nn.functional.selu
:noindex:
.. _api_nn_softplus: .. _api_nn_softplus:
softplus softplus
------------------------------- ----------
:doc_source: paddle.fluid.layers.softplus
.. autofunction:: paddle.nn.functional.softplus
:noindex:
.. _api_nn_softshrink: .. _api_nn_softshrink:
softshrink softshrink
------------------------------- ----------
:doc_source: paddle.fluid.layers.softshrink
.. autofunction:: paddle.nn.functional.softshrink
:noindex:
.. _api_nn_softsign: .. _api_nn_softsign:
softsign softsign
------------------------------- ----------
:doc_source: paddle.fluid.layers.softsign
.. autofunction:: paddle.nn.functional.softsign
:noindex:
.. _api_nn_tanh_shrink:
tanh_shrink
-------------------------------
:doc_source: paddle.fluid.layers.tanh_shrink
.. _api_nn_tanhshrink:
tanhshrink
-----------
.. autofunction:: paddle.nn.functional.tanhshrink
:noindex:
...@@ -167,7 +167,7 @@ paddle.nn ...@@ -167,7 +167,7 @@ paddle.nn
nn_cn/ssd_loss_cn.rst nn_cn/ssd_loss_cn.rst
nn_cn/swish_cn.rst nn_cn/swish_cn.rst
nn_cn/switch_case_cn.rst nn_cn/switch_case_cn.rst
nn_cn/tanh_shrink_cn.rst nn_cn/tanhshrink_cn.rst
nn_cn/target_assign_cn.rst nn_cn/target_assign_cn.rst
nn_cn/teacher_student_sigmoid_loss_cn.rst nn_cn/teacher_student_sigmoid_loss_cn.rst
nn_cn/temporal_shift_cn.rst nn_cn/temporal_shift_cn.rst
......
...@@ -13,10 +13,16 @@ activation ...@@ -13,10 +13,16 @@ activation
activation_cn/Hardshrink_cn.rst activation_cn/Hardshrink_cn.rst
activation_cn/Tanh_cn.rst activation_cn/Tanh_cn.rst
activation_cn/Hardtanh_cn.rst activation_cn/Hardtanh_cn.rst
activation_cn/PRelu_cn.rst
activation_cn/ReLU_cn.rst
activation_cn/LeakyReLU_cn.rst activation_cn/LeakyReLU_cn.rst
activation_cn/Softmax_cn.rst activation_cn/LogSigmoid_cn.rst
activation_cn/LogSoftmax_cn.rst activation_cn/LogSoftmax_cn.rst
activation_cn/PRelu_cn.rst
activation_cn/ReLU_cn.rst
activation_cn/ReLU6_cn.rst
activation_cn/SELU_cn.rst
activation_cn/Sigmoid_cn.rst activation_cn/Sigmoid_cn.rst
activation_cn/LogSigmoid_cn.rst activation_cn/Softmax_cn.rst
\ No newline at end of file activation_cn/Softplus_cn.rst
activation_cn/Softshrink_cn.rst
activation_cn/Softsign_cn.rst
activation_cn/Tanhshrink_cn.rst
.. _cn_api_nn_ReLU6:
ReLU6
-------------------------------
.. py:class:: paddle.nn.ReLU6(name=None)
ReLU6激活层
.. math::
ReLU6(x) = min(max(0,x), 6)
其中,:math:`x` 为输入的 Tensor
参数
::::::::::
- name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。
形状:
::::::::::
- input: 任意形状的Tensor。
- output: 和input具有相同形状的Tensor。
代码示例
:::::::::
.. code-block:: python
import paddle
import numpy as np
paddle.disable_static()
x = paddle.to_tensor(np.array([-1, 0.3, 6.5]))
m = paddle.nn.ReLU6()
out = m(x) # [0, 0.3, 6]
.. _cn_api_nn_SELU:
SELU
-------------------------------
.. py:class:: paddle.nn.SELU(scale=1.0507009873554804934193349852946, alpha=1.6732632423543772848170429916717, name=None)
SELU激活层
.. math::
SELU(x) = scale * (max(0,x) + min(0, alpha * (e^{x} - 1)))
其中,:math:`x` 为输入的 Tensor
参数
::::::::::
- scale (float, 可选) - SELU激活计算公式中的scale值。默认值为1.0507009873554804934193349852946。
- alpha (float, 可选) - SELU激活计算公式中的alpha值。默认值为1.6732632423543772848170429916717。
- name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。
形状:
::::::::::
- input: 任意形状的Tensor。
- output: 和input具有相同形状的Tensor。
代码示例
:::::::::
.. code-block:: python
import paddle
import numpy as np
paddle.disable_static()
x = paddle.to_tensor(np.array([[0.0, 1.0],[2.0, 3.0]]))
m = paddle.nn.SELU()
out = m(x) # [[0, 1.050701],[2.101402, 3.152103]]
.. _cn_api_nn_Softplus:
Softplus
-------------------------------
.. py:class:: paddle.nn.Softplus(beta=1, threshold=20, name=None)
Softplus激活层
.. math::
Softplus(x) = \frac{1}{beta} * \log(1 + e^{beta * x}) \\
\text{为了保证数值稳定性, 当}\,beta * x > threshold\,\text{时,函数转变为线性函数x}.
其中,:math:`x` 为输入的 Tensor
参数
::::::::::
- beta (float, 可选) - Softplus激活计算公式中的beta值。默认值为1。
- threshold (float, 可选) - Softplus激活计算公式中的threshold值。默认值为20。
- name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。
形状:
::::::::::
- input: 任意形状的Tensor。
- output: 和input具有相同形状的Tensor。
代码示例
:::::::::
.. code-block:: python
import paddle
import numpy as np
paddle.disable_static()
x = paddle.to_tensor(np.array([-0.4, -0.2, 0.1, 0.3]))
m = paddle.nn.Softplus()
out = m(x) # [0.513015, 0.598139, 0.744397, 0.854355]
.. _cn_api_nn_Softshrink:
Softshrink
-------------------------------
.. py:class:: paddle.nn.Softshrink(threshold=0.5, name=None)
Softshrink激活层
.. math::
Softshrink(x)= \begin{cases}
x - threshold, \text{if } x > threshold \\
x + threshold, \text{if } x < -threshold \\
0, \text{otherwise}
\end{cases}
其中,:math:`x` 为输入的 Tensor
参数
::::::::::
- threshold (float, 可选) - Softshrink激活计算公式中的threshold值,必须大于等于零。默认值为0.5。
- name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。
形状:
::::::::::
- input: 任意形状的Tensor。
- output: 和input具有相同形状的Tensor。
代码示例
:::::::::
.. code-block:: python
import paddle
import numpy as np
paddle.disable_static()
x = paddle.to_tensor(np.array([-0.9, -0.2, 0.1, 0.8]))
m = paddle.nn.Softshrink()
out = m(x) # [-0.4, 0, 0, 0.3]
.. _cn_api_nn_Softsign:
Softsign
-------------------------------
.. py:class:: paddle.nn.Softsign(name=None)
Softsign激活层
.. math::
Softsign(x) = \frac{x}{1 + |x|}
其中,:math:`x` 为输入的 Tensor
参数
::::::::::
- name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。
形状:
::::::::::
- input: 任意形状的Tensor。
- output: 和input具有相同形状的Tensor。
代码示例
:::::::::
.. code-block:: python
import paddle
import numpy as np
paddle.disable_static()
x = paddle.to_tensor(np.array([-0.4, -0.2, 0.1, 0.3]))
m = paddle.nn.Softsign()
out = m(x) # [-0.285714, -0.166667, 0.0909091, 0.230769]
.. _cn_api_nn_Tanhshrink:
Tanhshrink
-------------------------------
.. py:class:: paddle.nn.Tanhshrink(name=None)
Tanhshrink激活层
.. math::
Tanhshrink(x) = x - tanh(x)
其中,:math:`x` 为输入的 Tensor
参数
::::::::::
- name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。
形状:
::::::::::
- input: 任意形状的Tensor。
- output: 和input具有相同形状的Tensor。
代码示例
:::::::::
.. code-block:: python
import paddle
import numpy as np
paddle.disable_static()
x = paddle.to_tensor(np.array([-0.4, -0.2, 0.1, 0.3]))
m = paddle.nn.Tanhshrink()
out = m(x) # [-0.020051, -0.00262468, 0.000332005, 0.00868739]
...@@ -2,6 +2,36 @@ ...@@ -2,6 +2,36 @@
relu6 relu6
------------------------------- -------------------------------
:doc_source: paddle.fluid.layers.relu6
.. py:function:: paddle.nn.functional.relu6(x, name=None)
relu6激活层
.. math::
relu6(x) = min(max(0,x), 6)
其中,:math:`x` 为输入的 Tensor
参数:
::::::::::
- x (Tensor) - 输入的 ``Tensor`` ,数据类型为:float32、float64。
- 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([-1, 0.3, 6.5]))
out = F.relu6(x) # [0, 0.3, 6]
...@@ -2,6 +2,38 @@ ...@@ -2,6 +2,38 @@
selu selu
------------------------------- -------------------------------
:doc_source: paddle.fluid.layers.selu
.. py:function:: paddle.nn.functional.selu(x, scale=1.0507009873554804934193349852946, alpha=1.6732632423543772848170429916717, name=None)
selu激活层
.. math::
selu(x) = scale * (max(0,x) + min(0, alpha * (e^{x} - 1)))
其中,:math:`x` 为输入的 Tensor
参数:
::::::::::
- x (Tensor) - 输入的 ``Tensor`` ,数据类型为:float32、float64。
- scale (float, 可选) - selu激活计算公式中的scale值。默认值为1.0507009873554804934193349852946。
- alpha (float, 可选) - selu激活计算公式中的alpha值。默认值为1.6732632423543772848170429916717。
- 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([[0.0, 1.0],[2.0, 3.0]]))
out = F.selu(x) # [[0, 1.050701],[2.101402, 3.152103]]
...@@ -2,6 +2,39 @@ ...@@ -2,6 +2,39 @@
softplus softplus
------------------------------- -------------------------------
:doc_source: paddle.fluid.layers.softplus
.. py:function:: paddle.nn.functional.softplus(x, beta=1, threshold=20, name=None)
softplus激活层
.. math::
softplus(x) = \frac{1}{beta} * \log(1 + e^{beta * x}) \\
\text{为了保证数值稳定性, 当}\,beta * x > threshold\,\text{时,函数转变为线性函数x}.
其中,:math:`x` 为输入的 Tensor
参数:
::::::::::
- x (Tensor) - 输入的 ``Tensor`` ,数据类型为:float32、float64。
- beta (float, 可选) - Softplus激活计算公式中的beta值。默认值为1。
- threshold (float, 可选) - Softplus激活计算公式中的threshold值。默认值为20。
- 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([-0.4, -0.2, 0.1, 0.3]))
out = F.softplus(x) # [0.513015, 0.598139, 0.744397, 0.854355]
...@@ -2,6 +2,41 @@ ...@@ -2,6 +2,41 @@
softshrink softshrink
------------------------------- -------------------------------
:doc_source: paddle.fluid.layers.softshrink
.. py:function:: paddle.nn.functional.softshrink(x, threshold=0.5, name=None)
softshrink激活层
.. math::
softshrink(x)= \begin{cases}
x - threshold, \text{if } x > threshold \\
x + threshold, \text{if } x < -threshold \\
0, \text{otherwise}
\end{cases}
其中,:math:`x` 为输入的 Tensor
参数:
::::::::::
- x (Tensor) - 输入的 ``Tensor`` ,数据类型为:float32、float64。
- threshold (float, 可选) - softshrink激活计算公式中的threshold值,必须大于等于零。默认值为0.5。
- 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([-0.9, -0.2, 0.1, 0.8]))
out = F.softshrink(x) # [-0.4, 0, 0, 0.3]
...@@ -2,6 +2,36 @@ ...@@ -2,6 +2,36 @@
softsign softsign
------------------------------- -------------------------------
:doc_source: paddle.fluid.layers.softsign
.. py:function:: paddle.nn.functional.softsign(x, name=None)
softsign激活层
.. math::
softsign(x) = \frac{x}{1 + |x|}
其中,:math:`x` 为输入的 Tensor
参数:
::::::::::
- x (Tensor) - 输入的 ``Tensor`` ,数据类型为:float32、float64。
- 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([-0.4, -0.2, 0.1, 0.3]))
out = F.softsign(x) # [-0.285714, -0.166667, 0.0909091, 0.230769]
.. _cn_api_nn_cn_tanh_shrink:
tanh_shrink
-------------------------------
:doc_source: paddle.fluid.layers.tanh_shrink
.. _cn_api_nn_cn_tanhshrink:
tanhshrink
-------------------------------
.. py:function:: paddle.nn.functional.tanhshrink(x, name=None)
tanhshrink激活层
.. math::
tanhshrink(x) = x - tanh(x)
其中,:math:`x` 为输入的 Tensor
参数:
::::::::::
- x (Tensor) - 输入的 ``Tensor`` ,数据类型为:float32、float64。
- 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([-0.4, -0.2, 0.1, 0.3]))
out = F.tanhshrink(x) # [-0.020051, -0.00262468, 0.000332005, 0.00868739]
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册