Make sure the target has the shape [N, H, W] and contains class indices in the range [0, nb_classes-1], while your output should have the shape [N, nb_classes, H, W].
Apparently some target tensor contains values outside of this range.
You could use a print statement while iterating your DataLoader to track down the problematic batch.