code: def createIndex(self):
      # create index
      print("creating index...")
      anns, cats, imgs = {}, {}, {}
      imgNameToId, imgToAnns, catToImgs, imgNameToId = [
          defaultdict(list) for _ in range(4)
      ]
      if "annotations" in self.dataset:
          for ann in self.dataset["annotations"]:
              imgToAnns[ann["image_id"]].append(ann)
              anns[ann["id"]] = ann
              self.maxAnnId = max(self.maxAnnId, ann["id"])
  
      if "images" in self.dataset:
          for img in self.dataset["images"]:
              imgs[img["id"]] = img
              imgNameToId[img["file_name"]] = img["id"]
              try:
                  imgId = int(img["id"])
                  self.maxImgId = max(self.maxImgId, imgId)
              except:
                  pass
  
      if "categories" in self.dataset:
          for cat in self.dataset["categories"]:
              cats[cat["id"]] = cat
  
      if "annotations" in self.dataset and "categories" in self.dataset:
          for ann in self.dataset["annotations"]:
              catToImgs[ann["category_id"]].append(ann["image_id"])
      # TODO: read license
      print("index created!")
  
      self.anns = anns
      self.imgToAnns = imgToAnns
      self.catToImgs = catToImgs
      self.imgNameToId = imgNameToId
      self.imgs = imgs
      self.cats = cats
  
imports: import json
  import time
  import matplotlib.pyplot
  from matplotlib.collections import PatchCollection
  from matplotlib.patches import Polygon
  import numpy
  import copy
  import itertools
  import os
  import os.path
  from collections import defaultdict
  import sys
  from datetime import datetime
label_desc: Use image node_id 4 for calling the COCO obj's underlying member method code with example usage: obj.createIndex() without return types