Open unsky opened 5 years ago
package yacs is actually a dict wrapper. So first you read the first config as usual, let's say as Variable CONFIG, then you read the second config as a new python dict (e.g. variable a), then update the CONFIG variable using items in "a". The following function can be used:
def deep_update(source, overrides):
for key, value in overrides.iteritems():
if isinstance(value, collections.Mapping) and value:
returned = deep_update(source.get(key, {}), value)
returned = CfgNode(returned)
source[key] = returned
else:
source[key] = overrides[key]
return source
_C = CN(new_allowed=True)
It works for me.
You can use the 'merge_from_other_cfg' method:
https://github.com/rbgirshick/yacs/blob/32d5e4ac300eca6cd3b839097dde39c4017a1070/yacs/config.py#L215 e.g.
config1 = CN()
config1.BLAH = blah
config2 = CN()
config2.FOO = bar
config1.set_new_allowed(TRUE) # recursively update set_new_allowed to allow merging of configs and subconfigs
config1.merge_from_other_cfg(config2)```
config1.py:
config2.py:
how meger two config?