I’ve checked the code again and it’s running on my machine.
Could you post the error message, so that I can have a look?
I think I’ve misunderstood your question. I thought you would like to weight pixel-wise, not class-wise.
For a class weighting you could use the weight argument in nn.NLLLoss 158 or nn.CrossEntropyLoss 254.
In my example I create a weight mask to weight the edges of the targets more, but that’s apparently not your use case.
Let me know, if the class weight works for you!