pytorch BCELoss和BCEWithLogitsLoss
BCELoss CLASS torch.nn. BCELoss ( weight=None , size_average=None , reduce=None , reduction='mean' ) 创建一个标准来度量目标和输出之间的二进制交叉熵。 unreduced (i.e. with reduction set to 'none' ) 时该损失描述为: 其中N是批尺寸, 如果 reduction 不是 'none' (默认为 'mean' ), 则: 即,对批次中各样本损失求均值或求和。 其可以用来测量重构误差,例如一个自编码器。 注意目标y应该是0到1之间的数字。 Parameters: weight ( Tensor , optional ) – a manual rescaling weight given to the loss of each batch element. If given, has to be a Tensor of size nbatch . size_average ( bool , optional ) –(已弃用) Deprecated (see reduction ). By default, the losses are averaged over each loss element in the batch. Note that