Currently your target has float values, which won’t work using nn.CrossEntropyLoss.
You should transform these values to class indices, e.g. by using a threshold.
This will make sure that the center of the gaussian is marked as class1, while all other voxels belong to class0 (or vice versa).
Haha, just skip the pred.unique() part. I used it just for debugging purposes to see when the model learned to predict ones and forgot to remove it.