class_docstr: RPNTarget: Get RPN's classification and regression targets.
  
  RPNTarget is responsible for:
    * calculating the correct values for both classification and regression
      problems.
    * defining which anchors and target values are going to be used for the
      RPN minibatch.
  
  For calculating the correct values for classification (ie. the question of
  "does this anchor refer to an object?") and returning an objectness score,
  we calculate the intersection over union (IoU) between the anchors boxes
  and the ground truth boxes, and use this to categorize anchors. When the
  intersection between anchors and groundtruth is above a threshold, we can
  mark the anchor as an object or as being foreground. In case of not having
  any intersection or having a low IoU value, then we say that the anchor
  refers to background.
  
  For calculating the correct values for the regression, the problem of
  transforming the fixed size anchor into a more suitable bounding box (equal
  to the ground truth box) only applies to the anchors that we consider to be
  foreground.
  
  RPNTarget is also responsible for selecting which of the anchors are going
  to be used for the minibatch. This is a random process with some
  restrictions on the ratio between foreground and background samples.
  
  For selecting the minibatch, labels are not only set to 0 or 1 (for the
  cases of being background and foreground respectively), but also to -1 for
  the anchors we just want to ignore and not include in the minibatch.
  
  In summary:
    * 1 is positive
        when GT overlap is >= 0.7 (configurable) or for GT max overlap (one
        anchor)
    * 0 is negative
        when GT overlap is < 0.3 (configurable)
    * -1 is don't care
        useful for subsampling negative labels
  
  Returns:
      labels: label for each anchor
      bbox_targets: bbox regresion values for each anchor
code: def __init__(
      self, num_anchors, config, seed=None, name="anchor_target"
  ):
      super(RPNTarget, self).__init__(name=name)
      self._num_anchors = num_anchors
  
      self._allowed_border = config.allowed_border
      # We set clobber positive to False to make sure that there is always at
      # least one positive anchor per GT box.
      self._clobber_positives = config.clobber_positives
      # We set anchors as positive when the IoU is greater than
      # `positive_overlap`.
      self._positive_overlap = config.foreground_threshold
      # We set anchors as negative when the IoU is less than
      # `negative_overlap`.
      self._negative_overlap = config.background_threshold_high
      # Fraction of the batch to be foreground labeled anchors.
      self._foreground_fraction = config.foreground_fraction
      self._minibatch_size = config.minibatch_size
  
      # When choosing random targets use `seed` to replicate behaviour.
      self._seed = seed
  
file_path: luminoth/luminoth/models/fasterrcnn/rpn_target.py
imports: import sonnet
  import tensorflow
  from luminoth.utils.bbox_overlap import bbox_overlap_tf
  from luminoth.utils.bbox_transform_tf import encode
label_desc: Use image node_id 1 to create a new RPNTarget object from inherited base classes: snt with example: obj = RPNTarget(num_anchors, config, seed, name)