-
Notifications
You must be signed in to change notification settings - Fork 4
/
csv_record.py
70 lines (57 loc) · 2.62 KB
/
csv_record.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import csv
import copy
train_fileHeader = ["local_model", "flr", "average_loss", "accuracy", "correct_data",
"total_data"]
# train_fileHeader = ["local_model", "round", "epoch", "internal_epoch", "average_loss", "accuracy", "correct_data",
# "total_data"]
# test_fileHeader = ["model", "flr", "average_loss", "accuracy", "correct_data", "total_data"]
test_fileHeader = ["model", "flr", "avg_clean_loss", "avg_poison_loss", "avg_clean_acc", "avg_poison_acc"]
train_result = [] # train_fileHeader
test_result = [] # test_fileHeader
posiontest_result = [] # test_fileHeader
triggertest_fileHeader = ["model", "flr", "average_loss", "accuracy", "correct_data",
"total_data"]
poisontriggertest_result = [] # triggertest_fileHeader
posion_test_result = [] # train_fileHeader
posion_posiontest_result = [] # train_fileHeader
weight_result=[]
scale_result=[]
scale_temp_one_row=[]
def save_result_csv(epoch, is_posion, folder_path):
train_csvFile = open(f'{folder_path}/train_result.csv', "w")
train_writer = csv.writer(train_csvFile)
train_writer.writerow(train_fileHeader)
train_writer.writerows(train_result)
train_csvFile.close()
test_csvFile = open(f'{folder_path}/test_result.csv', "w")
test_writer = csv.writer(test_csvFile)
test_writer.writerow(test_fileHeader)
test_writer.writerows(test_result)
test_csvFile.close()
# if len(weight_result)>0:
# weight_csvFile= open(f'{folder_path}/weight_result.csv', "w")
# weight_writer = csv.writer(weight_csvFile)
# weight_writer.writerows(weight_result)
# weight_csvFile.close()
# if len(scale_temp_one_row)>0:
# _csvFile= open(f'{folder_path}/scale_result.csv', "w")
# _writer = csv.writer(_csvFile)
# scale_result.append(copy.deepcopy(scale_temp_one_row))
# scale_temp_one_row.clear()
# _writer.writerows(scale_result)
# _csvFile.close()
# if is_posion:
# test_csvFile = open(f'{folder_path}/posiontest_result.csv', "w")
# test_writer = csv.writer(test_csvFile)
# test_writer.writerow(test_fileHeader)
# test_writer.writerows(posiontest_result)
# test_csvFile.close()
# test_csvFile = open(f'{folder_path}/poisontriggertest_result.csv', "w")
# test_writer = csv.writer(test_csvFile)
# test_writer.writerow(triggertest_fileHeader)
# test_writer.writerows(poisontriggertest_result)
# test_csvFile.close()
def add_weight_result(name,weight,alpha):
weight_result.append(name)
weight_result.append(weight)
weight_result.append(alpha)