code: def get_annotations(data_dir, data_name, ids):
      assert COCO is not None, "`datasets.coco` requires `pycocotools`."
      if data_name not in metas:
          metas[data_name] = COCO(
              "%s/annotations/instances_%s.json" % (data_dir, data_name)
          )
      cmap = dict(
          [(b, a) for (a, b) in enumerate(metas[data_name].getCatIds())]
      )
      annotations = {}
      for i in ids:
          annids = metas[data_name].getAnnIds(imgIds=i, iscrowd=None)
          objs = metas[data_name].loadAnns(annids)
          annotations[i] = [[] for _ in range(80)]
          width = metas[data_name].imgs[i]["width"]
          height = metas[data_name].imgs[i]["height"]
          valid_objs = []
          for obj in objs:
              x1 = np.max((0, obj["bbox"][0]))
              y1 = np.max((0, obj["bbox"][1]))
              x2 = np.min(
                  (width - 1, x1 + np.max((0, obj["bbox"][2] - 1)))
              )
              y2 = np.min(
                  (height - 1, y1 + np.max((0, obj["bbox"][3] - 1)))
              )
              if obj["area"] > 0 and x2 >= x1 and y2 >= y1:
                  obj_struct = {"bbox": [x1, y1, x2, y2]}
                  cidx = cmap[obj["category_id"]]
                  annotations[i][cidx].append(obj_struct)
      return annotations
  
file_path: tensornets/tensornets/datasets/coco.py
imports: from __future__ import division
  import os
  import json
  import numpy
label_desc: Use image node_id 4 for calling a global function with example usage: get_annotations(data_dir, data_name, ids) and returns: annotations