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