赞
踩
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) # 64 classes, batch size = 10
output = torch.full([10, 64], 1.5) # A prediction (logit)
pos_weight = torch.ones([64]) # All weights are equal to 1
criterion = torch.nn.BCEWithLogitsLoss(pos_weight=pos_weight)
criterion(output, target) # -log(sigmoid(1.5))
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) # -log(sigmoid(1.5))
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。