code: def maybe_filter_categories_cocoapi(dataset_name, coco_api):
      meta = MetadataCatalog.get(dataset_name)
      cont_id_2_cat_id = get_contiguous_id_to_category_id_map(meta)
      cat_id_2_cont_id = meta.thing_dataset_id_to_contiguous_id
      # filter categories
      cats = []
      for cat in coco_api.dataset["categories"]:
          cat_id = cat["id"]
          if cat_id not in cat_id_2_cont_id:
              continue
          cont_id = cat_id_2_cont_id[cat_id]
          if (cont_id in cont_id_2_cat_id) and (
              cont_id_2_cat_id[cont_id] == cat_id
          ):
              cats.append(cat)
      coco_api.dataset["categories"] = cats
      # filter annotations, if multiple categories are mapped to a single
      # contiguous ID, use only one category ID and map all annotations to that category ID
      anns = []
      for ann in coco_api.dataset["annotations"]:
          cat_id = ann["category_id"]
          if cat_id not in cat_id_2_cont_id:
              continue
          cont_id = cat_id_2_cont_id[cat_id]
          ann["category_id"] = cont_id_2_cat_id[cont_id]
          anns.append(ann)
      coco_api.dataset["annotations"] = anns
      # recreate index
      coco_api.createIndex()
  
imports: import contextlib
  import io
  import logging
  import os
  from collections import defaultdict
  from dataclasses import dataclass
  from typing import Any, Dict, Iterable, List, Optional
  from fvcore.common.timer import Timer
  from detectron2.data import DatasetCatalog, MetadataCatalog
  from detectron2.structures import BoxMode
  from detectron2.utils.file_io import PathManager
  from ..utils import maybe_prepend_base_path
label_desc: Use image node_id 11 for calling a global function with example usage: maybe_filter_categories_cocoapi(dataset_name, coco_api) without return types