class_docstr: BatchSampler - from a MNIST-like dataset, samples batch_size according to given input distribution
  assuming multi-class labels
  adapted from https://github.com/adambielski/siamese-triplet/blob/master/datasets.py
class_docstr_tok: ["BatchSampler","-","from","a","MNIST-like","dataset",",","samples","batch_size","according","to","given","input","distribution","assuming","multi-class","labels","adapted","from","https",":","\/\/github.com\/adambielski\/siamese-triplet\/blob\/master\/datasets.py"]
code: def __iter__(self):
      for _ in range(self._n_batches):
          # sample batch_size classes
          class_idx = np.random.choice(
              self._classes,
              p=self._class_weights,
              replace=True,
              size=self._batch_size,
          )
          indices = []
          for class_, num in zip(
              *np.unique(class_idx, return_counts=True)
          ):
              indices.extend(self._class_to_iter[class_].get(num))
          np.random.shuffle(indices)
          yield indices
  
      for class_iter in self._class_to_iter.values():
          class_iter.reset()
  
imports: import logging
  import numpy
  import torch.utils.data
  import torchvision
  from torch.utils.data.sampler import BatchSampler, RandomSampler
label_desc: Use image node_id 2 for calling the ReweightedBatchSampler obj's underlying member method code with example usage: obj.__iter__() without return types