How to tackle the class imbalance problem during training in PyTorch

Can someone please tell me if I have a different number of images per class during training on how to tackle the class imbalance problem in PyTorch?

How to solve this “class imbalance problem” in PyTorch?

You could over/undersample the classes using a WeightedRandomSampler.
Have a look at this post for a small example.