class_docstr: Importance-based Sample Reweighting (ISR_N), described in `Prime Sample
  Attention in Object Detection <https://arxiv.org/abs/1904.04821>`_.
  
  Score hierarchical local rank (HLR) differentiates with RandomSampler in
  negative part. It firstly computes Score-HLR in a two-step way,
  then linearly maps score hlr to the loss weights.
  
  Args:
      num (int): Total number of sampled RoIs.
      pos_fraction (float): Fraction of positive samples.
      context (:class:`BaseRoIHead`): RoI head that the sampler belongs to.
      neg_pos_ub (int): Upper bound of the ratio of num negative to num
          positive, -1 means no upper bound.
      add_gt_as_proposals (bool): Whether to add ground truth as proposals.
      k (float): Power of the non-linear mapping.
      bias (float): Shift of the non-linear mapping.
      score_thr (float): Minimum score that a negative sample is to be
          considered as valid bbox.
class_docstr_tok: ["Importance-based","Sample","Reweighting","(","ISR_N",")",",","described","in","`","Prime","Sample","Attention","in","Object","Detection","<","https",":","\/\/arxiv.org\/abs\/1904.04821",">","`","_",".","Score","hierarchical","local","rank","(","HLR",")","differentiates","with","RandomSampler","in","negative","part",".","It","firstly","computes","Score-HLR","in","a","two-step","way",",","then","linearly","maps","score","hlr","to","the","loss","weights",".","Args",":","num","(","int",")",":","Total","number","of","sampled","RoIs",".","pos_fraction","(","float",")",":","Fraction","of","positive","samples",".","context","(",":","class",":","`","BaseRoIHead","`",")",":","RoI","head","that","the","sampler","belongs","to",".","neg_pos_ub","(","int",")",":","Upper","bound","of","the","ratio","of","num","negative","to","num","positive",",","-1","means","no","upper","bound",".","add_gt_as_proposals","(","bool",")",":","Whether","to","add","ground","truth","as","proposals",".","k","(","float",")",":","Power","of","the","non-linear","mapping",".","bias","(","float",")",":","Shift","of","the","non-linear","mapping",".","score_thr","(","float",")",":","Minimum","score","that","a","negative","sample","is","to","be","considered","as","valid","bbox","."]
docstr: Randomly select some elements from the gallery.
  
  If `gallery` is a Tensor, the returned indices will be a Tensor;
  If `gallery` is a ndarray or list, the returned indices will be a
  ndarray.
  
  Args:
      gallery (Tensor | ndarray | list): indices pool.
      num (int): expected sample num.
  
  Returns:
      Tensor or ndarray: sampled indices.
docstr_tok: ["Randomly","select","some","elements","from","the","gallery",".","If","`","gallery","`","is","a","Tensor",",","the","returned","indices","will","be","a","Tensor",";","If","`","gallery","`","is","a","ndarray","or","list",",","the","returned","indices","will","be","a","ndarray",".","Args",":","gallery","(","Tensor","|","ndarray","|","list",")",":","indices","pool",".","num","(","int",")",":","expected","sample","num",".","Returns",":","Tensor","or","ndarray",":","sampled","indices","."]
code: def random_choice(gallery, num):
      """Randomly select some elements from the gallery.
  
      If `gallery` is a Tensor, the returned indices will be a Tensor;
      If `gallery` is a ndarray or list, the returned indices will be a
      ndarray.
  
      Args:
          gallery (Tensor | ndarray | list): indices pool.
          num (int): expected sample num.
  
      Returns:
          Tensor or ndarray: sampled indices.
      """
      assert len(gallery) >= num
  
      is_tensor = isinstance(gallery, torch.Tensor)
      if not is_tensor:
          if torch.cuda.is_available():
              device = torch.cuda.current_device()
          else:
              device = "cpu"
          gallery = torch.tensor(
              gallery, dtype=torch.long, device=device
          )
      perm = torch.randperm(gallery.numel(), device=gallery.device)[
          :num
      ]
      rand_inds = gallery[perm]
      if not is_tensor:
          rand_inds = rand_inds.cpu().numpy()
      return rand_inds
  
file_path: insightface/detection/scrfd/mmdet/core/bbox/samplers/score_hlr_sampler.py
imports: import torch
  from mmcv.ops import nms_match
  from ..builder import BBOX_SAMPLERS
  from ..transforms import bbox2roi
  from .base_sampler import BaseSampler
  from .sampling_result import SamplingResult
label_desc: Use image node_id 2 for calling the ScoreHLRSampler obj's underlying member method code with example usage: obj.random_choice(gallery, num) and returns: rand_inds