def main(): parser = argparse.ArgumentParser() parser.add_argument('--hp_file', type=str, default='hparams.py') args = parser.parse_args() hp.configure(args.hp_file) fill_variables(hp) log_config(hp) os.makedirs(hp.save_dir, exist_ok=True) n_gpus = torch.cuda.device_count() args.__setattr__('n_gpus', n_gpus) if n_gpus > 1: run_distributed(run_training, args, hp) else: run_training(0, args, hp, None)
parser.add_argument('--log_params', action='store_true') parser.add_argument('--calc_wer', action='store_true') parser.add_argument('--segment', type=int, default=10000) parser.add_argument('--silence_file', type=str, default=None) parser.add_argument('--lm_type', type=str, default='LSTM') args = parser.parse_args() hp_file = args.hp_file model_name = args.load_name # save dir name model_path = os.path.dirname(model_name) if hp_file is None: hp_file = os.path.join(model_path, 'hparams.py') hp.configure(hp_file) fill_variables(hp) setattr(hp, 'silence_file', args.silence_file) if args.beam_width is not None: print(f'beam width is set to {args.beam_width}') hp.beam_width = args.beam_width script_file = hp.eval_file if args.test_script is not None: script_file = args.test_script if hp.lm_weight is not None: args.lm_weight = hp.lm_weight print(f'lm weight = {args.lm_weight}') model = Transformer(hp)
hp.save_dir + "/network.optimizer.epoch{}".format(epoch + 1)) adjust_learning_rate(optimizer, epoch + 1) if (epoch + 1) % hp.reset_optimizer_epoch == 0: optimizer = torch.optim.Adam(model.parameters(), weight_decay=1e-5) print("EPOCH {} end".format(epoch + 1)) print(f'elapsed time = {(time.time()-start_time)//60}m') if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('--hp_file', metavar='FILE', default='hparams.py') args = parser.parse_args() #overwrite_hparams(args) hp.configure(args.hp_file) fill_variables() hp.save_dir = os.path.join(hp.save_dir, 'LM') os.makedirs(hp.save_dir, exist_ok=True) if hp.debug_mode == 'tensorboard': writer = SummaryWriter(f'{hp.save_dir}/logs/{hp.comment}') log_config() model = Model_lm(hp) model.apply(init_weight) if torch.cuda.device_count() > 1: # multi-gpu configuration ngpu = torch.cuda.device_count() device_ids = list(range(ngpu))
parser.add_argument('--test_script', type=str, default=None) parser.add_argument('--load_name_lm', type=str, default=None) parser.add_argument('--lm_weight', type=float, default=None) parser.add_argument('--log_params', action='store_true') args = parser.parse_args() load_name = args.load_name load_dir = os.path.dirname(load_name) if os.path.exists(os.path.join(load_dir, 'hparams.py')): args.hp_file = os.path.join(load_dir, 'hparams.py') #hp = utils.HParams() hp.configure(args.hp_file) fill_variables(hp, args.log_params) overwrite_hparams(args, hp) if hp.decoder_type == 'Attention': model = AttModel(hp) elif hp.decoder_type == 'CTC': model = CTCModel(hp) if hp.load_name_lm is not None: hp_LM_path = os.path.join(os.path.dirname(hp.load_name_lm), 'hparams.py') hp_LM = utils.HParams() hp_LM.configure(hp_LM_path) model_lm = Model_lm(hp_LM) model_lm.to(DEVICE) model_lm.load_state_dict(load_model(hp.load_name_lm)) model_lm.eval()