updates and debugs

This commit is contained in:
Eren Golge
2018-02-13 01:45:52 -08:00
parent dadefb5dbc
commit 56697ac8cf
10 changed files with 121 additions and 63 deletions
+2 -3
View File
@@ -14,9 +14,8 @@ def prepare_data(inputs):
return np.stack([pad_data(x, max_len) for x in inputs])
def pad_per_step(inputs, outputs_per_step):
"""zero pad inputs if it is not divisible with outputs_per_step (r)"""
def pad_per_step(inputs, pad_len):
timesteps = inputs.shape[-1]
return np.pad(inputs, [[0, 0], [0, 0],
[0, outputs_per_step - (timesteps % outputs_per_step)]],
[0, pad_len]],
mode='constant', constant_values=0.0)
+15 -6
View File
@@ -48,7 +48,8 @@ def copy_config_file(config_file, path):
shutil.copyfile(config_file, out_path)
def save_checkpoint(model, model_loss, best_loss, out_path):
def save_checkpoint(model, optimizer, model_loss, best_loss, out_path,
current_step, epoch):
checkpoint_path = 'checkpoint_{}.pth.tar'.format(current_step)
checkpoint_path = os.path.join(out_path, checkpoint_path)
print("\n | > Checkpoint saving : {}".format(checkpoint_path))
@@ -56,16 +57,24 @@ def save_checkpoint(model, model_loss, best_loss, out_path):
'optimizer': optimizer.state_dict(),
'step': current_step,
'epoch': epoch,
'total_loss': loss.data[0],
'linear_loss': linear_loss.data[0],
'mel_loss': mel_loss.data[0],
'linear_loss': model_loss,
'date': datetime.date.today().strftime("%B %d, %Y")}
torch.save(state, checkpoint_path)
def save_best_model(model, optimizer, model_loss, best_loss, out_path,
current_step, epoch):
if model_loss < best_loss:
state = {'model': model.state_dict(),
'optimizer': optimizer.state_dict(),
'step': current_step,
'epoch': epoch,
'linear_loss': model_loss,
'date': datetime.date.today().strftime("%B %d, %Y")}
best_loss = model_loss
bestmodel_path = 'best_model.pth.tar'.format(current_step)
bestmodel_path = 'best_model.pth.tar'
bestmodel_path = os.path.join(out_path, bestmodel_path)
print("\n | > Best model saving with loss {} : {}".format(model_loss, bestmodel_path))
print("\n | > Best model saving with loss {0:.2f} : {1:}".format(model_loss, bestmodel_path))
torch.save(state, bestmodel_path)
return best_loss