Added a loss_saver file to save the losses
This commit is contained in:
16
Project_Model/Libs/Training/loss_saver.py
Normal file
16
Project_Model/Libs/Training/loss_saver.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import os
|
||||
|
||||
class Log:
|
||||
def __init__(self, path):
|
||||
self.path = path
|
||||
header = ["avg_txt","avg_enc","avg_dec","txt_loss","masking_loss","prediction_loss"]
|
||||
|
||||
with open(self.path, "w", encoding="utf-8", newline="") as f:
|
||||
f.write(",".join(header) + "\n")
|
||||
|
||||
def write(self, loss: list[float]):
|
||||
line = ",".join(str(float(x)) for x in loss) + "\n"
|
||||
with open(self.path, "a", encoding="utf-8", newline="") as f:
|
||||
f.write(line)
|
||||
f.flush()
|
||||
os.fsync(f.fileno()) # extra durability per write # suggested against sudden crashes since it will be done
|
||||
Reference in New Issue
Block a user