def parse_coco_categories(categories):
    """Parses the COCO categories list.

    The returned ``classes`` contains all class IDs from ``[0, max_id]``,
    inclusive.

    Args:
        categories: a dict of the form::

            [
                ...
                {
                    "id": 2,
                    "name": "cat",
                    "supercategory": "animal",
                    "keypoints": ["nose", "head", ...],
                    "skeleton": [[12, 14], [14, 16], ...]
                },
                ...
            ]

    Returns:
        a tuple of

        -   classes: a list of classes
        -   supercategory_map: a dict mapping class labels to category dicts
    """
    cat_map = {c["id"]: c for c in categories}

    classes = []
    supercategory_map = {}
    for cat_id in range(max(cat_map) + 1):
        category = cat_map.get(cat_id, None)
        try:
            name = category["name"]
        except:
            name = str(cat_id)

        classes.append(name)
        if category is not None:
            supercategory_map[name] = category

    return classes, supercategory_map