Shortcuts

ReLU

class torch.nn.ReLU(inplace=False)[源代码]

逐元素应用修正线性单元函数。

ReLU(x)=(x)+=max(0,x)\text{ReLU}(x) = (x)^+ = \max(0, x)

Parameters

inplace (布尔值) – 可以选择就地执行操作。默认值:False

Shape:
  • 输入:()(*),其中 * 表示任意数量的维度。

  • 输出: ()(*), 与输入形状相同。

../_images/ReLU.png

示例:

  >>> m = nn.ReLU()
  >>> input = torch.randn(2)
  >>> output = m(input)


CReLU 的一个实现 - https://arxiv.org/abs/1603.05201

  >>> m = nn.ReLU()
  >>> input = torch.randn(2).unsqueeze(0)
  >>> output = torch.cat((m(input), m(-input)))
优云智算