class_docstr: Proposal layer takes as input:
  (1) output of RPN cls_score
  (2) output of RPN bbox regression
  
  Converts that to an output ROIs
  (5, num_ROIs) <- [image_idx, x_min, y_min, x_max, y_max]
  
  Steps:
  1. For each anchor, generate anchor boxes and apply bbox deltas to get
     bbox proposals
  2. Clip bboxes to image
  3. remove bbox with H < threshold or W < threshold
  4. set the scores to be -1 for the padded area
  5. Take top pre_nms_N scores
  6. apply NMS with a threshold
  7. return the top num_ROIs proposals
  8. provide ROIs
  9. compute bbox targets and store in target_buffers
class_docstr_tok: ["Proposal","layer","takes","as","input",":","(","1",")","output","of","RPN","cls_score","(","2",")","output","of","RPN","bbox","regression","Converts","that","to","an","output","ROIs","(","5",",","num_ROIs",")","<","-","[","image_idx",",","x_min",",","y_min",",","x_max",",","y_max","]","Steps",":","1",".","For","each","anchor",",","generate","anchor","boxes","and","apply","bbox","deltas","to","get","bbox","proposals","2",".","Clip","bboxes","to","image","3.","remove","bbox","with","H","<","threshold","or","W","<","threshold","4.","set","the","scores","to","be","-1","for","the","padded","area","5",".","Take","top","pre_nms_N","scores","6.","apply","NMS","with","a","threshold","7.","return","the","top","num_ROIs","proposals","8.","provide","ROIs","9.","compute","bbox","targets","and","store","in","target_buffers"]
docstr: Arguments:
      rpn_layers (list): References to the RPN layers: [RPN_1x1_obj, RPN_1x1_bbox]
      target_buffers (tuple): Target buffers for training fast-rcnn: (class, bbox regression)
      num_rois (int, optional): Number of ROIs to sample from proposed (default: 128)
      pre_nms_N (int, optional): Number of ROIs to retain before using NMS (default: 12000)
      post_nms_N (int, optional): Number of ROIs to retain after using NMS (default: 2000)
      nms_thresh (float, optional): Threshold for non-maximum supression (default: 0.7)
      min_bbox_size (integer, optional): Minimize bboxes side length (default: 16)
      name (string, optional): Name of layer (default: None)
docstr_tok: ["Arguments",":","rpn_layers","(","list",")",":","References","to","the","RPN","layers",":","[","RPN_1x1_obj",",","RPN_1x1_bbox","]","target_buffers","(","tuple",")",":","Target","buffers","for","training","fast-rcnn",":","(","class",",","bbox","regression",")","num_rois","(","int",",","optional",")",":","Number","of","ROIs","to","sample","from","proposed","(","default",":","128",")","pre_nms_N","(","int",",","optional",")",":","Number","of","ROIs","to","retain","before","using","NMS","(","default",":","12000",")","post_nms_N","(","int",",","optional",")",":","Number","of","ROIs","to","retain","after","using","NMS","(","default",":","2000",")","nms_thresh","(","float",",","optional",")",":","Threshold","for","non-maximum","supression","(","default",":","0.7",")","min_bbox_size","(","integer",",","optional",")",":","Minimize","bboxes","side","length","(","default",":","16",")","name","(","string",",","optional",")",":","Name","of","layer","(","default",":","None",")"]
code: def __init__(
      self,
      rpn_layers,
      dataloader,
      inference=False,
      num_rois=128,
      pre_nms_N=12000,
      post_nms_N=2000,
      nms_thresh=0.7,
      min_bbox_size=16,
      fg_fraction=None,
      fg_thresh=None,
      bg_thresh_hi=None,
      bg_thresh_lo=None,
      deterministic=False,
      name=None,
      debug=False,
  ):
      """
      Arguments:
          rpn_layers (list): References to the RPN layers: [RPN_1x1_obj, RPN_1x1_bbox]
          target_buffers (tuple): Target buffers for training fast-rcnn: (class, bbox regression)
          num_rois (int, optional): Number of ROIs to sample from proposed (default: 128)
          pre_nms_N (int, optional): Number of ROIs to retain before using NMS (default: 12000)
          post_nms_N (int, optional): Number of ROIs to retain after using NMS (default: 2000)
          nms_thresh (float, optional): Threshold for non-maximum supression (default: 0.7)
          min_bbox_size (integer, optional): Minimize bboxes side length (default: 16)
          name (string, optional): Name of layer (default: None)
      """
      super(ProposalLayer, self).__init__(name)
  
      self.rpn_obj, self.rpn_bbox = rpn_layers
      self.num_rois = num_rois
      self.pre_nms_N = pre_nms_N
      self.post_nms_N = post_nms_N
      self.nms_thresh = nms_thresh
      self.min_bbox_size = min_bbox_size
      self.num_classes = dataloader.num_classes
      self.fg_fraction = fg_fraction if fg_fraction else FG_FRACTION
      self.fg_thresh = fg_thresh if fg_thresh else FG_THRESH
      self.bg_thresh_hi = bg_thresh_hi if bg_thresh_hi else BG_THRESH_HI
      self.bg_thresh_lo = bg_thresh_lo if bg_thresh_lo else BG_THRESH_LO
      self.deterministic = deterministic
      self.debug = debug
  
      # the output shape of this layer depends on whether the network
      # will be used for inference. In inference mode, the output shape is
      # (5, post_nms_N). For training, a smaller set of rois are sampled, yielding
      # an output shape of (5, num_rois)
      self.inference = inference
  
      # set references to dataset object buffers
      self.dataloader = dataloader
      self._conv_height = dataloader.conv_height
      self._conv_width = dataloader.conv_width
      self._scale = dataloader.conv_scale
  
      # generate anchors and load onto device
      # self._anchors has shape (KHW, 4)
      self._anchors = generate_all_anchors(
          self._conv_height, self._conv_width, self._scale
      )
      self._dev_anchors = self.be.array(self._anchors)
      self._num_anchors = self._anchors.shape[0]
  
imports: from __future__ import division
  import numpy
  from neon.layers.layer import Layer
  from generate_anchors import generate_all_anchors
  from util import compute_targets, calculate_bb_overlap
label_desc: Use image node_id 1 to create a new ProposalLayer object from inherited base classes: Layer with example: obj = ProposalLayer(rpn_layers, dataloader, inference, num_rois, pre_nms_N, post_nms_N, nms_thresh, min_bbox_size, fg_fraction, fg_thresh, bg_thresh_hi, bg_thresh_lo, deterministic, name, debug)