Skip to content
Advertisement

IndexError: Target 1 is out of bounds

When I run the program below, it gives me an error. The problem seems to be in the loss function but I can’t find it. I have read the Pytorch Documentation for nn.CrossEntropyLoss but still can’t find the problem.

Image size is (1 x 256 x 256), Batch size is 1

I am new to PyTorch, thanks.

JavaScript

Error:

JavaScript

Advertisement

Answer

This looks like a binary classifier model: cat or not cat. But you are using CrossEntropyLoss which is used when you have more than 2 target classes. So what you should use is Binary Cross Entropy Loss.

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement