the error about CudaClassNLLCriterion_updateOutput

when i use criterion = torch.nn.CrossEntropyLoss() to get the loss between the predicted value and the label, there is a error like this:
TypeError: CudaClassNLLCriterion_updateOutput received an invalid combination of arguments - got (int, torch.cuda.FloatTensor, !torch.cuda.FloatTensor!, torch.cuda.FloatTensor, bool, NoneType, torch.cuda.FloatTensor), but expected (int state, torch.cuda.FloatTensor input, torch.cuda.LongTensor target, torch.cuda.FloatTensor output, bool sizeAverage, [torch.cuda.FloatTensor weights or None], torch.cuda.FloatTensor total_weight)

i have checked my inputs many times, the two inputs are no problem. While this error still exist. Does any one can give some suggestions?

1 Like


Did you check that target tensor (which should be class numbers, not one-hot vectors) is actually a torch.cuda.LongTensor?
If your class numbers happen to be in a FloatTensor, you can convert them to a LongTensor with labels.long() (likely preferably before wrapping them in a Variable.

Best regards



Thanks for your help. it works.