def build_from_cfg(cfg, registry, default_args=None):
    """
    Build an object from config dict.
    """
    obj_type = cfg.pop('type')
    obj_class = registry.get(obj_type)
    if default_args is not None:
        return obj_class(cfg=cfg, **default_args)
    else:
        return obj_class(cfg=cfg)