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"
                },
                ...
            ]

    Returns:
        a tuple of

        -   classes: a list of classes
        -   supercategory_map: a dict mapping class labels to supercategories
    """
    id_map = {
        c["id"]: (c.get("name", None), c.get("supercategory", None))
        for c in categories
    }

    classes = []
    supercategory_map = {}
    for idx in range(max(id_map) + 1):
        name, supercategory = id_map.get(idx, (None, None))
        if name is None:
            name = str(idx)

        classes.append(name)
        supercategory_map[name] = supercategory

    return classes, supercategory_map