code: def extract_pred(g, topk=100, joint_preds=False):
      """extract prediction from prediction graph for validation and visualization"""
      if g is None or g.number_of_nodes() == 0:
          return None, None
  
      pred_class = g.ndata["node_class_pred"].asnumpy()
      pred_class_prob = g.ndata["node_class_logit"].asnumpy()
      pred_bbox = g.ndata["pred_bbox"][:, 0:4].asnumpy()
  
      pred_objects = np.vstack(
          [pred_class, pred_bbox.transpose(1, 0)]
      ).transpose(1, 0)
  
      score_pred = g.edata["score_pred"].asnumpy()
      score_phr = g.edata["score_phr"].asnumpy()
      score_pred_topk_eids = (-score_pred).argsort()[0:topk].tolist()
      score_phr_topk_eids = (-score_phr).argsort()[0:topk].tolist()
      topk_eids = sorted(
          list(set(score_pred_topk_eids + score_phr_topk_eids))
      )
  
      pred_rel_prob = g.edata["preds"][topk_eids].asnumpy()
      if joint_preds:
          pred_rel_class = pred_rel_prob[:, 1:].argmax(axis=1)
      else:
          pred_rel_class = pred_rel_prob.argmax(axis=1)
  
      pred_node_ids = g.find_edges(topk_eids)
      pred_node_sub = pred_node_ids[0].asnumpy()
      pred_node_ob = pred_node_ids[1].asnumpy()
  
      pred_sub_class = pred_class[pred_node_sub]
      pred_sub_class_prob = pred_class_prob[pred_node_sub]
      pred_sub_bbox = pred_bbox[pred_node_sub]
  
      pred_ob_class = pred_class[pred_node_ob]
      pred_ob_class_prob = pred_class_prob[pred_node_ob]
      pred_ob_bbox = pred_bbox[pred_node_ob]
  
      pred_triplets = np.vstack(
          [
              score_pred[topk_eids],
              score_phr[topk_eids],
              pred_rel_class,
              pred_sub_class,
              pred_ob_class,
              pred_sub_bbox.transpose(1, 0),
              pred_ob_bbox.transpose(1, 0),
          ]
      ).transpose(1, 0)
      return pred_objects, pred_triplets
  
imports: import logging
  import time
  from operator import attrgetter, itemgetter
  import dgl
  import mxnet
  import numpy
  from dgl.nn.mxnet import GraphConv
  from dgl.utils import toindex
  from gluoncv.data.batchify import Pad
  from gluoncv.model_zoo import get_model
  from mxnet import gluon, nd
  from mxnet.gluon import nn
label_desc: Use image node_id 5 for calling a global function with example usage: extract_pred(g, topk, joint_preds) and returns: pred_objects,  pred_triplets, None,  None