当前位置:   article > 正文

BCEWithLogitsLoss_nn.bcewithlogitsloss 权重

nn.bcewithlogitsloss 权重

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)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

在这里插入图片描述

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))
  • 1
  • 2
  • 3
  • 4
  • 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))
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/708949
推荐阅读
  

闽ICP备14008679号