How can I load the same number of data/images per class from the pascal dataset for the segmentation task?

I was wondering if there is a way to load a specific number of data per class for a multi-classes segmentation task?

can I use BatchSampler in this regard? if so, can you help me with an example? I have found these two topics here and here but I couldn’t implement them for multi-class labeling. Thanks in advance!