class_docstr: A sampler to choose positive/negative samples from RPN anchors
  
  Parameters
  ----------
  num_sample : int
      Number of samples for RPN targets.
  pos_iou_thresh : float
      Proposal whose IOU larger than ``pos_iou_thresh`` is regarded as positive samples.
  neg_iou_thresh : float
      Proposal whose IOU smaller than ``neg_iou_thresh`` is regarded as negative samples.
  pos_ratio : float
      ``pos_ratio`` defines how many positive samples (``pos_ratio * num_sample``) is
      to be sampled.
docstr: RPNTargetSampler is only used in data transform with no batch dimension.
  
  Parameters
  ----------
  ious: (N, M) i.e. (num_anchors, num_gt).
  
  Returns
  -------
  samples: (num_anchors,) value 1: pos, -1: neg, 0: ignore.
  matches: (num_anchors,) value [0, M).
docstr_tok: ["RPNTargetSampler","is","only","used","in","data","transform","with","no","batch","dimension",".","Parameters","--","--","--","--","--","ious",":","(","N",",","M",")","i.e",".","(","num_anchors",",","num_gt",")",".","Returns","--","--","--","-","samples",":","(","num_anchors",",",")","value","1",":","pos",",","-1",":","neg",",","0",":","ignore",".","matches",":","(","num_anchors",",",")","value","[","0",",","M",")","."]
code: def __call__(self, ious):
      """RPNTargetSampler is only used in data transform with no batch dimension.
  
      Parameters
      ----------
      ious: (N, M) i.e. (num_anchors, num_gt).
  
      Returns
      -------
      samples: (num_anchors,) value 1: pos, -1: neg, 0: ignore.
      matches: (num_anchors,) value [0, M).
  
      """
      if cython_rpn_target is not None:
          return cython_rpn_target.sampler(
              ious,
              self._pos_iou_thresh,
              self._neg_iou_thresh,
              self._num_sample,
              self._max_pos,
              self._eps,
          )
      matches = np.argmax(ious, axis=1)
  
      # samples init with 0 (ignore)
      ious_max_per_anchor = np.max(ious, axis=1)
      samples = np.zeros_like(ious_max_per_anchor)
  
      # set argmax (1, num_gt)
      ious_max_per_gt = np.max(ious, axis=0, keepdims=True)
      # ious (num_anchor, num_gt) >= argmax (1, num_gt) -> mark row as positive
      mask = (ious + self._eps) > ious_max_per_gt
      # reduce column (num_anchor, num_gt) -> (num_anchor)
      mask = np.sum(mask, axis=1)
      # row maybe sampled by 2 columns but still only matches to most overlapping gt
      samples = np.where(mask, 1.0, samples)
  
      # set positive overlap to 1
      samples = np.where(
          ious_max_per_anchor >= self._pos_iou_thresh, 1.0, samples
      )
      # set negative overlap to -1
      tmp = (ious_max_per_anchor < self._neg_iou_thresh) * (
          ious_max_per_anchor >= 0
      )
      samples = np.where(tmp, -1.0, samples)
  
      # subsample fg labels
      num_pos = int((samples > 0).sum())
      if num_pos > self._max_pos:
          disable_indices = np.random.choice(
              np.where(samples > 0)[0],
              size=(num_pos - self._max_pos),
              replace=False,
          )
          samples[disable_indices] = 0  # use 0 to ignore
  
      # subsample bg labels
      num_neg = int((samples < 0).sum())
      # if pos_sample is less than quota, we can have negative samples filling the gap
      max_neg = self._num_sample - min(num_pos, self._max_pos)
      if num_neg > max_neg:
          disable_indices = np.random.choice(
              np.where(samples < 0)[0],
              size=(num_neg - max_neg),
              replace=False,
          )
          samples[disable_indices] = 0
      return samples, matches
  
file_path: gluon-cv/gluoncv/model_zoo/rcnn/rpn/rpn_target.py
imports: from __future__ import absolute_import
  import numpy
  import mxnet
  from mxnet import autograd, gluon
  from ....nn.bbox import BBoxSplit
  from ....nn.coder import SigmoidClassEncoder, NumPyNormalizedBoxCenterEncoder
label_desc: Use image node_id 2 for calling the RPNTargetSampler obj's underlying member method code with example usage: obj.__call__(ious) and returns: samples,  matches, cython_rpn_target