Solved by ptrblck in post #7 
              
              
                As @smth suggested, the error is raised by an out-of-bounds indexing. 
Based on the stack trace it seems that your model output contains logits (or log probabilities) for 2 classes, while the target uses a class index of 2, which would assume at least 3 classes. 
nn.CrossEntropyLoss and nn.NLLLoss e…