1. BCELoss

class torch.nn.BCELoss(weight=None, size_average=True, reduce=True)

* effect :
calculation target  and output  The binary cross entropy between (Binary Cross Entropy)

 

N :batchsize

If reduce =True
l(x,y)=mean(L),if size_average=True l(x,y)=sum(L),if size_average=False
It is used to calculate the reconstruction error , as anto-encoder  in

targets y The value of is in 0 and 1 between

* parameter weight(Tensor,optional) - each batch Weight of elements . size_average- Default to True.
True,losses stay minibatch combination weight Average average. False,losses stay minibatch Add and sum sum.
When reduce=False Time , Ignore the parameter . reduce Default to True True,losses stay minibatch Average or sum
False,losses return per input/target Element value , And ignore it size_average input -input x,(N,*) input -target
y,(N,*) output - If reduce=True, Output scalar value , If reduce=False, The input and output are consistent ,(N,*)
* Examples import torch import torch.nn as nn sig = nn.Sigmoid() loss =
nn.BCELoss() input = torch.randn(3, requires_grad=True) target =
torch.empty(3).random_(2) output = loss(sig(input), target) output.backward()
2. BCEWithLogitsLoss

class torch.nn.BCEWithLogitsLoss(weight=None, size_average=True, reduce=True)

* effect
The loss  This layer includes  Sigmoid  Layer and BCELoss  layer .  Single category task .

The stability of numerical calculation is better (log-sum-exp trik),  Compared to Sigmoid +BCELoss.

If  reduce =True,
l(x,y)=mean(L),if size_average=True l(x,y)=sum(L),if size_average=False
It is used to calculate the reconstruction error , as auto-encoder  in .

target t[i]  The value of is 0  and 1  Values between .

* parameter weight(Tensor,optional) - each batch Weight of elements . size_average- Default to True.
True,losses stay minibatch combination weight Average average. False,losses stay minibatch Add and sum sum.
When reduce=False Time , Ignore the parameter . reduce Default to True True,losses stay minibatch Average or sum
False,losses return per input/target Element value , And ignore it size_average input -input x,(N,*) input -target
y,(N,*) output - If reduce=True, Output scalar value , If reduce=False, The input and output are consistent ,(N,*)
 

Technology