In image segmentation, how to deal with the inconsistency between pred and true shape when calculating loss

For example,I’m calculating dice loss right now.
My pred shape is [8,2,512,512], representing batch, channel, H, W
My true label shape is [8,512,512], representing batch, H, W
Calculating loss requires the same shape, how do I handle it?

my true label is a mask

If you are dealing with a multi-class segmentation, the shapes will work for nn.CrossEntropyLoss.