code: def create_proposal_target_layer(rpn_rois, scaled_gt_boxes, cfg):
      """
      Creates a proposal target layer that is used for training an object detection network as proposed in the "Faster R-CNN" paper:
          Shaoqing Ren and Kaiming He and Ross Girshick and Jian Sun:
          "Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks"
  
      Assigns object detection proposals to ground-truth targets.
      Produces proposal classification labels and bounding-box regression targets.
      It also adds gt_boxes to candidates and samples fg and bg rois for training.
  
      Args:
          rpn_rois:        The proposed ROIs, e.g. from a region proposal network
          scaled_gt_boxes: The ground truth boxes as (x1, y1, x2, y2, label). Coordinates are absolute pixels wrt. the input image.
          num_classes:     The number of classes in the data set
  
      Returns:
          rpn_target_rois - a set of rois containing the ground truth and a number of sampled fg and bg ROIs
          label_targets - the target labels for the rois
          bbox_targets - the regression coefficient targets for the rois
          bbox_inside_weights - the weights for the regression loss
      """
  
      ptl_param_string = "'num_classes': {}".format(
          cfg["DATA"].NUM_CLASSES
      )
      ptl = user_function(
          ProposalTargetLayer(
              rpn_rois,
              scaled_gt_boxes,
              batch_size=cfg.NUM_ROI_PROPOSALS,
              fg_fraction=cfg["TRAIN"].FG_FRACTION,
              normalize_targets=cfg.BBOX_NORMALIZE_TARGETS,
              normalize_means=cfg.BBOX_NORMALIZE_MEANS,
              normalize_stds=cfg.BBOX_NORMALIZE_STDS,
              fg_thresh=cfg["TRAIN"].FG_THRESH,
              bg_thresh_hi=cfg["TRAIN"].BG_THRESH_HI,
              bg_thresh_lo=cfg["TRAIN"].BG_THRESH_LO,
              param_str=ptl_param_string,
          )
      )
  
      # use an alias if you need to access the outputs, e.g., when cloning a trained network
      rois = alias(ptl.outputs[0], name="rpn_target_rois")
      label_targets = ptl.outputs[1]
      bbox_targets = ptl.outputs[2]
      bbox_inside_weights = ptl.outputs[3]
  
      return rois, label_targets, bbox_targets, bbox_inside_weights
  
file_path: CNTK/Examples/Image/Detection/utils/rpn/rpn_helpers.py
imports: import numpy
  import cntk
  from cntk import reduce_sum, ops
  from cntk import user_function, relu, softmax, slice, splice, reshape, element_times, plus, minus, alias, classification_error
  from cntk.initializer import glorot_uniform, normal
  from cntk.layers import Convolution
  from cntk.losses import cross_entropy_with_softmax
  from utils.rpn.anchor_target_layer import AnchorTargetLayer
  from utils.rpn.proposal_layer import ProposalLayer
  from utils.rpn.proposal_target_layer import ProposalTargetLayer
  from utils.rpn.cntk_smoothL1_loss import SmoothL1Loss
label_desc: Use image node_id 3 for calling a global function with example usage: create_proposal_target_layer(rpn_rois, scaled_gt_boxes, cfg) and returns: rois,  label_targets,  bbox_targets,  bbox_inside_weights