code: def test_anchor_target_layer():
      from utils.rpn.anchor_target_layer import (
          AnchorTargetLayer as CntkAnchorTargetLayer,
      )
      from utils.caffe_layers.anchor_target_layer import (
          AnchorTargetLayer as CaffeAnchorTargetLayer,
      )
  
      rpn_cls_score_shape_cntk = (1, 18, 61, 61)
      num_gt_boxes = 50
      gt_boxes_shape_cntk = (num_gt_boxes, 5)
      dims_info_shape = (6,)
      im_info = [1000, 1000, 1]
  
      # Create input tensors with values
      rpn_cls_score_dummy = np.random.random_sample(
          rpn_cls_score_shape_cntk
      ).astype(np.float32)
      dims_input = np.array(
          [1000, 1000, 1000, 1000, 1000, 1000]
      ).astype(np.float32)
  
      x1y1 = np.random.random_sample((num_gt_boxes, 2)) * 500
      wh = np.random.random_sample((num_gt_boxes, 2)) * 400
      x2y2 = x1y1 + wh + 50
      label = np.random.random_sample((num_gt_boxes, 1))
      label = label * 17.0
      gt_boxes = np.hstack((x1y1, x2y2, label)).astype(np.float32)
  
      # Create CNTK layer and call forward
      rpn_cls_score_var = input_variable(rpn_cls_score_shape_cntk)
      gt_boxes_var = input_variable(gt_boxes_shape_cntk)
      dims_info_var = input_variable(dims_info_shape)
  
      cntk_layer = user_function(
          CntkAnchorTargetLayer(
              rpn_cls_score_var,
              gt_boxes_var,
              dims_info_var,
              deterministic=True,
          )
      )
      state, cntk_output = cntk_layer.forward(
          {
              rpn_cls_score_var: [rpn_cls_score_dummy],
              gt_boxes_var: [gt_boxes],
              dims_info_var: dims_input,
          }
      )
  
      obj_key = [
          k for k in cntk_output if "objectness_target" in str(k)
      ][0]
      bbt_key = [k for k in cntk_output if "rpn_bbox_target" in str(k)][
          0
      ]
      bbw_key = [
          k for k in cntk_output if "rpn_bbox_inside_w" in str(k)
      ][0]
  
      cntk_objectness_target = cntk_output[obj_key][0]
      cntk_bbox_targets = cntk_output[bbt_key][0]
      cntk_bbox_inside_w = cntk_output[bbw_key][0]
  
      # Create Caffe layer and call forward
      bottom = [
          np.array(rpn_cls_score_dummy),
          np.array(gt_boxes),
          np.array(im_info),
      ]
      top = None  # handled through return statement in caffe layer for unit testing
  
      param_str = "'feat_stride': 16"
      caffe_layer = CaffeAnchorTargetLayer()
      caffe_layer.set_param_str(param_str)
      caffe_layer.setup(bottom, top)
      caffe_layer.set_deterministic_mode()
  
      (
          caffe_objectness_target,
          caffe_bbox_targets,
          caffe_bbox_inside_w,
      ) = caffe_layer.forward(bottom, top)
  
      # assert that results are exactly the same
      assert (
          cntk_objectness_target.shape == caffe_objectness_target.shape
      )
      assert cntk_bbox_targets.shape == caffe_bbox_targets.shape
      assert cntk_bbox_inside_w.shape == caffe_bbox_inside_w.shape
  
      assert np.allclose(
          cntk_objectness_target,
          caffe_objectness_target,
          rtol=0.0,
          atol=0.0,
      )
      assert np.allclose(
          cntk_bbox_targets, caffe_bbox_targets, rtol=0.0, atol=0.0
      )
      assert np.allclose(
          cntk_bbox_inside_w, caffe_bbox_inside_w, rtol=0.0, atol=0.0
      )
      print("Verified AnchorTargetLayer")
  
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 3 for calling a global function with example usage: test_anchor_target_layer() without return types