mirror of
https://github.com/wassname/pytorch-lightning.git
synced 2026-09-09 11:32:07 +08:00
added override for hparams in load_from_ckpt (#1797)
* added override for hparams in load_from_ckpt * override hparams * override hparams * Apply suggestions from code review Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com> * update doctest * typo * chlog Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com> Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com> Co-authored-by: Jirka <jirka.borovec@seznam.cz>
This commit is contained in:
co-authored by
Adrian Wälchli
Jirka Borovec
Jirka
parent
10ce1c0256
commit
35fe2efe27
@@ -48,6 +48,37 @@ class ModelIO(object):
|
||||
"""
|
||||
|
||||
|
||||
def update_hparams(hparams: dict, updates: dict) -> None:
|
||||
"""
|
||||
Overrides hparams with new values
|
||||
|
||||
>>> hparams = {'c': 4}
|
||||
>>> update_hparams(hparams, {'a': {'b': 2}, 'c': 1})
|
||||
>>> hparams['a']['b'], hparams['c']
|
||||
(2, 1)
|
||||
>>> update_hparams(hparams, {'a': {'b': 4}, 'c': 7})
|
||||
>>> hparams['a']['b'], hparams['c']
|
||||
(4, 7)
|
||||
|
||||
Args:
|
||||
hparams: the original params and also target object
|
||||
updates: new params to be used as update
|
||||
|
||||
"""
|
||||
for k, v in updates.items():
|
||||
# if missing, add the key
|
||||
if k not in hparams:
|
||||
hparams[k] = v
|
||||
continue
|
||||
|
||||
# recurse if dictionary
|
||||
if isinstance(v, dict):
|
||||
update_hparams(hparams[k], updates[k])
|
||||
else:
|
||||
# update the value
|
||||
hparams.update({k: v})
|
||||
|
||||
|
||||
def load_hparams_from_tags_csv(tags_csv: str) -> Namespace:
|
||||
if not os.path.isfile(tags_csv):
|
||||
log.warning(f'Missing Tags: {tags_csv}.')
|
||||
|
||||
Reference in New Issue
Block a user