原型
CLASS torch.nn.Hardsigmoid(inplace=False)
参数
False
定义
Hardsigmoid(x)={0if x≤−3,1if x≥+3,x/6+1/2otherwise\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 nnm = 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
上一篇:5. 郭老师爱猜果子