code: def convert_label_map_to_categories(
      label_map, max_num_classes, use_display_name=True
  ):
      """Loads label map proto and returns categories list compatible with eval.
  
      This function loads a label map and returns a list of dicts, each of which
      has the following keys:
        'id': (required) an integer id uniquely identifying this category.
        'name': (required) string representing category name
          e.g., 'cat', 'dog', 'pizza'.
      We only allow class into the list if its id-label_id_offset is
      between 0 (inclusive) and max_num_classes (exclusive).
      If there are several items mapping to the same id in the label map,
      we will only keep the first one in the categories list.
  
      Args:
        label_map: a StringIntLabelMapProto or None.  If None, a default categories
          list is created with max_num_classes categories.
        max_num_classes: maximum number of (consecutive) label indices to include.
        use_display_name: (boolean) choose whether to load 'display_name' field
          as category name.  If False or if the display_name field does not exist,
          uses 'name' field as category names instead.
      Returns:
        categories: a list of dictionaries representing all possible categories.
      """
      categories = []
      list_of_ids_already_added = []
      if not label_map:
          label_id_offset = 1
          for class_id in range(max_num_classes):
              categories.append(
                  {
                      "id": class_id + label_id_offset,
                      "name": "category_{}".format(
                          class_id + label_id_offset
                      ),
                  }
              )
          return categories
      for item in label_map.item:
          if not 0 < item.id <= max_num_classes:
              logging.info(
                  "Ignore item %d since it falls outside of requested "
                  "label range.",
                  item.id,
              )
              continue
          if use_display_name and item.HasField("display_name"):
              name = item.display_name
          else:
              name = item.name
          if item.id not in list_of_ids_already_added:
              list_of_ids_already_added.append(item.id)
              categories.append({"id": item.id, "name": name})
      return categories
  
file_path: SlowFast/ava_evaluation/label_map_util.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
label_desc: Use image node_id 4 for calling a global function with example usage: convert_label_map_to_categories(label_map, max_num_classes, use_display_name) and returns: categories, categories