-
Notifications
You must be signed in to change notification settings - Fork 1
/
plot_bars_v2.py
228 lines (194 loc) · 9.39 KB
/
plot_bars_v2.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import numpy as np
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
import argparse
from utils import my_bool
def plot_different_models(
path_to_elastic_trainer_resnet50,
path_to_elastic_trainer_vgg16,
path_to_elastic_trainer_mobilenetv2,
path_to_full_training_resnet50,
path_to_full_training_vgg16,
path_to_full_training_mobilenetv2,
path_to_traditional_tl_resnet50,
path_to_traditional_tl_vgg16,
path_to_traditional_tl_mobilenetv2,
path_to_bn_plus_bias_resnet50,
path_to_bn_plus_bias_vgg16,
path_to_bn_plus_bias_mobilenetv2,
figure_id,
figure_name,
):
et_r50 = np.loadtxt(path_to_elastic_trainer_resnet50) # [time(h), accuracy(%)]
et_v16 = np.loadtxt(path_to_elastic_trainer_vgg16)
et_mv2 = np.loadtxt(path_to_elastic_trainer_mobilenetv2)
ft_r50 = np.loadtxt(path_to_full_training_resnet50)
ft_v16 = np.loadtxt(path_to_full_training_vgg16)
ft_mv2 = np.loadtxt(path_to_full_training_mobilenetv2)
ttl_r50 = np.loadtxt(path_to_traditional_tl_resnet50)
ttl_v16 = np.loadtxt(path_to_traditional_tl_vgg16)
ttl_mv2 = np.loadtxt(path_to_traditional_tl_mobilenetv2)
bpb_r50 = np.loadtxt(path_to_bn_plus_bias_resnet50)
bpb_v16 = np.loadtxt(path_to_bn_plus_bias_vgg16)
bpb_mv2 = np.loadtxt(path_to_bn_plus_bias_mobilenetv2)
X = ['ResNet50','VGG16','MobileNetV2']
et = [et_r50[1], et_v16[1], et_mv2[1]]
ft = [ft_r50[1], ft_v16[1], ft_mv2[1]]
ttl = [ttl_r50[1], ttl_v16[1], ttl_mv2[1]]
bpb = [bpb_r50[1], bpb_v16[1], bpb_mv2[1]]
plt.figure(figure_id)
def subcategorybar1(X, vals, width=0.8):
n = len(vals)
_X = np.arange(len(X))
for i in range(n):
plt.bar(_X - width/2. + i/float(n)*width, vals[i],
width=width/float(n), align="edge")
plt.xticks(_X, X)
plt.ylabel('Accuracy (%)', fontdict={'family': 'Arial',
'color': 'black',
'weight': 'bold',
'size': 16,
})
plt.legend(['ElasticTrainer', 'Full training', 'Traditional TL', 'BN+Bias'])
plt.xticks(fontsize=16)
plt.yticks(fontsize=16)
subcategorybar1(X, [et, ft, ttl, bpb])
# plt.show()
plt.savefig(figure_name + '_accuracy.pdf', format="pdf", bbox_inches="tight")
#########
et = [et_r50[0], et_v16[0], et_mv2[0]]
ft = [ft_r50[0], ft_v16[0], ft_mv2[0]]
ttl = [ttl_r50[0], ttl_v16[0], ttl_mv2[0]]
bpb = [bpb_r50[0], bpb_v16[0], bpb_mv2[0]]
plt.figure(figure_id)
def subcategorybar2(X, vals, width=0.8):
n = len(vals)
_X = np.arange(len(X))
for i in range(n):
plt.bar(_X - width/2. + i/float(n)*width, vals[i],
width=width/float(n), align="edge")
plt.xticks(_X, X)
plt.ylabel('Wall-clock time (h)', fontdict={'family': 'Arial',
'color': 'black',
'weight': 'bold',
'size': 16,
})
plt.legend(['ElasticTrainer', 'Full training', 'Traditional TL', 'BN+Bias'])
plt.xticks(fontsize=16)
plt.yticks(fontsize=16)
subcategorybar2(X, [et, ft, ttl, bpb])
# plt.show()
plt.savefig(figure_name + '_time.pdf', format="pdf", bbox_inches="tight")
def plot_different_models_ego(
path_to_elastic_trainer_resnet50,
path_to_elastic_trainer_vgg16,
path_to_elastic_trainer_mobilenetv2,
figure_id,
figure_name,
):
et_r50 = np.loadtxt(path_to_elastic_trainer_resnet50) # [time(h), accuracy(%)]
et_v16 = np.loadtxt(path_to_elastic_trainer_vgg16)
et_mv2 = np.loadtxt(path_to_elastic_trainer_mobilenetv2)
X = ['ResNet50','VGG16','MobileNetV2']
et = [et_r50[1], et_v16[1], et_mv2[1]]
plt.figure(figure_id)
def subcategorybar1(X, vals, width=0.8):
n = len(vals)
_X = np.arange(len(X))
for i in range(n):
plt.bar(_X - width/2. + i/float(n)*width, vals[i],
width=width/float(n), align="edge")
plt.xticks(_X, X)
plt.ylabel('Accuracy (%)', fontdict={'family': 'Arial',
'color': 'black',
'weight': 'bold',
'size': 16,
})
# plt.legend(['ElasticTrainer', 'Full training', 'Traditional TL', 'BN+Bias'])
plt.xticks(fontsize=16)
plt.yticks(fontsize=16)
subcategorybar1(X, [et])
# plt.show()
plt.savefig(figure_name + '_accuracy.pdf', format="pdf", bbox_inches="tight")
##########
et = [et_r50[0], et_v16[0], et_mv2[0]]
plt.figure(figure_id + 1)
def subcategorybar2(X, vals, width=0.8):
n = len(vals)
_X = np.arange(len(X))
for i in range(n):
plt.bar(_X - width/2. + i/float(n)*width, vals[i],
width=width/float(n), align="edge")
plt.xticks(_X, X)
plt.ylabel('Wall-clock time (h)', fontdict={'family': 'Arial',
'color': 'black',
'weight': 'bold',
'size': 16,
})
plt.legend(['ElasticTrainer', 'Full training', 'Traditional TL', 'BN+Bias'])
plt.xticks(fontsize=16)
plt.yticks(fontsize=16)
subcategorybar2(X, [et])
# plt.show()
plt.savefig(figure_name + '_time.pdf', format="pdf", bbox_inches="tight")
def main():
parser = argparse.ArgumentParser(description='Plot experiment results as bars')
parser.add_argument('--path_to_elastic_trainer_resnet50', type=str, default='TBD')
parser.add_argument('--path_to_elastic_trainer_vgg16', type=str, default='TBD')
parser.add_argument('--path_to_elastic_trainer_mobilenetv2', type=str, default='TBD')
parser.add_argument('--path_to_full_training_resnet50', type=str, default='TBD')
parser.add_argument('--path_to_full_training_vgg16', type=str, default='TBD')
parser.add_argument('--path_to_full_training_mobilenetv2', type=str, default='TBD')
parser.add_argument('--path_to_traditional_tl_resnet50', type=str, default='TBD')
parser.add_argument('--path_to_traditional_tl_vgg16', type=str, default='TBD')
parser.add_argument('--path_to_traditional_tl_mobilenetv2', type=str, default='TBD')
parser.add_argument('--path_to_bn_plus_bias_resnet50', type=str, default='TBD')
parser.add_argument('--path_to_bn_plus_bias_vgg16', type=str, default='TBD')
parser.add_argument('--path_to_bn_plus_bias_mobilenetv2', type=str, default='TBD')
parser.add_argument('--figure_id', type=int, default=1, help='figure id')
parser.add_argument('--figure_name', type=str, default='TBD', help='figure name')
parser.add_argument('--ego', type=my_bool, default=False, help='Whether to exclude baseline schemes')
args = parser.parse_args()
path_to_elastic_trainer_resnet50 = args.path_to_elastic_trainer_resnet50
path_to_elastic_trainer_vgg16 = args.path_to_elastic_trainer_vgg16
path_to_elastic_trainer_mobilenetv2 = args.path_to_elastic_trainer_mobilenetv2
path_to_full_training_resnet50 = args.path_to_full_training_resnet50
path_to_full_training_vgg16 = args.path_to_full_training_vgg16
path_to_full_training_mobilenetv2 = args.path_to_full_training_mobilenetv2
path_to_traditional_tl_resnet50 = args.path_to_traditional_tl_resnet50
path_to_traditional_tl_vgg16 = args.path_to_traditional_tl_vgg16
path_to_traditional_tl_mobilenetv2 = args.path_to_traditional_tl_mobilenetv2
path_to_bn_plus_bias_resnet50 = args.path_to_bn_plus_bias_resnet50
path_to_bn_plus_bias_vgg16 = args.path_to_bn_plus_bias_vgg16
path_to_bn_plus_bias_mobilenetv2 = args.path_to_bn_plus_bias_mobilenetv2
figure_id = args.figure_id
figure_name = args.figure_name
ego = args.ego
if ego:
plot_different_models_ego(
'logs/' + path_to_elastic_trainer_resnet50 + '.txt',
'logs/' + path_to_elastic_trainer_vgg16 + '.txt',
'logs/' + path_to_elastic_trainer_mobilenetv2 + '.txt',
figure_id,
'figures/' + figure_name,
)
else:
plot_different_models(
'logs/' + path_to_elastic_trainer_resnet50 + '.txt',
'logs/' + path_to_elastic_trainer_vgg16 + '.txt',
'logs/' + path_to_elastic_trainer_mobilenetv2 + '.txt',
'logs/' + path_to_full_training_resnet50 + '.txt',
'logs/' + path_to_full_training_vgg16 + '.txt',
'logs/' + path_to_full_training_mobilenetv2 + '.txt',
'logs/' + path_to_traditional_tl_resnet50 + '.txt',
'logs/' + path_to_traditional_tl_vgg16 + '.txt',
'logs/' + path_to_traditional_tl_mobilenetv2 + '.txt',
'logs/' + path_to_bn_plus_bias_resnet50 + '.txt',
'logs/' + path_to_bn_plus_bias_vgg16 + '.txt',
'logs/' + path_to_bn_plus_bias_mobilenetv2 + '.txt',
figure_id,
'figures/' + figure_name,
)
if __name__ == '__main__':
main()