F.torch.sigmoid

二分类

import torch
from torch.nn import functional as F

X = torch.tensor([[0,0],[1,0],[0,1],[1,1]] ,dtype = torch.float32)

torch.random.manual_seed(420)

dense = torch.nn.Linear(2,1)
zhat = dense(X)

sigma = F.torch.sigmoid(zhat)

y = [int(x) for x in sigma>0.5]
y

你可能感兴趣的:(深度学习)