torch.nn.Softplus
原型
CLASS torch.nn.Softplus(beta=1, threshold=20)
参数
- beta (int) – Softplus里
β
\beta
β 值, 默认为
1
. - threshold (int) – 高于这个值恢复为线性函数,默认为
20
.
定义
Softplus ( x ) = 1 β ∗ log ( 1 + exp ( β ∗ x ) ) \text{Softplus}(x)=\frac{1}{\beta}*\log(1+\exp(\beta* x)) Softplus(x)=β1∗log(1+exp(β∗x))
图
代码
import torch
import torch.nn as nn
m = nn.Softplus()
input = torch.randn(4)
output = m(input)
print("input: ", input) # input: tensor([-1.7161, -1.2501, 0.4484, -0.4609])
print("output: ", output) # output: tensor([0.1653, 0.2519, 0.9423, 0.4890])