code: def get_image_annotations_mode(class_names, data_dir, mode="train"):
      """Returns map from img number to label (along with verification
      source and confidence)"""
  
      assert mode in set(["train", "test", "validation"])
      lab_dir = os.path.join(
          data_dir,
          "labels",
          f"{mode}-annotations-human-imagelabels-boxable.csv",
      )
      prefix = "oidv6-" if mode == "train" else ""
      anno_dir = os.path.join(
          data_dir, "boxes", f"{prefix}{mode}-annotations-bbox.csv"
      )
  
      img_to_label = {}
      with open(lab_dir, newline="") as csvfile:
          for ri, row in enumerate(
              csv.reader(csvfile, delimiter=" ", quotechar="|")
          ):
              if ri == 0:
                  continue
  
              assert len(row) == 1
              im_id, ver, cno, conf = tuple(row[0].split(","))
              cno = class_names[cno]
  
              if im_id not in img_to_label:
                  img_to_label[im_id] = {}
  
              if cno not in img_to_label[im_id]:
                  img_to_label[im_id][cno] = {"ver": [], "conf": []}
              img_to_label[im_id][cno]["ver"].append(ver)
              img_to_label[im_id][cno]["conf"].append(conf)
  
      for im_id in img_to_label:
          for lab in img_to_label[im_id]:
              assert (
                  len(np.unique(img_to_label[im_id][lab]["conf"])) == 1
              )
              img_to_label[im_id][lab]["conf"] = img_to_label[im_id][
                  lab
              ]["conf"][0]
  
      with open(anno_dir, newline="") as csvfile:
          for ri, row in enumerate(
              csv.reader(csvfile, delimiter=" ", quotechar="|")
          ):
              if ri == 0:
                  continue
              assert len(row) == 1
              rs = row[0].split(",")
              im_id, src, cno = tuple(rs[:3])
              cno = class_names[cno]
  
              box = [float(v) for v in rs[4:8]]
              if (
                  "box" not in img_to_label[im_id][cno]
                  or src == "activemil"
              ):
                  img_to_label[im_id][cno]["box"] = box
  
      return img_to_label
  
file_path: robustness/robustness/tools/openimgs_helpers.py
imports: import os
  import csv
  import numpy
  import torch
  import torch.utils.data
  import robustness.data_augmentation
  from robustness import imagenet_models
  from .folder import default_loader, IMG_EXTENSIONS
label_desc: Use image node_id 2 for calling a global function with example usage: get_image_annotations_mode(class_names, data_dir, mode) and returns: img_to_label