mindspore/docs/api/api_python/nn/mindspore.nn.ReLU.rst

39 lines
1.0 KiB
ReStructuredText
Raw Normal View History

2021-12-04 13:55:42 +08:00
mindspore.nn.ReLU
=================
.. py:class:: mindspore.nn.ReLU
修正线性单元激活函数Rectified Linear Unit activation function
按元素返回 :math:`\max(x,\ 0)` 。特别说明负数输出值会被修改为0正数输出不受影响。
.. math::
\text{ReLU}(x) = (x)^+ = \max(0, x),
ReLU相关图参见 `ReLU <https://en.wikipedia.org/wiki/Activation_function#/media/File:Activation_rectified_linear.svg>`_
**输入:**
2021-12-04 20:36:47 +08:00
- **x** (Tensor) - 用于计算ReLU的Tensor。数据类型为Number。shape为 :math:`(N,*)` ,其中 :math:`*` 表示任意的附加维度数。
2021-12-04 13:55:42 +08:00
**输出:**
Tensor具有与 `x` 相同的数据类型和shape。
**异常:**
- **TypeError** - `x` 的数据类型不是Number。
**支持平台:**
``Ascend`` ``GPU`` ``CPU``
**样例:**
>>> x = Tensor(np.array([-1, 2, -3, 2, -1]), mindspore.float16)
>>> relu = nn.ReLU()
>>> output = relu(x)
>>> print(output)
[0. 2. 0. 2. 0.]