code: def libra_sample_pos(
      max_overlaps, max_classes, pos_inds, num_expected
  ):
      if len(pos_inds) <= num_expected:
          return pos_inds
      else:
          unique_gt_inds = np.unique(max_classes[pos_inds])
          num_gts = len(unique_gt_inds)
          num_per_gt = int(round(num_expected / float(num_gts)) + 1)
  
          sampled_inds = []
          for i in unique_gt_inds:
              inds = np.nonzero(max_classes == i)[0]
              before_len = len(inds)
              inds = list(set(inds) & set(pos_inds))
              after_len = len(inds)
              if len(inds) > num_per_gt:
                  inds = np.random.choice(
                      inds, size=num_per_gt, replace=False
                  )
              sampled_inds.extend(
                  list(inds)
              )  # combine as a new sampler
          if len(sampled_inds) < num_expected:
              num_extra = num_expected - len(sampled_inds)
              extra_inds = np.array(
                  list(set(pos_inds) - set(sampled_inds))
              )
              assert len(sampled_inds) + len(extra_inds) == len(
                  pos_inds
              ), "sum of sampled_inds({}) and extra_inds({}) length must be equal with pos_inds({})!".format(
                  len(sampled_inds), len(extra_inds), len(pos_inds)
              )
              if len(extra_inds) > num_extra:
                  extra_inds = np.random.choice(
                      extra_inds, size=num_extra, replace=False
                  )
              sampled_inds.extend(extra_inds.tolist())
          elif len(sampled_inds) > num_expected:
              sampled_inds = np.random.choice(
                  sampled_inds, size=num_expected, replace=False
              )
          return paddle.to_tensor(sampled_inds)
  
file_path: PaddleDetection/ppdet/modeling/proposal_generator/target.py
imports: import numpy
  import paddle
  from ..bbox_utils import bbox2delta, bbox_overlaps
label_desc: Use image node_id 9 for calling a global function with example usage: libra_sample_pos(max_overlaps, max_classes, pos_inds, num_expected) and returns: pos_inds, paddle