class_docstr: Samples elements randomly from a given list of indices for imbalanced dataset
  
  :param indices: (list, optional): a list of indices
  :param num_samples: (int, optional): number of samples to draw
class_docstr_tok: ["Samples","elements","randomly","from","a","given","list","of","indices","for","imbalanced","dataset",":","param","indices",":","(","list",",","optional",")",":","a","list","of","indices",":","param","num_samples",":","(","int",",","optional",")",":","number","of","samples","to","draw"]
code: def __init__(self, dataset, indices=None, num_samples=None):
      # if indices is not provided, all elements in the dataset will be considered
      self.indices = (
          list(range(len(dataset))) if indices is None else indices
      )
  
      # if num_samples is not provided, draw `len(indices)` samples in each iteration
      self.num_samples = (
          len(self.indices) if num_samples is None else num_samples
      )
  
      # distribution of classes in the dataset
      label_to_count = {}
      for idx in self.indices:
          label = self._get_label(dataset, idx)
          if label in label_to_count:
              label_to_count[label] += 1
          else:
              label_to_count[label] = 1
  
      # weight for each sample
      weights = [
          1.0 / label_to_count[self._get_label(dataset, idx)]
          for idx in self.indices
      ]
      self.weights = torch.DoubleTensor(weights)
  
imports: import math
  from .utils import th_random_choice
  import torch.utils.data
  import torchvision
  from .datasets import FolderDataset, MultiFolderDataset, PredictFolderDataset, ClonedFolderDataset
  from torch.utils.data.sampler import Sampler
label_desc: Use image node_id 1 to create a new ImbalancedDatasetSampler object from inherited base classes: Sampler with example: obj = ImbalancedDatasetSampler(dataset, indices, num_samples)