Some problems with WeightedRandomSampler

I’m not sure if I understand it correctly, but it seems you would like to sample single pixels from your masks?
That doesn’t seem to make much sense, as your input image and mask would be created by pixel information of various other images and masks.

Your use case is basically similar to a multi-label classification, i.e. each sample might have more then a single active target. This case might be a bit complicated and I’m really not sure how to set the weights properly.
If the majority class occurs often together with a minority class, you can’t really oversample the minority class. Maybe @rasbt might have some ideas on this particular case.
In the past I tried to get the class counts for all classes individually (although they appeared often in pairs) and tried to create weights by multiplying the frequencies. Still, I’m not sure, if that is the best approach.