mirror of https://github.com/coqui-ai/TTS.git
refactored keep_all_best
parent
8cefa76bae
commit
2451a813a2
|
@ -551,8 +551,8 @@ def main(args): # pylint: disable=redefined-outer-name
|
|||
best_loss = torch.load(args.best_path,
|
||||
map_location='cpu')['model_loss']
|
||||
print(f" > Starting with loaded last best loss {best_loss}.")
|
||||
keep_best = c.get('keep_best', False)
|
||||
keep_after = c.get('keep_after', 10000) # void if keep_best False
|
||||
keep_all_best = c.get('keep_all_best', False)
|
||||
keep_after = c.get('keep_after', 10000) # void if keep_all_best False
|
||||
|
||||
# define dataloaders
|
||||
train_loader = setup_loader(ap, 1, is_val=False, verbose=True)
|
||||
|
@ -574,7 +574,7 @@ def main(args): # pylint: disable=redefined-outer-name
|
|||
target_loss = eval_avg_loss_dict['avg_loss']
|
||||
best_loss = save_best_model(target_loss, best_loss, model, optimizer,
|
||||
global_step, epoch, c.r, OUT_PATH,
|
||||
keep_best=keep_best, keep_after=keep_after)
|
||||
keep_all_best=keep_all_best, keep_after=keep_after)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -515,8 +515,8 @@ def main(args): # pylint: disable=redefined-outer-name
|
|||
best_loss = torch.load(args.best_path,
|
||||
map_location='cpu')['model_loss']
|
||||
print(f" > Starting with loaded last best loss {best_loss}.")
|
||||
keep_best = c.get('keep_best', False)
|
||||
keep_after = c.get('keep_after', 10000) # void if keep_best False
|
||||
keep_all_best = c.get('keep_all_best', False)
|
||||
keep_after = c.get('keep_after', 10000) # void if keep_all_best False
|
||||
|
||||
# define dataloaders
|
||||
train_loader = setup_loader(ap, 1, is_val=False, verbose=True)
|
||||
|
@ -536,7 +536,7 @@ def main(args): # pylint: disable=redefined-outer-name
|
|||
target_loss = eval_avg_loss_dict['avg_loss']
|
||||
best_loss = save_best_model(target_loss, best_loss, model, optimizer,
|
||||
global_step, epoch, c.r, OUT_PATH,
|
||||
keep_best=keep_best, keep_after=keep_after)
|
||||
keep_all_best=keep_all_best, keep_after=keep_after)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -595,8 +595,8 @@ def main(args): # pylint: disable=redefined-outer-name
|
|||
best_loss = torch.load(args.best_path,
|
||||
map_location='cpu')['model_loss']
|
||||
print(f" > Starting with loaded last best loss {best_loss}.")
|
||||
keep_best = c.get('keep_best', False)
|
||||
keep_after = c.get('keep_after', 10000) # void if keep_best False
|
||||
keep_all_best = c.get('keep_all_best', False)
|
||||
keep_after = c.get('keep_after', 10000) # void if keep_all_best False
|
||||
|
||||
# define data loaders
|
||||
train_loader = setup_loader(ap,
|
||||
|
@ -648,7 +648,7 @@ def main(args): # pylint: disable=redefined-outer-name
|
|||
epoch,
|
||||
c.r,
|
||||
OUT_PATH,
|
||||
keep_best=keep_best,
|
||||
keep_all_best=keep_all_best,
|
||||
keep_after=keep_after,
|
||||
scaler=scaler.state_dict() if c.mixed_precision else None
|
||||
)
|
||||
|
|
|
@ -555,8 +555,8 @@ def main(args): # pylint: disable=redefined-outer-name
|
|||
best_loss = torch.load(args.best_path,
|
||||
map_location='cpu')['model_loss']
|
||||
print(f" > Starting with best loss of {best_loss}.")
|
||||
keep_best = c.get('keep_best', False)
|
||||
keep_after = c.get('keep_after', 10000) # void if keep_best False
|
||||
keep_all_best = c.get('keep_all_best', False)
|
||||
keep_after = c.get('keep_after', 10000) # void if keep_all_best False
|
||||
|
||||
global_step = args.restore_step
|
||||
for epoch in range(0, c.epochs):
|
||||
|
@ -581,7 +581,7 @@ def main(args): # pylint: disable=redefined-outer-name
|
|||
global_step,
|
||||
epoch,
|
||||
OUT_PATH,
|
||||
keep_best=keep_best,
|
||||
keep_all_best=keep_all_best,
|
||||
keep_after=keep_after,
|
||||
model_losses=eval_avg_loss_dict,
|
||||
)
|
||||
|
|
|
@ -403,8 +403,8 @@ def main(args): # pylint: disable=redefined-outer-name
|
|||
best_loss = torch.load(args.best_path,
|
||||
map_location='cpu')['model_loss']
|
||||
print(f" > Starting with loaded last best loss {best_loss}.")
|
||||
keep_best = c.get('keep_best', False)
|
||||
keep_after = c.get('keep_after', 10000) # void if keep_best False
|
||||
keep_all_best = c.get('keep_all_best', False)
|
||||
keep_after = c.get('keep_after', 10000) # void if keep_all_best False
|
||||
|
||||
global_step = args.restore_step
|
||||
for epoch in range(0, c.epochs):
|
||||
|
@ -426,7 +426,7 @@ def main(args): # pylint: disable=redefined-outer-name
|
|||
global_step,
|
||||
epoch,
|
||||
OUT_PATH,
|
||||
keep_best=keep_best,
|
||||
keep_all_best=keep_all_best,
|
||||
keep_after=keep_after,
|
||||
model_losses=eval_avg_loss_dict,
|
||||
scaler=scaler.state_dict() if c.mixed_precision else None
|
||||
|
|
|
@ -426,8 +426,8 @@ def main(args): # pylint: disable=redefined-outer-name
|
|||
best_loss = torch.load(args.best_path,
|
||||
map_location='cpu')['model_loss']
|
||||
print(f" > Starting with loaded last best loss {best_loss}.")
|
||||
keep_best = c.get('keep_best', False)
|
||||
keep_after = c.get('keep_after', 10000) # void if keep_best False
|
||||
keep_all_best = c.get('keep_all_best', False)
|
||||
keep_after = c.get('keep_after', 10000) # void if keep_all_best False
|
||||
|
||||
global_step = args.restore_step
|
||||
for epoch in range(0, c.epochs):
|
||||
|
@ -450,7 +450,7 @@ def main(args): # pylint: disable=redefined-outer-name
|
|||
global_step,
|
||||
epoch,
|
||||
OUT_PATH,
|
||||
keep_best=keep_best,
|
||||
keep_all_best=keep_all_best,
|
||||
keep_after=keep_after,
|
||||
model_losses=eval_avg_loss_dict,
|
||||
scaler=scaler.state_dict() if c.mixed_precision else None
|
||||
|
|
|
@ -121,8 +121,8 @@
|
|||
"print_eval": false, // If True, it prints intermediate loss values in evalulation.
|
||||
"save_step": 10000, // Number of training steps expected to save traninpg stats and checkpoints.
|
||||
"checkpoint": true, // If true, it saves checkpoints per "save_step"
|
||||
"keep_best": false, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_best is true
|
||||
"keep_all_best": false, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_all_best is true
|
||||
"tb_model_param_stats": false, // true, plots param stats per layer on tensorboard. Might be memory consuming, but good for debugging.
|
||||
|
||||
// DATA LOADING
|
||||
|
|
|
@ -93,8 +93,8 @@
|
|||
"print_eval": false, // If True, it prints intermediate loss values in evalulation.
|
||||
"save_step": 5000, // Number of training steps expected to save traninpg stats and checkpoints.
|
||||
"checkpoint": true, // If true, it saves checkpoints per "save_step"
|
||||
"keep_best": false, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_best is true
|
||||
"keep_all_best": false, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_all_best is true
|
||||
"tb_model_param_stats": false, // true, plots param stats per layer on tensorboard. Might be memory consuming, but good for debugging.
|
||||
"apex_amp_level": null,
|
||||
|
||||
|
|
|
@ -105,8 +105,8 @@
|
|||
"print_eval": false, // If True, it prints intermediate loss values in evalulation.
|
||||
"save_step": 5000, // Number of training steps expected to save traninpg stats and checkpoints.
|
||||
"checkpoint": true, // If true, it saves checkpoints per "save_step"
|
||||
"keep_best": false, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_best is true
|
||||
"keep_all_best": false, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_all_best is true
|
||||
"tb_model_param_stats": false, // true, plots param stats per layer on tensorboard. Might be memory consuming, but good for debugging.
|
||||
|
||||
// DATA LOADING
|
||||
|
|
|
@ -121,8 +121,8 @@
|
|||
"print_eval": false, // If True, it prints intermediate loss values in evalulation.
|
||||
"save_step": 10000, // Number of training steps expected to save traninpg stats and checkpoints.
|
||||
"checkpoint": true, // If true, it saves checkpoints per "save_step"
|
||||
"keep_best": false, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_best is true
|
||||
"keep_all_best": false, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_all_best is true
|
||||
"tb_model_param_stats": false, // true, plots param stats per layer on tensorboard. Might be memory consuming, but good for debugging.
|
||||
|
||||
// DATA LOADING
|
||||
|
|
|
@ -109,8 +109,8 @@
|
|||
"print_eval": false, // If True, it prints intermediate loss values in evalulation.
|
||||
"save_step": 5000, // Number of training steps expected to save traninpg stats and checkpoints.
|
||||
"checkpoint": true, // If true, it saves checkpoints per "save_step"
|
||||
"keep_best": false, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_best is true
|
||||
"keep_all_best": false, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_all_best is true
|
||||
"tb_model_param_stats": false, // true, plots param stats per layer on tensorboard. Might be memory consuming, but good for debugging.:set n
|
||||
"mixed_precision": false,
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ def parse_arguments(argv):
|
|||
return parser.parse_args()
|
||||
|
||||
|
||||
def get_last_models(path):
|
||||
def get_last_checkpoint(path):
|
||||
"""Get latest checkpoint or/and best model in path.
|
||||
|
||||
It is based on globbing for `*.pth.tar` and the RegEx
|
||||
|
@ -144,7 +144,7 @@ def process_args(args, model_type):
|
|||
if args.continue_path:
|
||||
args.output_path = args.continue_path
|
||||
args.config_path = os.path.join(args.continue_path, "config.json")
|
||||
args.restore_path, best_model = get_last_models(args.continue_path)
|
||||
args.restore_path, best_model = get_last_checkpoint(args.continue_path)
|
||||
if not args.best_path:
|
||||
args.best_path = best_model
|
||||
|
||||
|
|
|
@ -138,8 +138,8 @@
|
|||
"print_eval": false, // If True, it prints loss values for each step in eval run.
|
||||
"save_step": 25000, // Number of training steps expected to plot training stats on TB and save model checkpoints.
|
||||
"checkpoint": true, // If true, it saves checkpoints per "save_step"
|
||||
"keep_best": false, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_best is true
|
||||
"keep_all_best": false, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_all_best is true
|
||||
"tb_model_param_stats": false, // true, plots param stats per layer on tensorboard. Might be memory consuming, but good for debugging.
|
||||
|
||||
// DATA LOADING
|
||||
|
|
|
@ -128,8 +128,8 @@
|
|||
"print_eval": false, // If True, it prints loss values for each step in eval run.
|
||||
"save_step": 25000, // Number of training steps expected to plot training stats on TB and save model checkpoints.
|
||||
"checkpoint": true, // If true, it saves checkpoints per "save_step"
|
||||
"keep_best": false, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_best is true
|
||||
"keep_all_best": false, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_all_best is true
|
||||
"tb_model_param_stats": false, // true, plots param stats per layer on tensorboard. Might be memory consuming, but good for debugging.
|
||||
|
||||
// DATA LOADING
|
||||
|
|
|
@ -141,8 +141,8 @@
|
|||
"print_eval": false, // If True, it prints loss values for each step in eval run.
|
||||
"save_step": 25000, // Number of training steps expected to plot training stats on TB and save model checkpoints.
|
||||
"checkpoint": true, // If true, it saves checkpoints per "save_step"
|
||||
"keep_best": false, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_best is true
|
||||
"keep_all_best": false, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_all_best is true
|
||||
"tb_model_param_stats": false, // true, plots param stats per layer on tensorboard. Might be memory consuming, but good for debugging.
|
||||
|
||||
// DATA LOADING
|
||||
|
|
|
@ -130,8 +130,8 @@
|
|||
"print_eval": false, // If True, it prints loss values for each step in eval run.
|
||||
"save_step": 25000, // Number of training steps expected to plot training stats on TB and save model checkpoints.
|
||||
"checkpoint": true, // If true, it saves checkpoints per "save_step"
|
||||
"keep_best": false, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_best is true
|
||||
"keep_all_best": false, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_all_best is true
|
||||
"tb_model_param_stats": false, // true, plots param stats per layer on tensorboard. Might be memory consuming, but good for debugging.
|
||||
|
||||
// DATA LOADING
|
||||
|
|
|
@ -124,8 +124,8 @@
|
|||
"print_eval": false, // If True, it prints loss values for each step in eval run.
|
||||
"save_step": 25000, // Number of training steps expected to plot training stats on TB and save model checkpoints.
|
||||
"checkpoint": true, // If true, it saves checkpoints per "save_step"
|
||||
"keep_best": false, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_best is true
|
||||
"keep_all_best": false, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_all_best is true
|
||||
"tb_model_param_stats": false, // true, plots param stats per layer on tensorboard. Might be memory consuming, but good for debugging.
|
||||
|
||||
// DATA LOADING
|
||||
|
|
|
@ -103,8 +103,8 @@
|
|||
"print_eval": false, // If True, it prints loss values for each step in eval run.
|
||||
"save_step": 5000, // Number of training steps expected to plot training stats on TB and save model checkpoints.
|
||||
"checkpoint": true, // If true, it saves checkpoints per "save_step"
|
||||
"keep_best": false, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_best is true
|
||||
"keep_all_best": false, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_all_best is true
|
||||
"tb_model_param_stats": true, // true, plots param stats per layer on tensorboard. Might be memory consuming, but good for debugging.
|
||||
|
||||
// DATA LOADING
|
||||
|
|
|
@ -89,8 +89,8 @@
|
|||
"print_eval": false, // If True, it prints loss values for each step in eval run.
|
||||
"save_step": 25000, // Number of training steps expected to plot training stats on TB and save model checkpoints.
|
||||
"checkpoint": true, // If true, it saves checkpoints per "save_step"
|
||||
"keep_best": false, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_best is true
|
||||
"keep_all_best": false, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_all_best is true
|
||||
"tb_model_param_stats": false, // true, plots param stats per layer on tensorboard. Might be memory consuming, but good for debugging.
|
||||
|
||||
// DATA LOADING
|
||||
|
|
|
@ -64,7 +64,7 @@ def save_checkpoint(model, optimizer, scheduler, model_disc, optimizer_disc,
|
|||
|
||||
def save_best_model(current_loss, best_loss, model, optimizer, scheduler,
|
||||
model_disc, optimizer_disc, scheduler_disc, current_step,
|
||||
epoch, out_path, keep_best=False, keep_after=10000,
|
||||
epoch, out_path, keep_all_best=False, keep_after=10000,
|
||||
**kwargs):
|
||||
if current_loss < best_loss:
|
||||
best_model_name = f'best_model_{current_step}.pth.tar'
|
||||
|
@ -82,7 +82,7 @@ def save_best_model(current_loss, best_loss, model, optimizer, scheduler,
|
|||
model_loss=current_loss,
|
||||
**kwargs)
|
||||
# only delete previous if current is saved successfully
|
||||
if not keep_best or (current_step < keep_after):
|
||||
if not keep_all_best or (current_step < keep_after):
|
||||
model_names = glob.glob(
|
||||
os.path.join(out_path, 'best_model*.pth.tar'))
|
||||
for model_name in model_names:
|
||||
|
|
|
@ -106,8 +106,8 @@
|
|||
"print_eval": false, // If True, it prints intermediate loss values in evalulation.
|
||||
"save_step": 5000, // Number of training steps expected to save traninpg stats and checkpoints.
|
||||
"checkpoint": true, // If true, it saves checkpoints per "save_step"
|
||||
"keep_best": true, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_best is true
|
||||
"keep_all_best": true, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_all_best is true
|
||||
"tb_model_param_stats": false, // true, plots param stats per layer on tensorboard. Might be memory consuming, but good for debugging.
|
||||
"apex_amp_level": null,
|
||||
|
||||
|
|
|
@ -111,8 +111,8 @@
|
|||
"print_eval": false, // If True, it prints intermediate loss values in evalulation.
|
||||
"save_step": 5000, // Number of training steps expected to save traninpg stats and checkpoints.
|
||||
"checkpoint": true, // If true, it saves checkpoints per "save_step"
|
||||
"keep_best": true, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_best is true
|
||||
"keep_all_best": true, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_all_best is true
|
||||
"tb_model_param_stats": false, // true, plots param stats per layer on tensorboard. Might be memory consuming, but good for debugging.:set n
|
||||
"mixed_precision": false,
|
||||
|
||||
|
|
|
@ -122,8 +122,8 @@
|
|||
"print_eval": false, // If True, it prints intermediate loss values in evalulation.
|
||||
"save_step": 10000, // Number of training steps expected to save traninpg stats and checkpoints.
|
||||
"checkpoint": true, // If true, it saves checkpoints per "save_step"
|
||||
"keep_best": true, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_best is true
|
||||
"keep_all_best": true, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_all_best is true
|
||||
"tb_model_param_stats": false, // true, plots param stats per layer on tensorboard. Might be memory consuming, but good for debugging.
|
||||
|
||||
// DATA LOADING
|
||||
|
|
|
@ -131,8 +131,8 @@
|
|||
"print_eval": false, // If True, it prints loss values for each step in eval run.
|
||||
"save_step": 25000, // Number of training steps expected to plot training stats on TB and save model checkpoints.
|
||||
"checkpoint": true, // If true, it saves checkpoints per "save_step"
|
||||
"keep_best": true, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_best is true
|
||||
"keep_all_best": true, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_all_best is true
|
||||
"tb_model_param_stats": false, // true, plots param stats per layer on tensorboard. Might be memory consuming, but good for debugging.
|
||||
|
||||
// DATA LOADING
|
||||
|
|
|
@ -101,8 +101,8 @@
|
|||
"print_eval": false, // If True, it prints loss values for each step in eval run.
|
||||
"save_step": 10000, // Number of training steps expected to plot training stats on TB and save model checkpoints.
|
||||
"checkpoint": true, // If true, it saves checkpoints per "save_step"
|
||||
"keep_best": true, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_best is true
|
||||
"keep_all_best": true, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_all_best is true
|
||||
"tb_model_param_stats": true, // true, plots param stats per layer on tensorboard. Might be memory consuming, but good for debugging.
|
||||
|
||||
// DATA LOADING
|
||||
|
|
|
@ -97,8 +97,8 @@
|
|||
"print_eval": false, // If True, it prints loss values for each step in eval run.
|
||||
"save_step": 25000, // Number of training steps expected to plot training stats on TB and save model checkpoints.
|
||||
"checkpoint": true, // If true, it saves checkpoints per "save_step"
|
||||
"keep_best": true, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_best is true
|
||||
"keep_all_best": true, // If true, keeps all best_models after keep_after steps
|
||||
"keep_after": 10000, // Global step after which to keep best models if keep_all_best is true
|
||||
"tb_model_param_stats": false, // true, plots param stats per layer on tensorboard. Might be memory consuming, but good for debugging.
|
||||
|
||||
// DATA LOADING
|
||||
|
|
Loading…
Reference in New Issue