The PyTorch docs mention the following about the input arguments for nn.CrossEntropyLoss :
image866×262 23.6 KB
If you have only two classes in your dataset, the loss will still accept it because it expects all target tensor values to be in the range [0, 1000-1]. So there won’t be an error raised. What you’re essentially doing is training a model for 1000-class classification and only showing it examples from the first two classes.