outputs['out'] should work and the error points to the additional dimension in your labels tensor.
Squeeze dim1 before passing labels to the loss function and it should work:
labels = labels.squeeze(1)




 shyxiaoxiao:

Another question is that my dataset(images) have 5 classes and some ignoer pixels then should I set the num_classes to 5 or 6 in the model ?


If you have 5 valid classes and an additional class you want to ignore, you could use 6 classes in total and pass ignore_index=class_index_to_ignore to your loss function.