def build_from_cfg(name, cfg, registry, default_args=None):
    """Build a module from config dict.

    Args:
        name (str): Name of the object
        cfg (addict): Config dict of the object
        registry (:obj:`Registry`): The registry to search the type from.
        default_args (dict, optional): Default initialization arguments.

    Returns:
        obj: The constructed object.
    """

    assert isinstance(default_args, dict) or default_args is None

    obj = registry.get(name)
    if obj is None:
        raise KeyError(f'{name} is not in the {registry.name} registry. '
                       f'Choose among {list(registry.obj_dict.keys())}')

    if default_args is not None:
        for key, value in default_args.items():
            cfg.setdefault(key, value)

    return obj(cfg)