Skip to content

Commit

Permalink
add mish cn docs (PaddlePaddle#4186)
Browse files Browse the repository at this point in the history
* add mish cn docs

* modify example of mish in static graph

* modify docs of mish
  • Loading branch information
wangxinxin08 authored Jan 11, 2022
1 parent 42f8d08 commit ba8fd55
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/api/api_label
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ paddle.fluid.layers.nn.mul .. _api_paddle_fluid_layers_nn_mul:
paddle.fluid.layers.learning_rate_scheduler.exponential_decay .. _api_paddle_fluid_layers_learning_rate_scheduler_exponential_decay:
paddle.static.nn.sequence_slice .. _api_paddle_static_nn_sequence_slice:
paddle.fluid.layers.nn.swish .. _api_paddle_fluid_layers_nn_swish:
paddle.fluid.layers.nn.mish .. _api_paddle_fluid_layers_nn_mish:
paddle.fluid.layers.nn.chunk_eval .. _api_paddle_fluid_layers_nn_chunk_eval:
paddle.fluid.layers.nn.reshape .. _api_paddle_fluid_layers_nn_reshape:
paddle.fluid.layers.nn.brelu .. _api_paddle_fluid_layers_nn_brelu:
Expand Down Expand Up @@ -870,6 +871,7 @@ paddle.nn.GroupNorm .. _api_paddle_nn_GroupNorm:
paddle.nn.Pad2D .. _api_paddle_nn_Pad2D:
paddle.nn.ELU .. _api_paddle_nn_ELU:
paddle.nn.Swish .. _api_paddle_nn_Swish:
paddle.nn.Mish .. _api_paddle_nn_Mish:
paddle.nn.RNN .. _api_paddle_nn_RNN:
paddle.nn.Softsign .. _api_paddle_nn_Softsign:
paddle.nn.Tanh .. _api_paddle_nn_Tanh:
Expand Down Expand Up @@ -916,6 +918,7 @@ paddle.nn.functional.cosine_similarity .. _api_paddle_nn_functional_cosine_simil
paddle.nn.functional.log_softmax .. _api_paddle_nn_functional_log_softmax:
paddle.nn.functional.binary_cross_entropy .. _api_paddle_nn_functional_binary_cross_entropy:
paddle.nn.functional.swish .. _api_paddle_nn_functional_swish:
paddle.nn.functional.mish .. _api_paddle_nn_functional_mish:
paddle.nn.functional.conv2d_transpose .. _api_paddle_nn_functional_conv2d_transpose:
paddle.nn.functional.tanhshrink .. _api_paddle_nn_functional_tanhshrink:
paddle.nn.functional.softplus .. _api_paddle_nn_functional_softplus:
Expand Down
47 changes: 47 additions & 0 deletions docs/api/paddle/fluid/layers/mish_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
.. _cn_api_fluid_layers_mish:

mish
-------------------------------

.. py:function:: paddle.fluid.layers.mish(x, threshold=20, name=None)
Mish激活函数。参考 `Mish: A Self Regularized Non-Monotonic Neural Activation Function <https://arxiv.org/abs/1908.08681>`_ 。

.. math::
softplus(x) = \begin{cases}
x, \text{if } x > \text{threshold} \\
\ln(1 + e^{x}), \text{otherwise}
\end{cases}
Mish(x) = x * \tanh(softplus(x))
参数:
- **x** (Variable) - 多维 Tensor 或 LoDTensor,数据类型为 float32,float64。
- **threshold** (float) - Mish激活函数中计算softplus的阈值。如果输入大于该阈值,将使用近似计算,默认值为 20.0。
- **name** (str,可选) – 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。

返回:
- Variable: Mish op 的结果,多维 Tensor 或 LoDTensor。数据类型为 float32 或 float64,数据类型以及形状和输入 x 一致。

**代码示例:**

.. code-block:: python
import paddle
paddle.enable_static()
import paddle.fluid as fluid
import numpy as np
DATATYPE='float32'
x_data = np.array([i for i in range(1,5)]).reshape([1,1,4]).astype(DATATYPE)
x = fluid.data(name="x", shape=[None,1,4], dtype=DATATYPE)
y = fluid.layers.mish(x)
place = fluid.CPUPlace()
# place = fluid.CUDAPlace(0)
exe = fluid.Executor(place)
out, = exe.run(feed={'x':x_data}, fetch_list=[y.name])
print(out) # [[0.66666667, 1.66666667, 3., 4.]]
37 changes: 37 additions & 0 deletions docs/api/paddle/nn/Mish_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.. _cn_api_nn_Mish:

Mish
-------------------------------
.. py:class:: paddle.nn.Mish(name=None)
Mish激活层

.. math::
softplus(x) = \begin{cases}
x, \text{if } x > \text{threshold} \\
\ln(1 + e^{x}), \text{otherwise}
\end{cases}
Mish(x) = x * \tanh(softplus(x))
参数
::::::::::
- name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。

形状:
::::::::::
- input: 任意形状的Tensor。
- output: 和input具有相同形状的Tensor。

代码示例
:::::::::

.. code-block:: python
import paddle
x = paddle.to_tensor([-5., 0., 5.])
m = paddle.nn.Mish()
out = m(x) # [-0.03357624, 0., 4.99955208]
2 changes: 2 additions & 0 deletions docs/api/paddle/nn/Overview_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ Padding层
" :ref:`paddle.nn.Softshrink <cn_api_nn_Softshrink>` ", "Softshrink激活层"
" :ref:`paddle.nn.Softsign <cn_api_nn_Softsign>` ", "Softsign激活层"
" :ref:`paddle.nn.Swish <cn_api_nn_Swish>` ", "Swish激活层"
" :ref:`paddle.nn.Mish <cn_api_nn_Mish>` ", "Mish激活层"
" :ref:`paddle.nn.Tanh <cn_api_nn_Tanh>` ", "Tanh激活层"
" :ref:`paddle.nn.Tanhshrink <cn_api_nn_Tanhshrink>` ", "Tanhshrink激活层"
" :ref:`paddle.nn.ThresholdedReLU <cn_api_nn_ThresholdedReLU>` ", "Thresholded ReLU激活层"
Expand Down Expand Up @@ -382,6 +383,7 @@ Padding相关函数
" :ref:`paddle.nn.functional.softshrink <cn_api_nn_cn_softshrink>` ", "softshrink激活函数"
" :ref:`paddle.nn.functional.softsign <cn_api_nn_cn_softsign>` ", "softsign激活函数"
" :ref:`paddle.nn.functional.swish <cn_api_nn_cn_swish>` ", "swish激活函数"
" :ref:`paddle.nn.functional.mish <cn_api_nn_cn_mish>` ", "mish激活函数"
" :ref:`paddle.nn.functional.tanhshrink <cn_api_nn_cn_tanhshrink>` ", "tanhshrink激活函数"
" :ref:`paddle.nn.functional.thresholded_relu <cn_api_nn_cn_thresholded_relu>` ", "thresholded_relu激活函数"

Expand Down
38 changes: 38 additions & 0 deletions docs/api/paddle/nn/functional/mish_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.. _cn_api_nn_cn_mish:

mish
-------------------------------

.. py:function:: paddle.nn.functional.mish(x, name=None)
mish激活层。计算公式如下:

.. math::
softplus(x) = \begin{cases}
x, \text{if } x > \text{threshold} \\
\ln(1 + e^{x}), \text{otherwise}
\end{cases}
Mish(x) = x * \tanh(softplus(x))
参数
::::::::::
- 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
x = paddle.to_tensor([-5., 0., 5.])
out = F.mish(x) # [-0.03357624, 0., 4.99955208]

0 comments on commit ba8fd55

Please sign in to comment.