F.binary_cross_entropy_with_logits函数和 F.binary_cross_entropy函数的reduction 参数都默认是‘mean’模式,直接使用默认值的话,结果是320个样本点的二元交叉熵的平均值, 若要计算8个图像样本的二元交叉熵的平均值,可以设置reduction=‘sum’ ,这样能得到320个样本点的二元交叉熵的和,然后除以batch_size 就能得到...
有一个(类)损失函数名字中带了with_logits. 而这里的logits指的是,该损失函数已经内部自带了计算logit的操作,无需在传入给这个loss函数之前手动使用sigmoid/softmax将之前网络的输入映射到[0,1]之间 再看看官方给的示例代码: binary_cross_entropy: input = torch.randn((3, 2), requires_grad=True) target =...
的确binary_cross_entropy_with_logits不需要sigmoid函数了。 事实上,官方是推荐使用函数带有with_logits的,解释是 This loss combines a Sigmoid layer and the BCELoss in one single class. This version is more numerically stable than using a plain Sigmoid followed by a BCELoss as, by combining the ope...