code: def load_in22k_subset_opeinimages_miap_labels_images_preds_metadata(
      input_data, confidence_threshold=0.0
  ):
      # load the predictions
      predictions = load_file(input_data["label_predictions"])
      print(f"Number of predictions: {predictions.shape}\n")
  
      # load the indices
      indices = load_file(input_data["pred_img_indices"])
      print(f"Number of indices: {indices.shape}\n")
  
      # load the confidence scores if provided
      has_confidence_scores = False
      if "label_predictions_scores" in input_data:
          confidence_scores = load_file(
              input_data["label_predictions_scores"]
          )
          filtered_confidence_scores, out_predictions = [], []
          for img_idx in range(len(predictions)):
              img_predictions, img_scores = [], []
              for pred_idx in predictions[img_idx]:
                  if (
                      confidence_scores[img_idx][pred_idx]
                      >= confidence_threshold
                  ):
                      img_predictions.append(pred_idx)
                      img_scores.append(
                          str(
                              round(
                                  confidence_scores[img_idx][pred_idx],
                                  5,
                              )
                          )
                      )
              filtered_confidence_scores.append(img_scores)
              out_predictions.append(img_predictions)
          has_confidence_scores = True
          predictions = out_predictions
          print(
              f"Confidence scores: {len(filtered_confidence_scores)}\n"
          )
  
      # load the metadata
      metadata = load_file(input_data["metadata"])
      if isinstance(metadata, list):
          print(f"metadata: {len(metadata)}")
          print(f"metadata keys: {metadata[0].keys()}")
      else:
          print(f"metadata: {list(metadata.values())[0].keys()}")
  
      # extract the image paths
      image_paths = [item["path"] for item in metadata]
      print(f"Number of image_paths: {len(image_paths)}\n")
      bbox_annotations = [item["bbox"] for item in metadata]
      print(f"Number of bbox_annotations: {len(bbox_annotations)}\n")
  
      # load the label id map
      label_to_id = load_file(input_data["label_to_id_map"])
      id_to_label = {value: key for key, value in label_to_id.items()}
      print("Loaded label_to_id and generated id_to_label map")
  
      # {'AgePresentation': 'Young',
      #     'Confidence': '1',
      #     'GenderPresentation': 'Unknown',
      #     'IsDepictionOf': '0',
      #     'IsGroupOf': '0',
      #     'IsInsideOf': '0',
      #     'IsOccluded': '0',
      #     'IsTruncated': '0',
      #     'LabelName': '/m/01g317',
      #     'bbox': ['886.5607679999999', '302.212474', '1016.448', '639.179403'],
      #     'path': '/path/to/img1.jpg'},
      SIMPLIFIED_GENDER_MAP = {
          "feminine": "female",
          "masculine": "male",
          "unknown": "gender_unknown",
      }
      openimages_miap_map = {}
      for item in metadata:
          path = item["path"]
          bbox = item["bbox"]
          str_bbox = "_".join(bbox)
          gender = SIMPLIFIED_GENDER_MAP[
              item["GenderPresentation"].lower().split()[-1]
          ]
          age = item["AgePresentation"].lower()
          map_key = f"{path}_{str_bbox}"
          openimages_miap_map[map_key] = {
              "gender": gender,
              "age": age,
              "orig_path": path,
              "bbox": bbox,
          }
      # now we filter further based on the image paths actually present in the data
      # and we enter the information about the prediction
      filtered_openimages_miap_map = {}
      for item in range(len(indices)):
          idx = indices[item]
          inp_img_path = image_paths[idx]
          bbox = bbox_annotations[idx]
          str_bbox = "_".join(bbox)
          map_key = f"{inp_img_path}_{str_bbox}"
          filtered_openimages_miap_map[map_key] = openimages_miap_map[
              map_key
          ]
          filtered_openimages_miap_map[map_key].update(
              {
                  "prediction": [
                      id_to_label[item] for item in predictions[item]
                  ]
              }
          )
          if has_confidence_scores:
              filtered_openimages_miap_map[map_key].update(
                  {
                      "confidence_scores": filtered_confidence_scores[
                          item
                      ]
                  }
              )
      print(
          f"Output data entries: {len(list(filtered_openimages_miap_map.keys()))}"
      )
      return filtered_openimages_miap_map, label_to_id
  
file_path: vissl/projects/fairness_indicators/harmful_label_associations/inference_label_assoc_openimages_miap_test.py
imports: import matplotlib.pyplot
  import numpy
  import pandas
  import torchvision.transforms
  from fvcore.common.file_io import PathManager
  from PIL import Image
  from vissl.utils.io import load_file
label_desc: Use image node_id 5 for calling a global function with example usage: load_in22k_subset_opeinimages_miap_labels_images_preds_metadata(input_data, confidence_threshold) and returns: filtered_openimages_miap_map,  label_to_id