stark:


Is it a general rule that the class weights should be pre-calculated for the entire training data rather than calculating for each batch on the fly?



From my experience, yes. Here you just do the processing of the weights in the dataset once, instead of doing it on each batch.



 stark:


Is the use of “class weights” in loss calculation and “data augmentation” mutually exclusive?



That is a good question. I would assume that depending on your data augmentation you would have to decide if you recalculate or not your weights. For example, the usual data augmentation I do in images is a horizontal flip and re-scaling, and I would argue that by doing these I am not modifying the ratio of each by such an amount that would I would need to recalculate the class weights.



 stark:


Should one use weights calculated from each input batch of A) augmented images or B) images before augmenting them?



If you think that the data augmentation changes somehow the ratios between classes by a considerable amount, then I would suggest you to do one of these things:

Update the weights on the fly, but be aware that some classes might not be present when you do the weight recalculation.
Apply the augmentation to your entire dataset and get the weights from there. But since some augmentations are based on random values, I would suggest you run this a few times to get an average of the class weights after augmentation.

Thank you for the questions!
I hope this helps!