code: def validate(net, val_data, ctx, eval_metric):
      """Test on validation dataset."""
      eval_metric.reset()
      # set nms threshold and topk constraint
      net.set_nms(nms_thresh=0.45, nms_topk=400)
      mx.nd.waitall()
      net.hybridize()
      for batch in val_data:
          data = gluon.utils.split_and_load(
              batch[0], ctx_list=ctx, batch_axis=0, even_split=False
          )
          label = gluon.utils.split_and_load(
              batch[1], ctx_list=ctx, batch_axis=0, even_split=False
          )
          det_bboxes = []
          det_ids = []
          det_scores = []
          gt_bboxes = []
          gt_ids = []
          gt_difficults = []
          for x, y in zip(data, label):
              # get prediction results
              ids, scores, bboxes = net(x)
              det_ids.append(ids)
              det_scores.append(scores)
              # clip to image size
              det_bboxes.append(bboxes.clip(0, batch[0].shape[2]))
              # 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_difficults.append(
                  y.slice_axis(axis=-1, begin=5, end=6)
                  if y.shape[-1] > 5
                  else None
              )
  
          # update metric
          eval_metric.update(
              det_bboxes,
              det_ids,
              det_scores,
              gt_bboxes,
              gt_ids,
              gt_difficults,
          )
      return eval_metric.get()
  
imports: import argparse
  import os
  import logging
  import time
  import warnings
  import numpy
  import mxnet
  from mxnet import nd
  from mxnet import gluon
  from mxnet import autograd
  import gluoncv
  from gluoncv import data
  from gluoncv import utils
  from gluoncv.model_zoo import get_model
  from gluoncv.data.batchify import Tuple, Stack, Pad
  from gluoncv.data.transforms.presets.yolo import YOLO3DefaultTrainTransform
  from gluoncv.data.transforms.presets.yolo import YOLO3DefaultValTransform
  from gluoncv.data.dataloader import RandomTransformDataLoader
  from gluoncv.utils.metrics.voc_detection import VOC07MApMetric
  from gluoncv.utils.metrics.coco_detection import COCODetectionMetric
  from gluoncv.utils import LRScheduler, LRSequential
  from mxnet.contrib import amp
label_desc: Use image node_id 5 for calling a global function with example usage: validate(net, val_data, ctx, eval_metric) and returns: eval_metric