MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / merge_from_dict

Method merge_from_dict

util/config.py:311–340  ·  view source on GitHub ↗

Merge list into cfg_dict. Merge the dict parsed by MultipleKVAction into this cfg. Examples: >>> options = {'model.backbone.depth': 50, ... 'model.backbone.with_cp':True} >>> cfg = Config(dict(model=dict(backbone=dict(type='ResNet'))))

(self, options)

Source from the content-addressed store, hash-verified

309 f.write(self.pretty_text)
310
311 def merge_from_dict(self, options):
312 """Merge list into cfg_dict.
313
314 Merge the dict parsed by MultipleKVAction into this cfg.
315
316 Examples:
317 >>> options = {'model.backbone.depth': 50,
318 ... 'model.backbone.with_cp':True}
319 >>> cfg = Config(dict(model=dict(backbone=dict(type='ResNet'))))
320 >>> cfg.merge_from_dict(options)
321 >>> cfg_dict = super(Config, self).__getattribute__('_cfg_dict')
322 >>> assert cfg_dict == dict(
323 ... model=dict(backbone=dict(depth=50, with_cp=True)))
324
325 Args:
326 options (dict): dict of configs to merge from.
327 """
328 option_cfg_dict = {}
329 for full_key, v in options.items():
330 d = option_cfg_dict
331 key_list = full_key.split('.')
332 for subkey in key_list[:-1]:
333 d.setdefault(subkey, ConfigDict())
334 d = d[subkey]
335 subkey = key_list[-1]
336 d[subkey] = v
337
338 cfg_dict = super(Config, self).__getattribute__('_cfg_dict')
339 super(Config, self).__setattr__(
340 '_cfg_dict', Config._merge_a_into_b(option_cfg_dict, cfg_dict))
341
342 # for multiprocess
343 def __setstate__(self, state):

Callers 2

get_config_fromfileMethod · 0.95
mainFunction · 0.80

Calls 4

ConfigDictClass · 0.85
__setattr__Method · 0.80
_merge_a_into_bMethod · 0.80
itemsMethod · 0.45

Tested by

no test coverage detected