class_docstr: RPN target generator network.
  
  Parameters
  ----------
  num_sample : int, default is 256
      Number of samples for RPN targets.
  pos_iou_thresh : float, default is 0.7
      Anchor with IOU larger than ``pos_iou_thresh`` is regarded as positive samples.
  neg_iou_thresh : float, default is 0.3
      Anchor with IOU smaller than ``neg_iou_thresh`` is regarded as negative samples.
      Anchors with IOU in between ``pos_iou_thresh`` and ``neg_iou_thresh`` are
      ignored.
  pos_ratio : float, default is 0.5
      ``pos_ratio`` defines how many positive samples (``pos_ratio * num_sample``) is
      to be sampled.
  stds : array-like of size 4, default is (1., 1., 1., 1.)
      Std value to be divided from encoded regression targets.
  allowed_border : int or float, default is 0
      The allowed distance of anchors which are off the image border. This is used to clip out of
      border anchors. You can set it to very large value to keep all anchors.
docstr: RPNTargetGenerator is only used in data transform with no batch dimension.
  Be careful there's numpy operations inside
  
  Parameters
  ----------
  bbox: (M, 4) ground truth boxes with corner encoding.
  anchor: (N, 4) anchor boxes with corner encoding.
  width: int width of input image
  height: int height of input image
  
  Returns
  -------
  cls_target: (N,) value +1: pos, 0: neg, -1: ignore
  box_target: (N, 4) only anchors whose cls_target > 0 has nonzero box target
  box_mask: (N, 4) only anchors whose cls_target > 0 has nonzero mask
docstr_tok: ["RPNTargetGenerator","is","only","used","in","data","transform","with","no","batch","dimension",".","Be","careful","there","'s","numpy","operations","inside","Parameters","--","--","--","--","--","bbox",":","(","M",",","4",")","ground","truth","boxes","with","corner","encoding",".","anchor",":","(","N",",","4",")","anchor","boxes","with","corner","encoding",".","width",":","int","width","of","input","image","height",":","int","height","of","input","image","Returns","--","--","--","-","cls_target",":","(","N",",",")","value","+1",":","pos",",","0",":","neg",",","-1",":","ignore","box_target",":","(","N",",","4",")","only","anchors","whose","cls_target",">","0","has","nonzero","box","target","box_mask",":","(","N",",","4",")","only","anchors","whose","cls_target",">","0","has","nonzero","mask"]
code: def forward(self, bbox, anchor, width, height):
      """
      RPNTargetGenerator is only used in data transform with no batch dimension.
      Be careful there's numpy operations inside
  
      Parameters
      ----------
      bbox: (M, 4) ground truth boxes with corner encoding.
      anchor: (N, 4) anchor boxes with corner encoding.
      width: int width of input image
      height: int height of input image
  
      Returns
      -------
      cls_target: (N,) value +1: pos, 0: neg, -1: ignore
      box_target: (N, 4) only anchors whose cls_target > 0 has nonzero box target
      box_mask: (N, 4) only anchors whose cls_target > 0 has nonzero mask
  
      """
      with autograd.pause():
          # calculate ious between (N, 4) anchors and (M, 4) bbox ground-truths
          # ious is (N, M)
          ious = mx.nd.contrib.box_iou(
              anchor, bbox, format="corner"
          ).asnumpy()
  
          # mask out invalid anchors, (N, 4)
          a_xmin, a_ymin, a_xmax, a_ymax = mx.nd.split(
              anchor, 4, axis=-1
          )
          invalid_mask = (
              (a_xmin < 0)
              + (a_ymin < 0)
              + (a_xmax >= width)
              + (a_ymax >= height)
          )
          ious = np.where(invalid_mask.asnumpy(), -1.0, ious)
          samples, matches = self._sampler(ious)
  
          # training targets for RPN
          cls_target, _ = self._cls_encoder(samples)
          box_target, box_mask = self._box_encoder(
              np.expand_dims(samples, axis=0),
              np.expand_dims(matches, axis=0),
              np.expand_dims(anchor.asnumpy(), axis=0),
              np.expand_dims(bbox.asnumpy(), axis=0),
          )
      return cls_target, box_target[0], box_mask[0]
  
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 RPNTargetGenerator obj's underlying member method code with example usage: obj.forward(bbox, anchor, width, height) and returns: cls_target,  box_target,  box_mask