code: def validate(net, val_data, ctx, eval_metric, args):
      """Test on validation dataset."""
      clipper = gcv.nn.bbox.BBoxClipToImage()
      eval_metric.reset()
      if not args.disable_hybridization:
          # input format is differnet than training, thus rehybridization is needed.
          net.hybridize(static_alloc=args.static_alloc)
      for i, batch in enumerate(val_data):
          batch = split_and_load(batch, ctx_list=ctx)
          det_bboxes = []
          det_ids = []
          det_scores = []
          gt_bboxes = []
          gt_ids = []
          gt_difficults = []
          for x, y, im_scale in zip(*batch):
              # get prediction results
              ids, scores, bboxes = net(x)
              det_ids.append(ids)
              det_scores.append(scores)
              # clip to image size
              det_bboxes.append(clipper(bboxes, x))
              # rescale to original resolution
              im_scale = im_scale.reshape((-1)).asscalar()
              det_bboxes[-1] *= im_scale
              # split ground truths
              gt_ids.append(y.slice_axis(axis=-1, begin=4, end=5))
              gt_bboxes.append(y.slice_axis(axis=-1, begin=0, end=4))
              gt_bboxes[-1] *= im_scale
              gt_difficults.append(
                  y.slice_axis(axis=-1, begin=5, end=6)
                  if y.shape[-1] > 5
                  else None
              )
  
          # update metric
          for (
              det_bbox,
              det_id,
              det_score,
              gt_bbox,
              gt_id,
              gt_diff,
          ) in zip(
              det_bboxes,
              det_ids,
              det_scores,
              gt_bboxes,
              gt_ids,
              gt_difficults,
          ):
              eval_metric.update(
                  det_bbox, det_id, det_score, gt_bbox, gt_id, gt_diff
              )
      return eval_metric.get()
  
imports: import argparse
  import os
  import logging
  import time
  import gluoncv
  import mxnet
  import numpy
  from data import *
  from gluoncv import data, utils
  from gluoncv.data.batchify import Append, FasterRCNNTrainBatchify, Tuple
  from gluoncv.data.transforms.presets.rcnn import FasterRCNNDefaultTrainTransform, FasterRCNNDefaultValTransform
  from gluoncv.model_zoo import get_model
  from gluoncv.utils.metrics.coco_detection import COCODetectionMetric
  from gluoncv.utils.metrics.rcnn import RCNNAccMetric, RCNNL1LossMetric, RPNAccMetric, RPNL1LossMetric
  from gluoncv.utils.metrics.voc_detection import VOC07MApMetric
  from gluoncv.utils.parallel import Parallel, Parallelizable
  from model import faster_rcnn_resnet101_v1d_custom, faster_rcnn_resnet50_v1b_custom
  from mxnet import autograd, gluon
  from mxnet.contrib import amp
label_desc: Use image node_id 6 for calling a global function with example usage: validate(net, val_data, ctx, eval_metric, args) and returns: eval_metric