torch.nn.Hardsigmoid
原型
CLASS torch.nn.Hardsigmoid(inplace=False)
参数
- inplace (bool) – 默认为
False
定义
Hardsigmoid ( x ) = { 0 if x ≤ − 3 , 1 if x ≥ + 3 , x / 6 + 1 / 2 otherwise \text{Hardsigmoid}(x) = \begin{cases} 0 & \text{if~} x \le -3, \\ 1 & \text{if~} x \ge +3, \\ x / 6 + 1 / 2 & \text{otherwise} \end{cases} Hardsigmoid(x)=⎩ ⎨ ⎧01x/6+1/2if x≤−3,if x≥+3,otherwise
图
代码
import torch
import torch.nn as nn
m = nn.Hardsigmoid()
input = torch.randn(2)
output = m(input)
print("input: ", input) # input: tensor([ 1.6288, -0.0689])
print("output: ", output) # output: tensor([0.7715, 0.4885])
【参考】
Hardsigmoid — PyTorch 1.13 documentation