RuntimeError: 1D target tensor expected, multi-target not supported site:stackoverflow.com code example

Example: RuntimeError: 1D target tensor expected, multi-target not supported site:stackoverflow.com

For nn.CrossEntropyLoss the target has to be a single number
from the interval [0, #classes] instead of a one-hot encoded target vector.
Your target is [1, 0], thus PyTorch thinks 
you want to have multiple labels per input which is not supported.

Replace your one-hot-encoded targets:

[1, 0] --> 0

[0, 1] --> 1

Tags:

Misc Example