def load_config(): r"""loads model config """ parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument( '--config', type=str, default='config_example.json', help= 'configuration file name. Relative path under given path (default: config.yml)' ) parser.add_argument( '--loadbest', type=int, default=0, choices=[0, 1], help= '1: load best model or 0: load checkpoints. Only works in non training mode.' ) parser.add_argument('--mode', type=str, choices=['train', 'trace', 'eval'], help='mode. can be [train,trace,eval]', required=True) args = parser.parse_args() config_path = os.path.abspath(args.config) if not os.path.exists(config_path): raise RuntimeError('Targer config file does not exist. {}' & config_path) # load config file config = Config(config_path) if 'NAME' not in config: config_name = os.path.basename(args.config) if len(config_name) > len('config_'): name = config_name[len('config_'):] name = os.path.splitext(name)[0] translation_table = dict.fromkeys(map(ord, '!@#$'), None) name = name.translate(translation_table) config['NAME'] = name config.LOADBEST = args.loadbest config.MODE = args.mode return config