import os import sys def generate_unique_logpath(logdir, raw_run_name): i = 0 while(True): run_name = raw_run_name + "_" + str(i) log_path = os.path.join(logdir, run_name) if not os.path.isdir(log_path): return log_path i = i + 1 def create_unique_logpath(top_logdir, raw_run_name): if not os.path.exists(top_logdir): os.mkdir(top_logdir) logdir = generate_unique_logpath(top_logdir, raw_run_name) os.mkdir(logdir) return logdir, raw_run_name def write_summary(logdir, model, optimizer, val_loss): summary_file = open(logdir + "/summary.txt", 'w') summary_text = """ Validation loss =============== {} Executed command ================ {} Dataset ======= FashionMNIST Model summary ============= {} {} trainable parameters Optimizer ======== {} """.format(val_loss," ".join(sys.argv), model, sum(p.numel() for p in model.parameters() if p.requires_grad), optimizer) summary_file.write(summary_text) summary_file.close()