Skip to content

constants

Constant Definitions

semantic_class_id_to_name() cached

Get mapping from semantic class id to class name

Returns:

Type Description
dict

class id to class name

Source code in omnigibson/utils/constants.py
@cache
def semantic_class_id_to_name():
    """
    Get mapping from semantic class id to class name

    Returns:
        dict: class id to class name
    """
    return {v: k for k, v in semantic_class_name_to_id().items()}

semantic_class_name_to_id() cached

Get mapping from semantic class name to class id

Returns:

Type Description
dict

class name to class id

Source code in omnigibson/utils/constants.py
@cache
def semantic_class_name_to_id():
    """
    Get mapping from semantic class name to class id

    Returns:
        dict: class name to class id
    """
    categories = get_all_object_categories()
    systems = get_all_system_categories(include_cloth=True)

    all_semantics = sorted(set(categories + systems + ["background", "unlabelled", "object", "light", "agent"]))

    # Assign a unique class id to each class name with hashing, the upper limit here is the max of int32
    max_int32 = th.iinfo(th.int32).max + 1
    class_name_to_class_id = {s: int(hashlib.md5(s.encode()).hexdigest(), 16) % max_int32 for s in all_semantics}

    return class_name_to_class_id