forked from PaddlePaddle/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add mish cn docs (PaddlePaddle#4186)
* add mish cn docs * modify example of mish in static graph * modify docs of mish
- Loading branch information
1 parent
42f8d08
commit ba8fd55
Showing
5 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.]] | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |