class_docstr: Dataset for ReID.
  
  Args:
      triplet_sampler (dict, optional): The sampler for hard mining
          triplet loss. Defaults to None.
      keys: num_ids (int): The number of person ids.
            ins_per_id (int): The number of image for each person.
class_docstr_tok: ["Dataset","for","ReID",".","Args",":","triplet_sampler","(","dict",",","optional",")",":","The","sampler","for","hard","mining","triplet","loss",".","Defaults","to","None",".","keys",":","num_ids","(","int",")",":","The","number","of","person","ids",".","ins_per_id","(","int",")",":","The","number","of","image","for","each","person","."]
docstr: Triplet sampler for hard mining triplet loss. First, for one
  pos_pid, random sample ins_per_id images with same person id.
  
  Then, random sample num_ids - 1 images for each negative id.
  Finally, random sample ins_per_id images for each negative id.
  
  Args:
      pos_pid (ndarray): The person id of the anchor.
      num_ids (int): The number of person ids.
      ins_per_id (int): The number of images for each person.
  
  Returns:
      Dict: Annotation information of num_ids X ins_per_id images.
docstr_tok: ["Triplet","sampler","for","hard","mining","triplet","loss",".","First",",","for","one","pos_pid",",","random","sample","ins_per_id","images","with","same","person","id",".","Then",",","random","sample","num_ids","-","1","images","for","each","negative","id",".","Finally",",","random","sample","ins_per_id","images","for","each","negative","id",".","Args",":","pos_pid","(","ndarray",")",":","The","person","id","of","the","anchor",".","num_ids","(","int",")",":","The","number","of","person","ids",".","ins_per_id","(","int",")",":","The","number","of","images","for","each","person",".","Returns",":","Dict",":","Annotation","information","of","num_ids","X","ins_per_id","images","."]
code: def triplet_sampling(
      self, pos_pid, num_ids: int = 8, ins_per_id: int = 4
  ) -> Dict:
      """Triplet sampler for hard mining triplet loss. First, for one
      pos_pid, random sample ins_per_id images with same person id.
  
      Then, random sample num_ids - 1 images for each negative id.
      Finally, random sample ins_per_id images for each negative id.
  
      Args:
          pos_pid (ndarray): The person id of the anchor.
          num_ids (int): The number of person ids.
          ins_per_id (int): The number of images for each person.
  
      Returns:
          Dict: Annotation information of num_ids X ins_per_id images.
      """
      assert len(self.pids) >= num_ids, (
          "The number of person ids in the training set must "
          "be greater than the number of person ids in the sample."
      )
  
      pos_idxs = self.index_dic[
          int(pos_pid)
      ]  # all positive idxs for pos_pid
      idxs_list = []
      # select positive samplers
      idxs_list.extend(
          pos_idxs[
              np.random.choice(
                  pos_idxs.shape[0], ins_per_id, replace=True
              )
          ]
      )
      # select negative ids
      neg_pids = np.random.choice(
          [i for i, _ in enumerate(self.pids) if i != pos_pid],
          num_ids - 1,
          replace=False,
      )
      # select negative samplers for each negative id
      for neg_pid in neg_pids:
          neg_idxs = self.index_dic[neg_pid]
          idxs_list.extend(
              neg_idxs[
                  np.random.choice(
                      neg_idxs.shape[0], ins_per_id, replace=True
                  )
              ]
          )
      # return the final triplet batch
      triplet_img_infos = []
      for idx in idxs_list:
          triplet_img_infos.append(
              copy.deepcopy(self.get_data_info(idx))
          )
      # Collect data_list scatters (list of dict -> dict of list)
      out = dict()
      for key in triplet_img_infos[0].keys():
          out[key] = [_info[key] for _info in triplet_img_infos]
      return out
  
file_path: mmdetection/mmdet/datasets/reid_dataset.py
imports: import copy
  import os.path
  from collections import defaultdict
  from typing import Any, Dict, List
  import numpy
  from mmengine.dataset import BaseDataset
  from mmengine.utils import check_file_exist
  from mmdet.registry import DATASETS
label_desc: Use image node_id 5 for calling the ReIDDataset obj's underlying member method code with example usage: obj.triplet_sampling(pos_pid, num_ids, ins_per_id) and returns: out