Commit 13a20f51 authored by Colleen Beaumard's avatar Colleen Beaumard
Browse files

Correction of a line

parent 0ac91958
......@@ -52,6 +52,10 @@ ses_nb = args.session_test
labels = list(args.emotions.split(" "))
nb_batch = str(args.batchs)
model_type = args.model
if "(" in model_type:
model_type, model_2nd = model_type.split("(")[0], "_(" + model_type.split("(")[1]
else:
model_2nd = ""
lr = str(args.lr)
cates = str(args.categories)
if args.freeze is not None:
......@@ -158,9 +162,9 @@ valid_loss = [line for line in file if "Validation Loss" in line]
# "Loss:" and "Epoch" in same line
if model_type == "custom":
loss_epoch = [line for line in file if "Epoch" in line]
loss_epoch = loss_epoch[::2]
loss_epoch = loss_epoch[::4] # 2 because only 1 gpu used: if more gpus are used, you have to do 2*nb_gpus
else:
loss_epoch = [line for line in file if "Epoch" in line][2:]
loss_epoch = [line for line in file if "Epoch" in line]
reduce_lr = [line for line in file if "reducing" in line] # Can be empty
......@@ -181,7 +185,10 @@ for e, t, v in zip(aepoch, tloss, vloss):
print("Epoch:", e, "\ttrain loss:", t, "\tvalid loss:", v)
### Plotting of confusion matrix and losses ###
path = "model_{}/Sess{}_test/{}emo_{}batch_lr-{}{}".format(model_type, ses_nb, cates, nb_batch, lr, freeze)
if model_type == "custom":
path = "model_{}/Sess{}_test/{}/{}emo_{}batch_lr-{}{}".format(model_type, ses_nb, model_2nd[2:-2] ,cates, nb_batch, lr, freeze)
else:
path = "model_{}/Sess{}_test/{}emo_{}batch_lr-{}{}".format(model_type, ses_nb, cates, nb_batch, lr, freeze)
if not os.path.isdir(path.rsplit("/", 1)[0]):
os.mkdir(path.rsplit("/", 1)[0])
if not os.path.isdir(path):
......@@ -189,12 +196,12 @@ if not os.path.isdir(path):
# Plot confusion matrice
sns.heatmap(confMatrix, annot=annot, fmt="10", cmap="Blues", vmin=0, vmax=350, xticklabels=labels, yticklabels=labels)
plt.title("Model: " + str(config["model_archi"]["model_type"]) + "{}_".format(freeze) + str(config["speaker_number"]) +
plt.title("Model: {}{}{}_".format(model_type, model_2nd[1:], freeze) + str(config["speaker_number"]) +
"emo_{}batch\nepoch: {} lr: {} Data: Test-IEMOCAP {}".format(nb_batch, aepoch[-1], lr, ses_nb) +
" UAR = " + str(UARPercent) + "%")
plt.xlabel("Prediction")
plt.ylabel("Ground truth")
plt.savefig(os.path.join(path, "confusion_matrix_{}{}_".format(model_type, freeze) + str(config["speaker_number"]) +
plt.savefig(os.path.join(path, "confusion_matrix_{}{}_".format(model_type, model_2nd[2:-2], freeze) + str(config["speaker_number"]) +
"emo_{}batch_epoch-{}_lr-{}_Test-IEMOCAP{}.png".format(nb_batch, aepoch[-1], lr, ses_nb)))
plt.show()
plt.clf()
......@@ -216,10 +223,10 @@ if len(reduce_lr) != 0:
plt.axvline(x=key, color=colors[i], linestyle='--', label=label)
i += 1
plt.legend()
plt.title("Model: {}{}_{}emo_{}batch\nEpoch: {} lr: {} Data: Test-IEMOCAP {}".format(model_type, freeze, cates,
plt.title("Model: {}{}{}_{}emo_{}batch\nEpoch: {} lr: {} Data: Test-IEMOCAP {}".format(model_type, model_2nd[1:], freeze, cates,
nb_batch, aepoch[-1], lr, ses_nb)
)
plt.savefig(os.path.join(path, "losses_{}{}_{}emo_{}batch_epoch-{}_lr-{}_Test-IEMOCAP{}.png".format(model_type, freeze,
plt.savefig(os.path.join(path, "losses_{}{}{}_{}emo_{}batch_epoch-{}_lr-{}_Test-IEMOCAP{}.png".format(model_type, model_2nd[2:-2], freeze,
cates, nb_batch,
aepoch[-1], lr,
ses_nb)))
......@@ -230,12 +237,12 @@ print("Losses plotted!\n")
### We move confusion matrix and logs to another folder ###
os.replace("model_{}/best_{}_{}emo_{}batch_lr-{}_Test-IEMOCAP{}.pt".format(model_type, model_type, cates, nb_batch, lr,
ses_nb),
os.path.join(path, "best_{}{}_{}emo_{}batch_lr-{}_Test-IEMOCAP{}.pt".format(model_type, freeze, cates,
os.path.join(path, "best_{}{}{}_{}emo_{}batch_lr-{}_Test-IEMOCAP{}.pt".format(model_type, model_2nd[2:-2], freeze, cates,
nb_batch, lr, ses_nb)))
os.replace("model_{}/tmp_{}_{}emo_{}batch_lr-{}_Test-IEMOCAP{}.pt".format(model_type, model_type, cates, nb_batch, lr,
ses_nb),
os.path.join(path, "tmp_{}{}_{}emo_{}batch_lr-{}_Test-IEMOCAP{}.pt".format(model_type, freeze, cates,
os.path.join(path, "tmp_{}{}{}_{}emo_{}batch_lr-{}_Test-IEMOCAP{}.pt".format(model_type, model_2nd[2:-2], freeze, cates,
nb_batch, lr, ses_nb)))
os.replace("logs/{}_{}emo_{}batch_lr-{}_Test-IEMOCAP{}.log".format(model_type, cates, nb_batch, lr, ses_nb),
os.path.join(path, "{}{}_{}emo_{}batch_lr-{}_Test-IEMOCAP{}.log".format(model_type, freeze, cates,
os.path.join(path, "{}{}{}_{}emo_{}batch_lr-{}_Test-IEMOCAP{}.log".format(model_type, model_2nd[2:-2], freeze, cates,
nb_batch, lr, ses_nb)))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment