Imbalanced classes in semantic segmentation

Is it better to calculate class weights to re-scale loss for the whole dataset or per minibatch?

In my experience, it’s better to rescale the loss based on the entire training set. But I’d love to hear other opinions!