code: def generate_dollar_street_map(
      image_paths,
      metadata,
      predictions,
      id_to_label,
      confidence_scores=None,
      topk=5,
  ):
      confidence_scores = confidence_scores or []
      output_ds_metadata = {}
      for entry in metadata:
          img_id = entry["_id"]
          label = entry["label"]
          path = f"{label}/{img_id}"
          output_ds_metadata[path] = {
              "country": entry["country"],
              "concept": entry["label"],
              "country_concept": f"{entry['country']}_{entry['label']}",
              "region": entry["region"],
              "income": entry["income"],
              "url": entry["url"],
          }
  
      filtered_ds_metadata = {}
      has_confidence_scores = False
      if len(confidence_scores) > 0:
          has_confidence_scores = True
      for idx in range(len(image_paths)):
          pred = predictions[idx][:topk]
          img_predictions = []
          raw_predictions = []
          for item in pred:
              raw_predictions.append(id_to_label[str(item)])
          for item in pred:
              img_predictions.extend(id_to_label[str(item)])
          img_id = os.path.splitext(image_paths[idx].split("/")[-1])[0]
          target_label = image_paths[idx].split("/")[-2]
          path = f"{target_label}/{img_id}"
          if path in output_ds_metadata:
              filtered_ds_metadata[path] = output_ds_metadata[path]
              filtered_ds_metadata[path].update(
                  {"prediction": img_predictions}
              )
              filtered_ds_metadata[path].update(
                  {"raw_prediction": raw_predictions}
              )
              if has_confidence_scores:
                  filtered_ds_metadata[path].update(
                      {
                          "confidence_scores": confidence_scores[idx][
                              :topk
                          ]
                      }
                  )
          else:
              print(f"Not found: {path}")
      print(
          f"Output data entries: {len(list(filtered_ds_metadata.keys()))}"
      )
      return filtered_ds_metadata
  
imports: import json
  import os
  from math import ceil, floor
  from pathlib import Path
  import matplotlib.pyplot
  import numpy
  import pandas
  import seaborn
  from IPython.display import display_html
  from matplotlib.ticker import FixedLocator
  from vissl.utils.io import load_file, save_file
label_desc: Use image node_id 2 for calling a global function with example usage: generate_dollar_street_map(image_paths, metadata, predictions, id_to_label, confidence_scores, topk) and returns: filtered_ds_metadata