How to handle imbalanced classes

This post shows you an example of splitting the indices and using a WeightedRandomSampler. Let me know, if this works for you.