【PyTorch】教程:torch.nn.Hardsigmoid

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 x3,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

猜你喜欢

转载自blog.csdn.net/zhoujinwang/article/details/129290891