B
C
E
W
i
t
h
L
o
g
i
t
s
L
o
s
s
BCEWithLogitsLoss
BCEWithLogitsLoss
一 Pytorch实现
torch.nn.BCEWithLogitsLoss(
weight: Optional[torch.Tensor] = None,
size_average=None,
reduce=None,
reduction: str = 'mean',
pos_weight: Optional[torch.Tensor] = None)
target = torch.ones([10, 64], dtype=torch.float32)
output = torch.full([10, 64], 1.5)
pos_weight = torch.ones([64])
criterion = torch.nn.BCEWithLogitsLoss(pos_weight=pos_weight)
criterion(output, target)
import torch
from torch import nn
target = torch.tensor([[1,2,3]],dtype=torch.float)
output = torch.tensor([[1,2,30]],dtype=torch.float)
criterion = torch.nn.BCEWithLogitsLoss()
criterion(output, target)