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: Sample positive and negative bboxes.
  
  This is a simple implementation of bbox sampling given candidates,
  assigning results and ground truth bboxes.
  
  Args:
      assign_result (:obj:`AssignResult`): Bbox assigning results.
      bboxes (Tensor): Boxes to be sampled from.
      gt_bboxes (Tensor): Ground truth bboxes.
      gt_labels (Tensor, optional): Class labels of ground truth bboxes.
  
  Returns:
      tuple[:obj:`SamplingResult`, Tensor]: Sampling result and negetive
          label weights.
docstr_tok: ["Sample","positive","and","negative","bboxes",".","This","is","a","simple","implementation","of","bbox","sampling","given","candidates",",","assigning","results","and","ground","truth","bboxes",".","Args",":","assign_result","(",":","obj",":","`","AssignResult","`",")",":","Bbox","assigning","results",".","bboxes","(","Tensor",")",":","Boxes","to","be","sampled","from",".","gt_bboxes","(","Tensor",")",":","Ground","truth","bboxes",".","gt_labels","(","Tensor",",","optional",")",":","Class","labels","of","ground","truth","bboxes",".","Returns",":","tuple","[",":","obj",":","`","SamplingResult","`",",","Tensor","]",":","Sampling","result","and","negetive","label","weights","."]
code: def sample(
      self,
      assign_result,
      bboxes,
      gt_bboxes,
      gt_labels=None,
      img_meta=None,
      **kwargs,
  ):
      """Sample positive and negative bboxes.
  
      This is a simple implementation of bbox sampling given candidates,
      assigning results and ground truth bboxes.
  
      Args:
          assign_result (:obj:`AssignResult`): Bbox assigning results.
          bboxes (Tensor): Boxes to be sampled from.
          gt_bboxes (Tensor): Ground truth bboxes.
          gt_labels (Tensor, optional): Class labels of ground truth bboxes.
  
      Returns:
          tuple[:obj:`SamplingResult`, Tensor]: Sampling result and negetive
              label weights.
      """
      bboxes = bboxes[:, :4]
  
      gt_flags = bboxes.new_zeros((bboxes.shape[0],), dtype=torch.uint8)
      if self.add_gt_as_proposals:
          bboxes = torch.cat([gt_bboxes, bboxes], dim=0)
          assign_result.add_gt_(gt_labels)
          gt_ones = bboxes.new_ones(
              gt_bboxes.shape[0], dtype=torch.uint8
          )
          gt_flags = torch.cat([gt_ones, gt_flags])
  
      num_expected_pos = int(self.num * self.pos_fraction)
      pos_inds = self.pos_sampler._sample_pos(
          assign_result, num_expected_pos, bboxes=bboxes, **kwargs
      )
      num_sampled_pos = pos_inds.numel()
      num_expected_neg = self.num - num_sampled_pos
      if self.neg_pos_ub >= 0:
          _pos = max(1, num_sampled_pos)
          neg_upper_bound = int(self.neg_pos_ub * _pos)
          if num_expected_neg > neg_upper_bound:
              num_expected_neg = neg_upper_bound
      neg_inds, neg_label_weights = self.neg_sampler._sample_neg(
          assign_result,
          num_expected_neg,
          bboxes,
          img_meta=img_meta,
          **kwargs,
      )
  
      return (
          SamplingResult(
              pos_inds,
              neg_inds,
              bboxes,
              gt_bboxes,
              assign_result,
              gt_flags,
          ),
          neg_label_weights,
      )
  
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 5 for calling the ScoreHLRSampler obj's underlying member method code with example usage: obj.sample(assign_result, bboxes, gt_bboxes, gt_labels, img_meta) and returns: SamplingResult,  neg_label_weights