Hi,
I am getting an error while training this CNN, the inputs are images and the labes are one-hot encoded vectors, and I am getting the following error when training the CNN
Thanks for the help in advance
Hi,
I am getting an error while training this CNN, the inputs are images and the labes are one-hot encoded vectors, and I am getting the following error when training the CNN
Thanks for the help in advance
nn.CrossEntropyLoss
expects the target as a LongTensor
and to have the shape [batch_size]
containing the class indices in the range [0, nb_classes]
.
Since your target is one-hot encoded, you could use:
target = torch.argmax(target, dim=1)`
to create the expected shape and type.
PS: It’s better to post code snippets by wrapping them into three backticks ``` instead of screenshots.