class_docstr: Sample person identities evenly in each batch.
  Args:
      train_color_label, train_thermal_label: labels of two modalities
      color_pos, thermal_pos: positions of each identity
      batchSize: batch size
class_docstr_tok: ["Sample","person","identities","evenly","in","each","batch",".","Args",":","train_color_label",",","train_thermal_label",":","labels","of","two","modalities","color_pos",",","thermal_pos",":","positions","of","each","identity","batchSize",":","batch","size"]
code: def __init__(
      self,
      train_color_label,
      train_thermal_label,
      color_pos,
      thermal_pos,
      batchSize,
      num_img_per_id=4,
  ):
      uni_label = np.unique(train_color_label)
      self.n_classes = len(uni_label)
  
      sample_color = np.arange(batchSize)
      sample_thermal = np.arange(batchSize)
      N = np.maximum(len(train_color_label), len(train_thermal_label))
  
      num_id_per_batch = batchSize / num_img_per_id
  
      for j in range(N // batchSize + 1):
          batch_idx = np.random.choice(
              uni_label, int(num_id_per_batch), replace=False
          )
  
          for s, i in enumerate(range(0, batchSize, num_img_per_id)):
              sample_flag = (
                  True
                  if len(color_pos[batch_idx[s]]) < num_img_per_id
                  or len(thermal_pos[batch_idx[s]]) < num_img_per_id
                  else False
              )
  
              sample_color[i : i + num_img_per_id] = np.random.choice(
                  color_pos[batch_idx[s]],
                  num_img_per_id,
                  replace=sample_flag,
              )
              sample_thermal[i : i + num_img_per_id] = np.random.choice(
                  thermal_pos[batch_idx[s]],
                  num_img_per_id,
                  replace=sample_flag,
              )
  
          if j == 0:
              index1 = sample_color
              index2 = sample_thermal
          else:
              index1 = np.hstack((index1, sample_color))
              index2 = np.hstack((index2, sample_thermal))
  
      self.visIndex = index1
      self.nirIndex = index2
      self.N = N
  
imports: from PIL import Image
  import os
  import torch.utils.data
  import torchvision.transforms
  from torch.utils.data.sampler import Sampler
  import numpy
label_desc: Use image node_id 1 to create a new IdentitySampler object from inherited base classes: Sampler with example: obj = IdentitySampler(train_color_label, train_thermal_label, color_pos, thermal_pos, batchSize, num_img_per_id)