class_docstr: Sampler that restricts data loading to the label of the dataset.
  
  A class-aware sampling strategy to effectively tackle the
  non-uniform class distribution. The length of the training data is
  consistent with source data. Simple improvements based on `Relay
  Backpropagation for Effective Learning of Deep Convolutional
  Neural Networks <https://arxiv.org/abs/1512.05830>`_
  
  The implementation logic is referred to
  https://github.com/Sense-X/TSD/blob/master/mmdet/datasets/samplers/distributed_classaware_sampler.py
  
  Args:
      dataset: Dataset used for sampling.
      seed (int, optional): random seed used to shuffle the sampler.
          This number should be identical across all
          processes in the distributed group. Defaults to None.
      num_sample_class (int): The number of samples taken from each
          per-label list. Defaults to 1.
class_docstr_tok: ["Sampler","that","restricts","data","loading","to","the","label","of","the","dataset",".","A","class-aware","sampling","strategy","to","effectively","tackle","the","non-uniform","class","distribution",".","The","length","of","the","training","data","is","consistent","with","source","data",".","Simple","improvements","based","on","`","Relay","Backpropagation","for","Effective","Learning","of","Deep","Convolutional","Neural","Networks","<","https",":","\/\/arxiv.org\/abs\/1512.05830",">","`","_","The","implementation","logic","is","referred","to","https",":","\/\/github.com\/Sense-X\/TSD\/blob\/master\/mmdet\/datasets\/samplers\/distributed_classaware_sampler.py","Args",":","dataset",":","Dataset","used","for","sampling",".","seed","(","int",",","optional",")",":","random","seed","used","to","shuffle","the","sampler",".","This","number","should","be","identical","across","all","processes","in","the","distributed","group",".","Defaults","to","None",".","num_sample_class","(","int",")",":","The","number","of","samples","taken","from","each","per-label","list",".","Defaults","to","1","."]
code: def __iter__(self) -> Iterator[int]:
      # deterministically shuffle based on epoch
      g = torch.Generator()
      g.manual_seed(self.epoch + self.seed)
  
      # initialize label list
      label_iter_list = RandomCycleIter(
          self.valid_cat_inds, generator=g
      )
      # initialize each per-label image list
      data_iter_dict = dict()
      for i in self.valid_cat_inds:
          data_iter_dict[i] = RandomCycleIter(
              self.cat_dict[i], generator=g
          )
  
      def gen_cat_img_inds(cls_list, data_dict, num_sample_cls):
          """Traverse the categories and extract `num_sample_cls` image
          indexes of the corresponding categories one by one."""
          id_indices = []
          for _ in range(len(cls_list)):
              cls_idx = next(cls_list)
              for _ in range(num_sample_cls):
                  id = next(data_dict[cls_idx])
                  id_indices.append(id)
          return id_indices
  
      # deterministically shuffle based on epoch
      num_bins = int(
          math.ceil(
              self.total_size
              * 1.0
              / self.num_classes
              / self.num_sample_class
          )
      )
      indices = []
      for i in range(num_bins):
          indices += gen_cat_img_inds(
              label_iter_list, data_iter_dict, self.num_sample_class
          )
  
      # fix extra samples to make it evenly divisible
      if len(indices) >= self.total_size:
          indices = indices[: self.total_size]
      else:
          indices += indices[: (self.total_size - len(indices))]
      assert len(indices) == self.total_size
  
      # subsample
      offset = self.num_samples * self.rank
      indices = indices[offset : offset + self.num_samples]
      assert len(indices) == self.num_samples
  
      return iter(indices)
  
file_path: mmdetection/mmdet/datasets/samplers/class_aware_sampler.py
imports: import math
  from typing import Dict, Iterator, Optional, Union
  import numpy
  import torch
  from mmengine.dataset import BaseDataset
  from mmengine.dist import get_dist_info, sync_random_seed
  from torch.utils.data import Sampler
  from mmdet.registry import DATA_SAMPLERS
label_desc: Use image node_id 3 for calling the ClassAwareSampler obj's underlying member method code with example usage: obj.__iter__() and returns: iter, id_indices