mindspore.nn.ReLU

View Source On Gitee
class mindspore.nn.ReLU[source]

Applies ReLU (Rectified Linear Unit activation function) element-wise.

\[\text{ReLU}(input) = (input)^+ = \max(0, input),\]

It returns element-wise \(\max(0, input)\).

Note

The neurons with the negative output will be suppressed and the active neurons will stay the same.

ReLU Activation Function Graph:

../../_images/ReLU.png
Inputs:
  • input (Tensor) - The input of ReLU is a Tensor of any dimension.

Outputs:

Tensor, with the same type and shape as the input.

Raises

TypeError – If dtype of input is not supported.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import numpy as np
>>> import mindspore
>>> from mindspore import Tensor, nn
>>> input = Tensor(np.array([-1, 2, -3, 2, -1]), mindspore.float16)
>>> relu = nn.ReLU()
>>> output = relu(input)
>>> print(output)
[0. 2. 0. 2. 0.]