forked from ryujaehun/pytorch-gpu-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot.py
235 lines (185 loc) · 7.52 KB
/
plot.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
229
230
231
232
233
234
235
import numpy as np
import pandas as pd
import os
import glob
import matplotlib
matplotlib.use('TkAgg')
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator
from collections import namedtuple
def arr_train():
result_path=os.path.join(os.getcwd(),'results')
arr_train=[i for i in glob.glob(result_path+'/*training*.csv')]
arr_train.sort()
return arr_train
def arr_inference():
result_path=os.path.join(os.getcwd(),'results')
arr_inference=[i for i in glob.glob(result_path+'/*inference*.csv')]
arr_inference.sort()
return arr_inference
def total_model(arr,device_name):
model_name=arr[0].split('/')[-1].split('_')[0]
type=arr[0].split('/')[-1].split('_')[3]
n_groups = 15
double=pd.read_csv(arr[0])
half=pd.read_csv(arr[1])
single=pd.read_csv(arr[2])
means_double =double.mean().values
std_double =double.std().values
means_half =half.mean().values
std_half =half.std().values
means_single =single.mean().values
std_single =single.std().values
fig, ax = plt.subplots()
index = np.arange(n_groups)
bar_width = 0.35
opacity = 0.4
error_config = {'ecolor': '0.3'}
rects1 = ax.bar(index, means_double, bar_width,
alpha=opacity, color='b',
yerr=std_double, error_kw=error_config,
label='double')
rects2 = ax.bar(index + bar_width, means_half, bar_width,
alpha=opacity, color='r',
yerr=std_half, error_kw=error_config,
label='half')
rects2 = ax.bar(index + bar_width*2, means_single, bar_width,
alpha=opacity, color='g',
yerr=std_single, error_kw=error_config,
label='single')
ax.set_xlabel('models')
ax.set_ylabel('times(ms)')
ax.set_title("total_"+type+"_"+model_name)
ax.set_xticks(index + bar_width / 2)
ax.set_xticklabels(double.columns,rotation=60, fontsize=9)
ax.legend()
fig.tight_layout()
plt.savefig(device_name+'total.png',dpi=400)
def model_plot(arr,model):
model_name=arr[0].split('/')[-1].split('_')[0]
type=arr[0].split('/')[-1].split('_')[3]
double=pd.read_csv(arr[0])
half=pd.read_csv(arr[1])
single=pd.read_csv(arr[2])
if model.lower() =='densenet':
n_groups = 4
double=double[['densenet121', 'densenet161', 'densenet169', 'densenet201']]
half=half[['densenet121', 'densenet161', 'densenet169', 'densenet201']]
single=single[['densenet121', 'densenet161', 'densenet169', 'densenet201']]
elif model.lower() =='resnet':
n_groups = 5
double=double[['resnet101','resnet152', 'resnet18', 'resnet34', 'resnet50']]
half=half[['resnet101','resnet152', 'resnet18', 'resnet34', 'resnet50']]
single=single[['resnet101','resnet152', 'resnet18', 'resnet34', 'resnet50']]
elif model.lower() =='squeezenet':
n_groups = 2
double=double[['squeezenet1_0','squeezenet1_1']]
half=half[['squeezenet1_0','squeezenet1_1']]
single=single[['squeezenet1_0','squeezenet1_1']]
elif model.lower() =='vgg':
n_groups = 4
double=double[[ 'vgg16', 'vgg16_bn', 'vgg19', 'vgg19_bn']]
half=half[[ 'vgg16', 'vgg16_bn', 'vgg19', 'vgg19_bn']]
single=single[[ 'vgg16', 'vgg16_bn', 'vgg19', 'vgg19_bn']]
else:
raise NotImplementedError("To be implemented")
means_double =double.mean().values
std_double =double.std().values
means_half =half.mean().values
std_half =half.std().values
means_single =single.mean().values
std_single =single.std().values
fig, ax = plt.subplots()
index = np.arange(n_groups)
bar_width = 0.25
opacity = 0.4
error_config = {'ecolor': '0.3'}
rects1 = ax.bar(index, means_double, bar_width,
alpha=opacity, color='b',
yerr=std_double, error_kw=error_config,
label='double')
rects2 = ax.bar(index + bar_width, means_half, bar_width,
alpha=opacity, color='r',
yerr=std_half, error_kw=error_config,
label='half')
rects2 = ax.bar(index + bar_width*2, means_single, bar_width,
alpha=opacity, color='g',
yerr=std_single, error_kw=error_config,
label='single')
ax.set_xlabel('models')
ax.set_ylabel('times(ms)')
ax.set_title(model+'_'+type+"_"+model_name)
ax.set_xticks(index + bar_width / 2)
ax.set_xticklabels(double.columns,rotation=45, fontsize=9)
ax.legend()
fig.tight_layout()
plt.savefig(model+'.png',dpi=300)
def arr_type(arr,type):
arr=[x for x in arr if not '(2)' in x ]
if type == 'single':
temp=[x for x in arr if 'single' in x ]
elif type == 'double':
temp=[x for x in arr if 'double' in x ]
elif type == 'half':
temp=[x for x in arr if 'half' in x ]
return temp
def model_plot2(arr,model):
#model_name=arr[0].split('/')[-1].split('_')[0]
type=arr[0].split('/')[-1].split('_')[3]
ti1080=pd.read_csv(arr[0])
ti2080=pd.read_csv(arr[1])
titan=pd.read_csv(arr[2])
if model.lower() =='densenet':
n_groups = 4
ti1080=ti1080[['densenet121', 'densenet161', 'densenet169', 'densenet201']]
ti2080=ti2080[['densenet121', 'densenet161', 'densenet169', 'densenet201']]
titan=titan[['densenet121', 'densenet161', 'densenet169', 'densenet201']]
elif model.lower() =='resnet':
n_groups = 5
ti1080=ti1080[['resnet101','resnet152', 'resnet18', 'resnet34', 'resnet50']]
ti2080=ti2080[['resnet101','resnet152', 'resnet18', 'resnet34', 'resnet50']]
titan=titan[['resnet101','resnet152', 'resnet18', 'resnet34', 'resnet50']]
elif model.lower() =='squeezenet':
n_groups = 2
ti1080=ti1080[['squeezenet1_0','squeezenet1_1']]
ti2080=ti2080[['squeezenet1_0','squeezenet1_1']]
titan=titan[['squeezenet1_0','squeezenet1_1']]
elif model.lower() =='vgg':
n_groups = 4
ti1080=ti1080[[ 'vgg16', 'vgg16_bn', 'vgg19', 'vgg19_bn']]
ti2080=ti2080[[ 'vgg16', 'vgg16_bn', 'vgg19', 'vgg19_bn']]
titan=titan[[ 'vgg16', 'vgg16_bn', 'vgg19', 'vgg19_bn']]
else:
raise NotImplementedError("To be implemented")
means_double =ti1080.mean().values
std_double =ti1080.std().values
means_half =ti2080.mean().values
std_half =ti2080.std().values
means_single =titan.mean().values
std_single =titan.std().values
fig, ax = plt.subplots()
index = np.arange(n_groups)
bar_width = 0.25
opacity = 0.4
error_config = {'ecolor': '0.3'}
rects1 = ax.bar(index, means_double, bar_width,
alpha=opacity, color='b',
yerr=std_double, error_kw=error_config,
label='1080ti')
rects2 = ax.bar(index + bar_width, means_half, bar_width,
alpha=opacity, color='r',
yerr=std_half, error_kw=error_config,
label='2080ti')
rects2 = ax.bar(index + bar_width*2, means_single, bar_width,
alpha=opacity, color='g',
yerr=std_single, error_kw=error_config,
label='TitanV')
ax.set_xlabel('models')
ax.set_ylabel('times(ms)')
ax.set_title(model+'_'+type)
ax.set_xticks(index + bar_width / 2)
ax.set_xticklabels(ti1080.columns,rotation=45, fontsize=9)
ax.legend()
fig.tight_layout()
plt.savefig(model+'_'+type+'_'+model_name+'.png',dpi=300)