torch.nn.bceloss()和torch.nn.functional.binary_cross_entropy
这两个损失函数之间的基本区别是什么?我已经尝试使用两个损失功能。
What is the basic difference between these two loss functions? I have already tried using both the loss functions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不同之处在于,
和是两个与同一操作的Pytorch接口。nn.bceloss
,
torch.nn.bceloss
是一类,是从nn.module
这使得以两步的方式使用它,就像您始终在OOP中一样(面向对象的编程):初始化然后使用。初始化处理参数和属性初始化,因为该名称暗示了使用状态运算符(例如参数化层和类型)非常有用的。这是实现自己的类时要走的方法,例如:另一方面, selt ,
torch.nn.functional.binary.binary.binary_cross_entropy
是功能接口。实际上,它是nn.bceloss
使用的基础操作员/Loss.py#l1164“ rel =“ noreferrer”> 这条线 。您可以使用此界面,但是使用状态运营商时,这可能会变得笨拙。在这种特殊情况下,二进制跨透镜损失没有参数(在最一般的情况下),因此您可以做:The difference is that
nn.BCEloss
andF.binary_cross_entropy
are two PyTorch interfaces to the same operations.The former,
torch.nn.BCELoss
, is a class and inherits fromnn.Module
which makes it handy to be used in a two-step fashion, as you would always do in OOP (Object Oriented Programming): initialize then use. Initialization handles parameters and attributes initialization as the name implies which is quite useful when using stateful operators such as parametrized layers and the kind. This is the way to go when implementing classes of your own, for example:On the other hand, the later,
torch.nn.functional.binary_cross_entropy
, is the functional interface. It is actually the underlying operator used bynn.BCELoss
, as you can see at this line. You can use this interface but this can become cumbersome when using stateful operators. In this particular case, the binary cross-entropy loss does not have parameters (in the most general case), so you could do:bceloss 是 binary_cross_entropy 损失。
torch.nn.functional.binary_cross_entropy 计算 torch.nn.bceloss()的实际损失
BCEloss is the Binary_Cross_Entropy loss.
torch.nn.functional.binary_cross_entropy calculates the actual loss inside the torch.nn.BCEloss()