Solved by ptrblck in post #34 
              
              
                Based on your weights, I assume you might have multiples of this distribution: 
class_counts = torch.tensor([104, 642, 784])

If so, I’ve manipulated my example code to use your weights and data distribution to get approx. equally distributed batches: 
# Create dummy data with class imbalance 99 to …