omegaconf
omegaconf copied to clipboard
Add a Get_leaves_str() function for printing all the leave values in an OmegaConf object
Describe the solution you'd like I want to print all the leave values of an OmegaConf object, so that I can check them directly.
Additional context Thanks sincerely for the help from @Jasha10, and here is a simple implementation as:
def get_leaves_str(cfg, parent=None):
if not OmegaConf.is_config(cfg):
assert parent, cfg
return [f"{parent} = {str(cfg)}"]
if OmegaConf.is_list(cfg):
keys = range(len(cfg))
elif OmegaConf.is_config(cfg):
keys = cfg.keys()
else:
raise NotImplementedError
string = []
parent = f"{parent}." if parent else ""
for k in keys:
child_key = f"{parent}{k}"
v = cfg[k] if not OmegaConf.is_missing(cfg, k) else "???"
string += get_leaves_str(v, child_key)
return string
Cross-linking to related discussion: https://github.com/omry/omegaconf/discussions/961
I think this is not useful enough as an API. Given the lack of community attention in the last 6 months, I think it's safe to close.