pytorch中的交叉熵(CrossEntropyLoss)的使用说明


官方示例:

>>> loss = nn.CrossEntropyLoss()
>>> input = torch.randn(3, 5, requires_grad=True)
>>> target = torch.empty(3, dtype=torch.long).random_(5)
>>> output = loss(input, target)
>>> output.backward()

1.在loss中的输入中,target为类别的index,而非one-hot编码。

2.在输入的target的index中,数据的范围为[0, c-1],其中c为类别的总数,注意index的编码从0开始。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM