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)

原文地址:https://www.cnblogs.com/xuanmanstein/p/13520020.html