binary_cross_entropy_with_logits 和 binary_cross_entropy 的区别

差在一个 sigmoid 函数上

见下面的代码

import torch
from torch.nn import functional as F
logits = torch.rand(16,7)
ys = torch.randint(0,2,(16,7))

F.binary_cross_entropy_with_logits(logits,ys.float()) == F.binary_cross_entropy(torch.sigmoid(logits),ys.float())

你可能感兴趣的:(python,深度学习笔记,深度学习,pytorch,人工智能)