diff --git a/lab06_evaluation.py b/lab06_evaluation.py index 2aaddd7..3ac9a14 100644 --- a/lab06_evaluation.py +++ b/lab06_evaluation.py @@ -10,6 +10,7 @@ from sklearn.metrics import accuracy_score, f1_score from csv import DictWriter import torch.nn.functional as F import sys +import os class Model(nn.Module): def __init__(self, input_dim): @@ -52,9 +53,13 @@ def print_metrics(test_labels, predictions): print(f"Build number: {build_number}") field_names = ['BUILD_NUMBER', 'F1', 'ACCURACY'] dict = {'BUILD_NUMBER': build_number, 'F1': f1, 'ACCURACY': accuracy } + filename = "./metrics.csv" + file_exists = os.path.isfile(filename) - with open('metrics.csv', 'a') as metrics_file: + with open(filename, 'a') as metrics_file: dictwriter_object = DictWriter(metrics_file, fieldnames=field_names) + if not file_exists: + dictwriter_object.writeheader() dictwriter_object.writerow(dict) metrics_file.close() except Exception as e: