code: def to_official(args, preds, features):
      rel2id = json.load(open(f"{args.data_dir}/rel2id.json", "r"))
      id2rel = {value: key for key, value in rel2id.items()}
  
      h_idx, t_idx, title = [], [], []
  
      for f in features:
          hts = f["hts"]
          h_idx += [ht[0] for ht in hts]
          t_idx += [ht[1] for ht in hts]
          title += [f["title"] for ht in hts]
  
      res = []
      # print('h_idx, preds', len(h_idx), len(preds))
      # assert len(h_idx) == len(preds)
  
      for i in range(preds.shape[0]):
          pred = preds[i]
          pred = np.nonzero(pred)[0].tolist()
          for p in pred:
              if p != 0:
                  res.append(
                      {
                          "title": title[i],
                          "h_idx": h_idx[i],
                          "t_idx": t_idx[i],
                          "r": id2rel[p],
                      }
                  )
      return res
  
imports: import os
  import os.path
  import json
  import numpy
label_desc: Use image node_id 1 for calling a global function with example usage: to_official(args, preds, features) and returns: res