code: def validate(net, val_data, ctx, eval_metric, size):
      """Test on validation dataset."""
      clipper = gcv.nn.bbox.BBoxClipToImage()
      eval_metric.reset()
      net.hybridize(static_alloc=True)
      with tqdm(total=size) as pbar:
          for ib, 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,
                  )
              pbar.update(len(ctx))
      return eval_metric.get()
  
imports: from __future__ import division
  from __future__ import print_function
  import os
  import argparse
  import glob
  import logging
  import time
  import numpy
  import mxnet
  from tqdm import tqdm
  from mxnet import nd
  from mxnet import gluon
  import gluoncv
  from gluoncv import data
  from gluoncv.data import batchify
  from gluoncv.data.transforms.presets.rcnn import FasterRCNNDefaultValTransform
  from gluoncv.utils.metrics.voc_detection import VOC07MApMetric
  from gluoncv.utils.metrics.coco_detection import COCODetectionMetric
label_desc: Use image node_id 5 for calling a global function with example usage: validate(net, val_data, ctx, eval_metric, size) and returns: eval_metric