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 = []
              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 = gcv.data.transforms.mask.fill(
                          det_mask,
                          det_bbox,
                          (im_width, im_height),
                          fast_fill=False,
                      )
                      eval_metric.update(
                          det_bbox, det_id, det_score, full_masks
                      )
              pbar.update(len(ctx))
      return eval_metric.get()
  
file_path: gluon-cv/scripts/instance/mask_rcnn/eval_mask_rcnn.py
imports: from __future__ import division
  import os
  import argparse
  import glob
  import logging
  import numpy
  import mxnet
  from tqdm import tqdm
  import gluoncv
  from gluoncv import data
  from gluoncv.data import batchify
  from gluoncv.data.transforms.presets.rcnn import MaskRCNNDefaultValTransform
  from gluoncv.utils.metrics.coco_instance import COCOInstanceMetric
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