Mean is not a valid value for reduction

I run the deeplabv3+ on cityscapes dataset, in the training I run the following code:

for cur_step, (images, labels) in enumerate( train_loader ):
if scheduler is not None:
#images is ([8,3,512,512]) tensor, labels is ([8,512,512]) tensor, 8 is the batch_size
images =, dtype=torch.float32)
labels =, dtype=torch.long)
print( np.unique(labels.cpu().numpy()) )
# N, C, H, W
#outputs is ([8,20,512,512]) tensor, 20 is class num
outputs = model(images)
#criterion is Cross Entropy Loss
loss = criterion(outputs, labels)

in the above code, I got the error

I think the bug is in the " loss = criterion(outputs, labels)", but I dont know how to fix it

How did you initialize the criterion?
Note that 'mean' should be passed as a string.
Also, in older PyTorch versions (pre 1.0), you had to use 'elementwise_mean' as far as I remember.
If you are using one of the older versions, I would strongly recommend to update.