Here the approach I used was to make a dataset for each class, and then merge them.

  
      
      TensorFlow
  
  
    

Classification on imbalanced data  |  TensorFlow Core 15



  
  
    
    
  
  


I used sample_from_datasets so it’s approximately equal. But you could also zip the datasets then and .map a function to stack all the zipped tensors.