pytorch的HingeEmbeddingLoss 有先后顺序


L1Loss  MSELoss 都没问题,但是 HingeEmbeddingLoss 却总报错 说不能求梯度

 

#criterion = nn.MSELoss()
#criterion = nn.L1Loss()
criterion = nn.HingeEmbeddingLoss()

 

https://pytorch.org/docs/stable/generated/torch.nn.HingeEmbeddingLoss.html#torch.nn.HingeEmbeddingLoss

 

发现 Hinge损失函数还是区分了 

  • Input: (*)() where *∗ means, any number of dimensions. The sum operation operates over all the elements.

  • Target: (*)() , same shape as the input

  • Output: scalar. If reduction is 'none', then same shape as the input

 

 保证模型输出的变量在第一个就可以了,第二个是Label/Target

      loss =criterion(out, data.y)


免责声明!

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



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