code: def test_proposal_layer():
      from utils.rpn.proposal_layer import (
          ProposalLayer as CntkProposalLayer,
      )
      from utils.caffe_layers.proposal_layer import (
          ProposalLayer as CaffeProposalLayer,
      )
      from FasterRCNN.FasterRCNN_config import cfg
  
      cls_prob_shape_cntk = (18, 61, 61)
      cls_prob_shape_caffe = (18, 61, 61)
      rpn_bbox_shape = (36, 61, 61)
      dims_info_shape = (6,)
      im_info = [1000, 1000, 1]
  
      # Create input tensors with values
      cls_prob = np.random.random_sample(cls_prob_shape_cntk).astype(
          np.float32
      )
      rpn_bbox_pred = np.random.random_sample(rpn_bbox_shape).astype(
          np.float32
      )
      dims_input = np.array(
          [1000, 1000, 1000, 1000, 1000, 1000]
      ).astype(np.float32)
  
      # Create CNTK layer and call forward
      cls_prob_var = input_variable(cls_prob_shape_cntk)
      rpn_bbox_var = input_variable(rpn_bbox_shape)
      dims_info_var = input_variable(dims_info_shape)
  
      layer_config = {}
      layer_config["feat_stride"] = 16
      layer_config["scales"] = [8, 16, 32]
  
      layer_config["train_pre_nms_topN"] = cfg[
          "TRAIN"
      ].RPN_PRE_NMS_TOP_N
      layer_config["train_post_nms_topN"] = cfg[
          "TRAIN"
      ].RPN_POST_NMS_TOP_N
      layer_config["train_nms_thresh"] = float(
          cfg["TRAIN"].RPN_NMS_THRESH
      )
      layer_config["train_min_size"] = float(cfg["TRAIN"].RPN_MIN_SIZE)
  
      layer_config["test_pre_nms_topN"] = cfg["TEST"].RPN_PRE_NMS_TOP_N
      layer_config["test_post_nms_topN"] = cfg[
          "TEST"
      ].RPN_POST_NMS_TOP_N
      layer_config["test_nms_thresh"] = float(
          cfg["TEST"].RPN_NMS_THRESH
      )
      layer_config["test_min_size"] = float(cfg["TEST"].RPN_MIN_SIZE)
  
      cntk_layer = user_function(
          CntkProposalLayer(
              cls_prob_var, rpn_bbox_var, dims_info_var, layer_config
          )
      )
      state, cntk_output = cntk_layer.forward(
          {
              cls_prob_var: [cls_prob],
              rpn_bbox_var: [rpn_bbox_pred],
              dims_info_var: dims_input,
          }
      )
      cntk_proposals = cntk_output[next(iter(cntk_output))][0]
  
      # Create Caffe layer and call forward
      cls_prob_caffe = cls_prob.reshape(cls_prob_shape_caffe)
      bottom = [
          np.array([cls_prob_caffe]),
          np.array([rpn_bbox_pred]),
          np.array([im_info]),
      ]
      top = None  # handled through return statement in caffe layer for unit testing
  
      param_str = "'feat_stride': 16"
      caffe_layer = CaffeProposalLayer()
      caffe_layer.set_param_str(param_str)
      caffe_layer.setup(bottom, top)
      caffe_output = caffe_layer.forward(bottom, top)
      caffe_proposals = caffe_output[:, 1:]
  
      # assert that results are exactly the same
      assert cntk_proposals.shape == caffe_proposals.shape
      assert np.allclose(
          cntk_proposals, caffe_proposals, rtol=0.0, atol=0.0
      )
      print("Verified ProposalLayer")
  
file_path: CNTK/Tests/EndToEndTests/CNTKv2Python/Examples/rpn_unit_test.py
imports: import os, sys
  import pytest
  import numpy
  from cntk import user_function
  from cntk.ops import input_variable
  from test_decorators import run_if_win35_linux35_linux36
label_desc: Use image node_id 1 for calling a global function with example usage: test_proposal_layer() without return types