code: def reference_test(dataloader, X, Y):
      bbtargets_mask = Y[1][1]
  
      target = AnchorTargetLayer()
      im_shape = dataloader.im_shape.get()
      im_scale = dataloader.im_scale.get()[0][0]
      num_gt_boxes = dataloader.num_gt_boxes.get()[0][0]
  
      # prepare inputs
      bottom = [0, 1, 2]
  
      bottom[0] = np.zeros(
          (dataloader.conv_height, dataloader.conv_width)
      )
      bottom[1] = dataloader.gt_boxes.get()[:num_gt_boxes]
      bottom[2] = [im_shape[0], im_shape[1], im_scale]
  
      # obtain forward pass output
      top = [0, 1, 2, 3]
      target.setup(bottom, top)
      target.forward(bottom, top)
      py_labels, py_bbtargets, py_iw, py_ow = top
  
      label = bbtargets_mask.get().reshape((4, -1))[0, :]
  
      # positive labels should match
      if np.sum(label == 1) < 128:
          # assert positive labels match since positives (usually) dont get under sampled
          assert np.allclose(
              np.where(label == 1)[0],
              np.where(py_labels.flatten() == 1)[0],
          )
  
          # our bboxes are in 4 * K, whereas reference is in K * 4 order, so reshape
          bb = Y[1][0].get() * Y[1][1].get()
  
          pybb = py_bbtargets * py_iw
          pybb = pybb.reshape(
              (1, 9, 4, dataloader.conv_height, dataloader.conv_width)
          ).transpose(0, 2, 1, 3, 4)
          pybb = pybb.reshape(
              1, 36, dataloader.conv_height, dataloader.conv_width
          ).flatten()
          # bounding box target locations and values must match
          assert np.allclose(
              np.where(bb != 0)[0], np.where(pybb != 0)[0], atol=0.001
          )
          assert np.allclose(
              bb[np.where(bb != 0)],
              pybb[np.where(pybb != 0)],
              atol=0.001,
          )
  
file_path: neon/examples/faster-rcnn/tests/test_anchor_target_layer.py
imports: from __future__ import division
  import numpy
  from neon.backends import gen_backend
  import itertools
  from anchor_target_layer_ref import AnchorTargetLayer
  from objectlocalization import ObjectLocalization, PASCALVOC
  from neon.data.dataloader_transformers import TypeCast
  from aeon import DataLoader
  import os
label_desc: Use image node_id 3 for calling a global function with example usage: reference_test(dataloader, X, Y) without return types