-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot1.py
82 lines (80 loc) · 2.55 KB
/
plot1.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import os
import matplotlib.pyplot as plt
Fedavg=[]
Fedavgm=[]
FedCnm=[]
Fedprox=[]
scaffold=[]
FedAdam=[]
FedAdam1=[]
logdir="./logs/"
with open(os.path.join(logdir, "fedavg_02-23_12-16.log"), 'r+') as f:
while(1):
str=f.readline()
if not str:
break
if str[24:41:] == "Global Model Test":
Fedavg.append(float(str[52:60:]))
with open(os.path.join(logdir, "fedcnm_02-23_20-56.log"), 'r+') as f:
while (1):
str = f.readline()
if not str:
break
if str[24:41:] == "Global Model Test":
FedCnm.append(float(str[52:60:]))
with open(os.path.join(logdir, "fedprox_02-24_05-54.log"), 'r+') as f:
while (1):
str = f.readline()
if not str:
break
if str[24:41:] == "Global Model Test":
Fedavgm.append(float(str[52:60:]))
with open(os.path.join(logdir, "fedavgm_02-24_16-06.log"), 'r+') as f:
while 1:
str = f.readline()
if not str:
break
if str[24:41:] == "Global Model Test":# state of the art
FedAdam.append(float(str[52:60:]))
with open(os.path.join(logdir, "fedadam_02-25_00-48.log"), 'r+') as f:
while(1):
str=f.readline()
if not str:
break
if str[24:41:] == "Global Model Test":
Fedprox.append(float(str[52:60:]))
with open(os.path.join(logdir, "fedadc_02-26_14-56.log"), 'r+') as f:
while(1):
str=f.readline()
if not str:
break
if str[24:41:]=="Global Model Test":
scaffold.append(float(str[52:60:]))
# with open(os.path.join('./logs/', "domo_11-21_17-06.log"), 'r+') as f:
# while 1:
# str = f.readline()
# if not str:
# break
# if str[24:41:] == "Global Model Test":
# FedAdam1.append(float(str[52:60:]))
print(Fedavg[-5::],len(Fedavg))
print(FedCnm[-5::],len(FedCnm))
print(Fedavgm[-5::],len(Fedavgm))
print(FedAdam[-5::],len(FedAdam))
print(Fedprox[-5::],len(Fedprox))
print(scaffold[-5::],len(scaffold))
print(FedAdam1[-5::],len(FedAdam1))
plt.plot(Fedavg[::],label='fedavgsm')
plt.plot(FedCnm[::],label='fedavg')
plt.plot(Fedavgm[::],label='fedavglm')
plt.plot(FedAdam[::],label='fedavglsm')
plt.plot(Fedprox[::],label='fedcnm')
plt.plot(scaffold[::],label='α=0.99')
plt.plot(FedAdam1[::],label='Fedadam1')
plt.title('CIFAR100 lr=0.1')
plt.grid(True)
plt.axis('tight')
plt.legend(loc=0)
plt.xlabel('Communication Rounds')
plt.ylabel('Test Accuracy')
plt.show()