How to get a batch with equal number of images of each class?

You could use the WeightedRandomSampler.

The issue was also discussed in this thread.

1 Like