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

0

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
Posted by: Guest on December-19-2020

Python Answers by Framework

Browse Popular Code Answers by Language