You can build your own sampler, where you have a permutation of the data from the class with higher frequency while over sampling from the class with lower frequency:
for example:
class_vector = [0,0,0,0,0,0,0,1,1,1]
class count = {0: 6 1: 3}
build a permutation of 0-6 with
np.random.permutation(6) and a over-sampling vector of class 1:
np.random.randint(7,9,6) # generates 6 integer numbers from 7,8,9
If you do not want data to repeat you can do a Stratified sampling:

  
    
    
    How to enable the dataloader to sample from each class with equal probability 
  
  
    The dataloader utility in torch (courtesy of Soumith Chintala) allowed one to sample from each class with equal probability. I was wondering, if there is a straightforward approach to enable the same in pytorch dataloaders.
  


helpful links:

  
      github.com
  
  
    pytorch/pytorch/blob/master/torch/utils/data/sampler.py 70
import torch
from torch._six import int_classes as _int_classes


class Sampler(object):
    r"""Base class for all Samplers.

    Every Sampler subclass has to provide an __iter__ method, providing a way
    to iterate over indices of dataset elements, and a __len__ method that
    returns the length of the returned iterators.
    """

    def __init__(self, data_source):
        pass

    def __iter__(self):
        raise NotImplementedError

    def __len__(self):
        raise NotImplementedError


  This file has been truncated. show original

  
  
    
    
  
  


http://pytorch.org/tutorials/beginner/data_loading_tutorial.html# 75