【PyTorch】教程:torch.nn.Softplus

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)=β1log(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])

【参考】

Softplus — PyTorch 1.13 documentation

猜你喜欢

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