【PyTorch】教程:torch.nn.Sigmoid

torch.nn.Sigmoid

原型

CLASS torch.nn.Sigmoid(*args, **kwargs)

定义

Applies the element-wise function:

S i g m o i d ( x ) = σ ( x ) = 1 1 + exp ⁡ ( − x ) Sigmoid(x)=\sigma(x)=\frac{1}{1+\exp(-x)} Sigmoid(x)=σ(x)=1+exp(x)1

在这里插入图片描述

代码

import torch
import torch.nn as nn

m = nn.Sigmoid()
input = torch.randn(4)
output = m(input)

print("input: ", input)   # input:  tensor([-0.8462,  0.7929, -0.5680, -0.5883])
print("output: ", output) # output:  tensor([0.3002, 0.6885, 0.3617, 0.3570])

【参考】

Sigmoid — PyTorch 2.0 documentation

猜你喜欢

转载自blog.csdn.net/zhoujinwang/article/details/129602479
今日推荐