Shortcuts

阈值

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

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

阈值定义为:

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

  • (浮点数) – 要替换的值

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

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

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

示例:

>>> m = nn.Threshold(0.1, 20)
>>> input = torch.randn(2)
>>> output = m(input)
优云智算