Hello, I am trying to implement the correct way of weight maps from U-net architecture as well. Did you come to the conclusion from the 2 options you brought us in this question?
I am reading the documentation for the first option: torch.nn.functional.cross_entropy, and for the input parameter weight: a number_of_classes tensor size is needed, so I think this option is not what you were looking for.