Load the same number of data per class 
  
  
    I know weighted sampler can solve imbalanced data problem. 
However, I wonder is there a way to load exactly the same number of data per class ? 
What I need now is, for example, a batch of 10 samples from class A, 10 from class B, 10 from class C, ETC…( I mean “not probablistically” but deterministically make sure to load 10 sample per class. ) 
I also want to know how to combine that solution with torch.utils.data.DataLoader
  



  
    
    
    Load the same number of data per class 
  
  
    I had the same problem when I re-implement PFE, which needs 64 classes, which have 4  data in each class, as an input. 
Here’s my solution (not very good but useful for me). 
#class Dataset
def __init__(self):
    self.label_to_index = {'A': [1, 3, 4], 'B': [0, 2, 5], 'C': [6, 7, 8]}

def __getitem__(self, item):
    images = np.empty((1, *image_shape))
    labels = np.empty((1,))
    for i, (label, indices) in enumerate(self.label_to_index.items()):
        index = np.random.choice(indices, 1, …