Binary label: Tensor type?

Hello,

It seems to be a minor issue. I’m training a toy siamese network. My label is either -1 or 1, so I was using a LongTensor to store the label. It seems to me that torch complains because target is supposed to be a FloatTensor?

File “/usr/local/lib/python2.7/dist-packages/torch/nn/_functions/loss.py”, line 110, in forward
buffer[torch.eq(target, -1.)] = 0
TypeError: torch.eq received an invalid combination of arguments - got (torch.cuda.LongTensor, float), but expected one of:

  • (torch.cuda.LongTensor tensor, int value)
    didn’t match because some of the arguments have invalid types: (torch.cuda.LongTensor, float)
  • (torch.cuda.LongTensor tensor, torch.cuda.LongTensor other)
    didn’t match because some of the arguments have invalid types: (torch.cuda.LongTensor, float)
  • (torch.cuda.LongTensor tensor, int value)
    didn’t match because some of the arguments have invalid types: (torch.cuda.LongTensor, float)
  • (torch.cuda.LongTensor tensor, torch.cuda.LongTensor other)
    didn’t match because some of the arguments have invalid types: (torch.cuda.LongTensor, float)

Thanks!

What loss are you using? I think casting the target to a FloatTensor should fix it.

I’m using HingeEmbeddingLoss.
Yes, casting to FloatTensor fixes the problem.

I assumed that a binary label should be an integer until it complains.

Thanks!

1 Like