(config='', exp_name='', hparams_str='', print_hparams=True, global_hparams=True)
| 21 | |
| 22 | |
| 23 | def set_hparams(config='', exp_name='', hparams_str='', print_hparams=True, global_hparams=True): |
| 24 | if config == '': |
| 25 | parser = argparse.ArgumentParser(description='neural music') |
| 26 | parser.add_argument('--config', type=str, default='', |
| 27 | help='location of the data corpus') |
| 28 | parser.add_argument('--exp_name', type=str, default='', help='exp_name') |
| 29 | parser.add_argument('--hparams', type=str, default='', |
| 30 | help='location of the data corpus') |
| 31 | parser.add_argument('--infer', action='store_true', help='infer') |
| 32 | parser.add_argument('--validate', action='store_true', help='validate') |
| 33 | parser.add_argument('--reset', action='store_true', help='reset hparams') |
| 34 | parser.add_argument('--debug', action='store_true', help='debug') |
| 35 | args, unknown = parser.parse_known_args() |
| 36 | else: |
| 37 | args = Args(config=config, exp_name=exp_name, hparams=hparams_str, |
| 38 | infer=False, validate=False, reset=False, debug=False) |
| 39 | args_work_dir = '' |
| 40 | if args.exp_name != '': |
| 41 | args.work_dir = args.exp_name |
| 42 | args_work_dir = f'checkpoints/{args.work_dir}' |
| 43 | |
| 44 | config_chains = [] |
| 45 | loaded_config = set() |
| 46 | |
| 47 | def load_config(config_fn): # deep first |
| 48 | with open(config_fn) as f: |
| 49 | hparams_ = yaml.safe_load(f) |
| 50 | loaded_config.add(config_fn) |
| 51 | if 'base_config' in hparams_: |
| 52 | ret_hparams = {} |
| 53 | if not isinstance(hparams_['base_config'], list): |
| 54 | hparams_['base_config'] = [hparams_['base_config']] |
| 55 | for c in hparams_['base_config']: |
| 56 | if c not in loaded_config: |
| 57 | if c.startswith('.'): |
| 58 | c = f'{os.path.dirname(config_fn)}/{c}' |
| 59 | c = os.path.normpath(c) |
| 60 | override_config(ret_hparams, load_config(c)) |
| 61 | override_config(ret_hparams, hparams_) |
| 62 | else: |
| 63 | ret_hparams = hparams_ |
| 64 | config_chains.append(config_fn) |
| 65 | return ret_hparams |
| 66 | |
| 67 | global hparams |
| 68 | assert args.config != '' or args_work_dir != '' |
| 69 | saved_hparams = {} |
| 70 | if args_work_dir != 'checkpoints/': |
| 71 | ckpt_config_path = f'{args_work_dir}/config.yaml' |
| 72 | if os.path.exists(ckpt_config_path): |
| 73 | try: |
| 74 | with open(ckpt_config_path) as f: |
| 75 | saved_hparams.update(yaml.safe_load(f)) |
| 76 | except: |
| 77 | pass |
| 78 | if args.config == '': |
| 79 | args.config = ckpt_config_path |
| 80 |
no test coverage detected