code: def validate(
      net,
      val_data,
      async_eval_processes,
      ctx,
      eval_metric,
      logger,
      epoch,
      best_map,
      args,
  ):
      """Test on validation dataset."""
      clipper = gcv.nn.bbox.BBoxClipToImage()
      eval_metric.reset()
      if not args.disable_hybridization:
          net.hybridize(static_alloc=args.static_alloc)
      tic = time.time()
      for ib, batch in enumerate(val_data):
          batch = split_and_load(batch, ctx_list=ctx)
          det_bboxes = []
          det_ids = []
          det_scores = []
          det_masks = []
          det_infos = []
          for x, im_info in zip(*batch):
              # get prediction results
              ids, scores, bboxes, masks = net(x)
              det_bboxes.append(clipper(bboxes, x))
              det_ids.append(ids)
              det_scores.append(scores)
              det_masks.append(masks)
              det_infos.append(im_info)
          # update metric
          for det_bbox, det_id, det_score, det_mask, det_info in zip(
              det_bboxes, det_ids, det_scores, det_masks, det_infos
          ):
              for i in range(det_info.shape[0]):
                  # numpy everything
                  det_bbox = det_bbox[i].asnumpy()
                  det_id = det_id[i].asnumpy()
                  det_score = det_score[i].asnumpy()
                  det_mask = det_mask[i].asnumpy()
                  det_info = det_info[i].asnumpy()
                  # filter by conf threshold
                  im_height, im_width, im_scale = det_info
                  valid = np.where(
                      ((det_id >= 0) & (det_score >= 0.001))
                  )[0]
                  det_id = det_id[valid]
                  det_score = det_score[valid]
                  det_bbox = det_bbox[valid] / im_scale
                  det_mask = det_mask[valid]
                  # fill full mask
                  im_height, im_width = int(
                      round(im_height / im_scale)
                  ), int(round(im_width / im_scale))
                  full_masks = gdata.transforms.mask.fill(
                      det_mask, det_bbox, (im_width, im_height)
                  )
                  eval_metric.update(
                      det_bbox, det_id, det_score, full_masks
                  )
      if args.horovod and MPI is not None:
          comm = MPI.COMM_WORLD
          res = comm.gather(eval_metric.get_result_buffer(), root=0)
          if hvd.rank() == 0:
              logger.info(
                  "[Epoch {}] Validation Inference cost: {:.3f}".format(
                      epoch, (time.time() - tic)
                  )
              )
              rank0_res = eval_metric.get_result_buffer()
              if len(rank0_res) == 2:
                  res = res[1:]
                  rank0_res[0].extend(
                      [
                          item
                          for res_tuple in res
                          for item in res_tuple[0]
                      ]
                  )
                  rank0_res[1].extend(
                      [
                          item
                          for res_tuple in res
                          for item in res_tuple[1]
                      ]
                  )
              else:
                  rank0_res.extend([item for r in res for item in r])
  
      def coco_eval_save_task(eval_metric, logger):
          map_name, mean_ap = eval_metric.get()
          if map_name and mean_ap is not None:
              val_msg = "\n".join(
                  [
                      "{}={}".format(k, v)
                      for k, v in zip(map_name, mean_ap)
                  ]
              )
              logger.info(
                  "[Epoch {}] Validation: \n{}".format(epoch, val_msg)
              )
              current_map = float(mean_ap[-1])
              save_params(
                  net,
                  logger,
                  best_map,
                  current_map,
                  epoch,
                  args.save_interval,
                  args.save_prefix,
              )
  
      if not args.horovod or hvd.rank() == 0:
          p = Process(
              target=coco_eval_save_task, args=(eval_metric, logger)
          )
          async_eval_processes.append(p)
          p.start()
  
imports: import argparse
  import os
  import logging
  import time
  import numpy
  import mxnet
  from mxnet import gluon
  from mxnet.contrib import amp
  from distutils.version import LooseVersion
  import gluoncv
  from gluoncv import data
  from gluoncv import utils
  from gluoncv.model_zoo import get_model
  from gluoncv.data import batchify
  from gluoncv.data.transforms.presets.rcnn import MaskRCNNDefaultTrainTransform, MaskRCNNDefaultValTransform
  from gluoncv.utils.metrics.coco_instance import COCOInstanceMetric
  from gluoncv.utils.metrics.rcnn import RPNAccMetric, RPNL1LossMetric, RCNNAccMetric, RCNNL1LossMetric, MaskAccMetric, MaskFGAccMetric
  from gluoncv.utils.parallel import Parallel
  from gluoncv.data import COCODetection, VOCDetection
  from multiprocessing import Process
  from gluoncv.model_zoo.rcnn.mask_rcnn.data_parallel import ForwardBackwardTask
label_desc: Use image node_id 7 for calling a global function with example usage: validate(net, val_data, async_eval_processes, ctx, eval_metric, logger, epoch, best_map, args) without return types