code: def get_coco_imgs_labels_info(split, data_source_dir, args):
      # pycocotools is an optional dependency for VISSL
      from pycocotools.coco import COCO
  
      json_file = (
          f"{data_source_dir}/annotations/instances_{split}2014.json"
      )
      assert g_pathmgr.exists(
          json_file
      ), "Annotations file does not exist. Abort"
      json_data = json.load(g_pathmgr.open(json_file, "r"))
      image_index = [x["id"] for x in json_data["images"]]
      coco = COCO(json_file)
  
      num_cats = len(json_data["categories"])
      logging.info(
          "partition: {} num_cats: {} num_images: {}".format(
              split, num_cats, len(image_index)
          )
      )
      cat_ids = [x["id"] for x in json_data["categories"]]
      coco_to_me = {val: ind for ind, val in enumerate(cat_ids)}
      cat_names = [str(x["name"]) for x in json_data["categories"]]
      cat_name_to_id, cat_id_to_name = {}, {}
      for ind, name in enumerate(cat_names):
          cat_name_to_id[name] = ind
          cat_id_to_name[ind] = name
  
      class_ids = cat_id_to_name.keys()
      assert len(list(class_ids)) == num_cats
      assert min(class_ids) == 0
      assert max(class_ids) == len(class_ids) - 1
      assert len(set(class_ids)) == len(class_ids)
      # label_matrix = np.zeros((len(image_index), len(cat_names)), dtype=np.float32)
      # area_matrix = np.zeros((len(image_index), len(cat_names)), dtype=np.float32)
      img_labels_map = {}
      num_classes = len(cat_names)
      for _, im_id in enumerate(image_index):
          ann_ids = coco.getAnnIds(imgIds=im_id)
          entry = coco.imgs[im_id]
          img_name = entry["file_name"]
          objs = coco.loadAnns(ann_ids)
          valid_objs = get_valid_objs(entry, objs)
          if img_name not in img_labels_map:
              img_labels_map[img_name] = np.zeros(
                  num_classes, dtype=np.int32
              )
          for _, obj in enumerate(valid_objs):
              cocoCatId = obj["category_id"]
              myId = coco_to_me[cocoCatId]
              img_labels_map[img_name][myId] = 1.0
  
      # label = 1 (present), 0 (not present)
      img_paths, img_labels = [], []
      train_imgs_path = f"{data_source_dir}/train2014"
      val_imgs_path = f"{data_source_dir}/val2014"
      prefix = train_imgs_path if split == "train" else val_imgs_path
      for item in sorted(img_labels_map.keys()):
          img_paths.append(f"{prefix}/{item}")
          img_labels.append(img_labels_map[item])
  
      # save to the datasets folder and return the path
      output_dir = get_output_dir()
      img_info_out_path = f"{output_dir}/{split}_images.npy"
      label_info_out_path = f"{output_dir}/{split}_labels.npy"
      save_file(np.array(img_paths), img_info_out_path)
      save_file(np.array(img_labels), label_info_out_path)
      return [img_info_out_path, label_info_out_path]
  
file_path: vissl/vissl/data/datasets/coco.py
imports: import json
  import logging
  import os
  import numpy
  from iopath.common.file_io import g_pathmgr
  from vissl.utils.io import makedir, save_file
label_desc: Use image node_id 4 for calling a global function with example usage: get_coco_imgs_labels_info(split, data_source_dir, args) and returns: list