Most likely your target indices and the model output doesn’t for your use case.
For a multi-class segmentation using two classes, the model output should contain lots and have the shape [batch_size, 2, height, width], while the target should contain class indices in [0, 1] and have the shape [batch_size, height, width]. Could you check these requirements? Also, you might want to run the code of the CPU to get a better error message.