code: def make_weights_for_balanced_classes(self):
      
  
      nclasses = len(self.classes)
      count = np.ones(nclasses)
      for item in self.data:
        count[item[1]] += 1
  
      N = float(sum(count))
      weight_per_class = N / count
      weight = np.zeros(len(self.data))
      for idx, item in enumerate(self.data):
        weight[idx] = weight_per_class[item[1]]
      return weight
docs: adopted from https://discuss.pytorch.org/t/balanced-sampling-between-classes-with-torchvision-dataloader/2703/3