code: def build_graph_validate_gt_bbox(
      img,
      ids,
      scores,
      bbox,
      spatial_feat,
      gt_ids=None,
      bbox_improvement=True,
      overlap=False,
  ):
      """given ground truth bbox, build graph for validation"""
      n_batch = img.shape[0]
      img_size = img.shape[2:4]
      bbox[:, :, 0] /= img_size[1]
      bbox[:, :, 1] /= img_size[0]
      bbox[:, :, 2] /= img_size[1]
      bbox[:, :, 3] /= img_size[0]
      ctx = img.context
  
      g_batch = []
      for btc in range(n_batch):
          id_btc = scores[btc][:, :, 0].argmax(0)
          score_btc = scores[btc][:, :, 0].max(0)
          inds = np.where(bbox[btc].sum(1).asnumpy() > 0)[0].tolist()
          if len(inds) == 0:
              continue
          n_nodes = len(inds)
          g_pred = dgl.DGLGraph()
          g_pred.add_nodes(
              n_nodes,
              {
                  "pred_bbox": bbox[btc, inds],
                  "node_feat": spatial_feat[btc, inds],
                  "node_class_pred": id_btc,
                  "node_class_logit": nd.log(score_btc + 1e-7),
              },
          )
  
          edge_list = []
          for i in range(n_nodes - 1):
              for j in range(i + 1, n_nodes):
                  edge_list.append((i, j))
          src, dst = tuple(zip(*edge_list))
          g_pred.add_edges(src, dst)
          g_pred.add_edges(dst, src)
  
          n_nodes = g_pred.number_of_nodes()
          n_edges = g_pred.number_of_edges()
          if bbox_improvement:
              g_pred.ndata["pred_bbox"] = bbox_improve(
                  g_pred.ndata["pred_bbox"]
              )
          g_pred.edata["rel_bbox"] = extract_edge_bbox(g_pred)
          g_pred.edata["batch_id"] = (
              nd.zeros((n_edges, 1), ctx=ctx) + btc
          )
  
          g_batch.append(g_pred)
  
      if len(g_batch) == 0:
          return None
      if len(g_batch) > 1:
          return dgl.batch(g_batch)
      return g_batch[0]
  
file_path: dgl/examples/mxnet/scenegraph/utils/build_graph.py
imports: import dgl
  import numpy
  from mxnet import nd
label_desc: Use image node_id 5 for calling a global function with example usage: build_graph_validate_gt_bbox(img, ids, scores, bbox, spatial_feat, gt_ids, bbox_improvement, overlap) and returns: g_batch, None, dgl