阈值

classtorch.nn.Threshold(threshold, value, inplace=False)[源代码]

对输入张量的每个元素应用阈值处理。

阈值是指:

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

  • value (float) — 替换的目标值

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

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

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

示例:

>>> m = nn.Threshold(0.1, 20)
>>> input = torch.randn(2)
>>> output = m(input)
本页目录