评价此页

Threshold#

class torch.nn.modules.activation.Threshold(threshold, value, inplace=False)[source]#

对输入 Tensor 的每个元素进行阈值处理。

Threshold 定义为

y={x, if x>thresholdvalue, otherwise y = \begin{cases} x, &\text{ if } x > \text{threshold} \\ \text{value}, &\text{ otherwise } \end{cases}
参数
  • threshold (float) – 用于阈值判断的值

  • value (float) – 用于替换的值

  • inplace (bool) – 可以选择是否就地执行操作。默认值:False

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

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

../_images/Threshold.png

示例

>>> m = nn.Threshold(0, 0.5)
>>> input = torch.arange(-3, 3)
>>> output = m(input)
extra_repr()[source]#

返回模块的额外表示。

返回类型

str

forward(input)[source]#

执行前向传播。

返回类型

张量