code: def subsample_labels(
      labels, num_samples, fg_fraction, bg_label=0, use_random=True
  ):
      positive = paddle.nonzero(
          paddle.logical_and(labels != -1, labels != bg_label)
      )
      negative = paddle.nonzero(labels == bg_label)
  
      fg_num = int(num_samples * fg_fraction)
      fg_num = min(positive.numel(), fg_num)
      bg_num = num_samples - fg_num
      bg_num = min(negative.numel(), bg_num)
      if fg_num == 0 and bg_num == 0:
          fg_inds = paddle.zeros([0], dtype="int32")
          bg_inds = paddle.zeros([0], dtype="int32")
          return fg_inds, bg_inds
  
      # randomly select positive and negative examples
  
      negative = negative.cast("int32").flatten()
      bg_perm = paddle.randperm(negative.numel(), dtype="int32")
      bg_perm = paddle.slice(
          bg_perm, axes=[0], starts=[0], ends=[bg_num]
      )
      if use_random:
          bg_inds = paddle.gather(negative, bg_perm)
      else:
          bg_inds = paddle.slice(
              negative, axes=[0], starts=[0], ends=[bg_num]
          )
      if fg_num == 0:
          fg_inds = paddle.zeros([0], dtype="int32")
          return fg_inds, bg_inds
  
      positive = positive.cast("int32").flatten()
      fg_perm = paddle.randperm(positive.numel(), dtype="int32")
      fg_perm = paddle.slice(
          fg_perm, axes=[0], starts=[0], ends=[fg_num]
      )
      if use_random:
          fg_inds = paddle.gather(positive, fg_perm)
      else:
          fg_inds = paddle.slice(
              positive, axes=[0], starts=[0], ends=[fg_num]
          )
  
      return fg_inds, bg_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 3 for calling a global function with example usage: subsample_labels(labels, num_samples, fg_fraction, bg_label, use_random) and returns: fg_inds,  bg_inds, fg_inds,  bg_inds, fg_inds,  bg_inds