class_docstr: BatchSampler - samples n_samples for each of the n_domains.
      Returns batches of size n_domains * (batch_size / n_domains)
  
  Args:
      dataset (.multi_domain.MultiDomainImageFolder or torch.utils.data.Subset): Multi-domain data access.
      batch_size (int): Batch size
class_docstr_tok: ["BatchSampler","-","samples","n_samples","for","each","of","the","n_domains",".","Returns","batches","of","size","n_domains","*","(","batch_size","\/","n_domains",")","Args",":","dataset","(",".multi_domain.MultiDomainImageFolder","or","torch.utils.data.Subset",")",":","Multi-domain","data","access",".","batch_size","(","int",")",":","Batch","size"]
code: def __init__(self, dataset, batch_size):
      # call to __init__ of super class will generate class balanced sampler, do not do it here
      dataset_type = type(dataset)
      if dataset_type is torch.utils.data.Subset:
          domain_labels = np.asarray(dataset.dataset.domain_labels)[
              dataset.indices
          ]
          domains = list(dataset.dataset.domain_to_idx.values())
      else:
          domain_labels = np.asarray(dataset.domain_labels)
          domains = list(dataset.domain_to_idx.values())
  
      n_domains = len(domains)
  
      self._n_samples = batch_size // n_domains
      if self._n_samples == 0:
          raise ValueError(
              f"batch_size should be bigger than the number of classes, got {batch_size}"
          )
  
      self._class_iters = [
          InfiniteSliceIterator(
              np.where(domain_labels == domain_)[0], class_=domain_
          )
          for domain_ in domains
      ]
      batch_size = self._n_samples * n_domains
  
      self._n_batches = len(domain_labels) // batch_size
      if self._n_batches == 0:
          raise ValueError(
              f"Dataset is not big enough to generate batches with size {batch_size}"
          )
      logging.debug("K=", n_domains, "nk=", self._n_samples)
      logging.debug("Batch size = ", batch_size)
  
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 1 to create a new DomainBalancedBatchSampler object from inherited base classes: BalancedBatchSampler with example: obj = DomainBalancedBatchSampler(dataset, batch_size)