-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathplot_cifar100.py
242 lines (210 loc) · 14.7 KB
/
plot_cifar100.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
236
237
238
239
240
241
242
import numpy as np
import matplotlib.pyplot as plt
import sys, os
from lib.config import cfg
if sys.version_info[0] == 2:
import cPickle as pickle
else:
import pickle
def plot_accuracies(data, title='Accuracy Plot', plot_type='Accuracy', x_axis_label='Epochs',save_location=None, mode='Test'):
"""
This helper function can be used to plot(visualize) the accuracies saved using lib.utils.save_accuracies()
:return: None
"""
plt.tick_params(direction='out', length=6, width=2)
if(save_location==None):
save_location = './final_plots/cifar100/'
if not os.path.exists(save_location):
os.makedirs(save_location)
for (i,info) in enumerate(data):
with open(info[0], 'rb') as f:
acc = pickle.load(f)
_plot_indiv_accuracies(acc, color=info[2], label=info[1], plot_type=plot_type)
if(info[1]=='SGD'):
with open(info[3], 'rb') as f:
upper_limit = pickle.load(f)
with open(info[4], 'rb') as f:
lower_limit = pickle.load(f)
x = np.arange(1, len(acc) + 1)
if(plot_type=="Accuracy"):
lower_limit = 100-lower_limit
upper_limit = 100-upper_limit
plt.fill_between(x, lower_limit, upper_limit, color='lightskyblue')
size = 15
plt.legend(fontsize=size)
# if title is not None:
# plt.title(title)
plt.xlabel(x_axis_label,fontsize=size)
plt.grid(True, linestyle='--', axis='y')
# plt.xticks(np.arange(0, 101, step=20))
if plot_type == 'Accuracy':
plt.yticks(np.arange(0, 110, step=10))
if (mode == 'Test'):
plt.ylabel('Test Error',fontsize=size)
elif (mode == 'Train'):
plt.ylabel('Train Error',fontsize=size)
plt.ylim([35,70])
else:
# plt.yticks(np.arange(0, 2, step=0.5))
if (mode == 'Test'):
plt.ylabel('Test Loss',fontsize=size)
elif (mode == 'Train'):
plt.ylabel('Train Loss',fontsize=size)
plt.ylim([1,4])
plt.savefig(save_location + title.replace(' ', '_').replace('(', '_').replace(')', '_') + '.eps', format='eps')
plt.close()
def _plot_indiv_accuracies(accuracies, color='blue', label='', plot_type=None):
x = np.arange(1, len(accuracies) + 1)
if(plot_type=='Accuracy'):
accuracies = 100 - np.array(accuracies)
plt.plot(x, accuracies, color=color, label=label)
if __name__ == '__main__':
#
# for i in range(1, 61):
# try:
# test_data = [[
# '/home/vamshi/PycharmProjects/SMDL/final_Results/final_SGD_CIFAR_ResNet20_0211_152357/accuracies/test_acc_between_iteration_epoch_' + str(i) + '_accuracy.pkl',
# 'SGD', 'blue'],
# [
# '/home/vamshi/PycharmProjects/SMDL/output/cifar100_resnet32_submodcomb_refresh-5_epochs-60_0203_103925/accuracies/test_acc_between_iteration_epoch_' + str(i) + '_accuracy.pkl',
# 'Submodular Selection', 'green']
# ]
# plot_accuracies(test_data, title='CIFAR100 Epoch ' + str(i) + ' Test Accuracy', x_axis_label='# of iterations (x10)')
# except Exception as error:
# print ('Exception occured for index {}, {}'.format(i, error))
# # CIFAR - 100
# -------------------
test_data = [[
'/home/vamshi/PycharmProjects/SMDL/final_Results/final_SGD_CIFAR_100_ResNet32_0211_152526/accuracies/test_acc_mean_accuracy.pkl',
'SGD', 'blue', '/home/vamshi/PycharmProjects/SMDL/final_Results/final_SGD_CIFAR_100_ResNet32_0211_152526/accuracies/test_acc_upper_limit_accuracy.pkl',
'/home/vamshi/PycharmProjects/SMDL/final_Results/final_SGD_CIFAR_100_ResNet32_0211_152526/accuracies/test_acc_lower_limit_accuracy.pkl'],
[
'/home/vamshi/PycharmProjects/SMDL/final_Results/final_SGD_CIFAR_100_ResNet32_0211_152526/accuracies/test_acc_round_0_accuracy.pkl',
'LOSS', 'darkviolet'],
[
'/home/vamshi/PycharmProjects/SMDL/final_Results/fix_SMDL_CIFAR_100_ResNet32_0215_182025/accuracies/test_acc_round_0_accuracy.pkl',
'SMDL', 'green']
]
plot_accuracies(test_data, title='CIFAR 100 Test Accuracy (Main)')
train_data = [[
'/home/vamshi/PycharmProjects/SMDL/final_Results/final_SGD_CIFAR_100_ResNet32_0211_152526/accuracies/train_acc_mean_accuracy.pkl',
'SGD', 'blue', '/home/vamshi/PycharmProjects/SMDL/final_Results/final_SGD_CIFAR_100_ResNet32_0211_152526/accuracies/train_acc_upper_limit_accuracy.pkl',
'/home/vamshi/PycharmProjects/SMDL/final_Results/final_SGD_CIFAR_100_ResNet32_0211_152526/accuracies/train_acc_lower_limit_accuracy.pkl'],
[
'/home/vamshi/PycharmProjects/SMDL/final_Results/final_SGD_CIFAR_100_ResNet32_0211_152526/accuracies/train_acc_round_0_accuracy.pkl',
'LOSS', 'darkviolet'],
[
'/home/vamshi/PycharmProjects/SMDL/final_Results/fix_SMDL_CIFAR_100_ResNet32_0215_182025/accuracies/train_acc_round_0_accuracy.pkl',
'SMDL', 'green']
]
plot_accuracies(train_data, title='CIFAR 100 Train Accuracy (Main)')
test_loss_data = [[
'/home/vamshi/PycharmProjects/SMDL/final_Results/final_SGD_CIFAR_100_ResNet32_0211_152526/accuracies/test_loss_mean_accuracy.pkl',
'SGD', 'blue', '/home/vamshi/PycharmProjects/SMDL/final_Results/final_SGD_CIFAR_100_ResNet32_0211_152526/accuracies/test_loss_upper_limit_accuracy.pkl',
'/home/vamshi/PycharmProjects/SMDL/final_Results/final_SGD_CIFAR_100_ResNet32_0211_152526/accuracies/test_loss_lower_limit_accuracy.pkl'],
[
'/home/vamshi/PycharmProjects/SMDL/final_Results/final_SGD_CIFAR_100_ResNet32_0211_152526/accuracies/test_loss_round_0_accuracy.pkl',
'LOSS', 'darkviolet'],
[
'/home/vamshi/PycharmProjects/SMDL/final_Results/fix_SMDL_CIFAR_100_ResNet32_0215_182025/accuracies/test_loss_round_0_accuracy.pkl',
'SMDL', 'green']
]
plot_accuracies(test_loss_data, title='CIFAR 100 Test Loss (Main)', plot_type='Loss')
train_loss_data = [[
'/home/vamshi/PycharmProjects/SMDL/final_Results/final_SGD_CIFAR_100_ResNet32_0211_152526/accuracies/train_loss_mean_accuracy.pkl',
'SGD', 'blue', '/home/vamshi/PycharmProjects/SMDL/final_Results/final_SGD_CIFAR_100_ResNet32_0211_152526/accuracies/train_loss_upper_limit_accuracy.pkl',
'/home/vamshi/PycharmProjects/SMDL/final_Results/final_SGD_CIFAR_100_ResNet32_0211_152526/accuracies/train_loss_lower_limit_accuracy.pkl'],
[
'/home/vamshi/PycharmProjects/SMDL/final_Results/final_SGD_CIFAR_100_ResNet32_0211_152526/accuracies/test_loss_round_0_accuracy.pkl',
'LOSS', 'darkviolet'],
[
'/home/vamshi/PycharmProjects/SMDL/final_Results/fix_SMDL_CIFAR_100_ResNet32_0215_182025/accuracies/test_loss_round_0_accuracy.pkl',
'SMDL', 'green']
]
plot_accuracies(train_loss_data, title='CIFAR 100 Train Loss (Main)', plot_type='Loss')
############## ablations ###############
########## refresh rate ##############
test_data = [[
'/home/vamshi/PycharmProjects/SMDL/final_Results/final_SGD_CIFAR_100_ResNet32_0211_152526/accuracies/test_acc_mean_accuracy.pkl',
'Random Selection', 'blue', '/home/vamshi/PycharmProjects/SMDL/final_Results/final_SGD_CIFAR_100_ResNet32_0211_152526/accuracies/test_acc_upper_limit_accuracy.pkl',
'/home/vamshi/PycharmProjects/SMDL/final_Results/final_SGD_CIFAR_100_ResNet32_0211_152526/accuracies/test_acc_lower_limit_accuracy.pkl'],
[
'/home/vamshi/PycharmProjects/SMDL/final_Results/fix_SMDL_CIFAR_100_ResNet32_0215_182025/accuracies/test_acc_round_0_accuracy.pkl',
'SMDL Refresh Rate-5', 'green'],
[
'/home/vamshi/PycharmProjects/SMDL/final_Results/final_SMDL_CIFAR_100_ResNet32_Refresh10_0212_123549/accuracies/test_acc_round_0_accuracy.pkl',
'SMDL Refresh Rate-10', 'orange'],
[
'/home/vamshi/PycharmProjects/SMDL/final_Results/final_SMDL_CIFAR_100_ResNet32_Refresh25_0212_123328/accuracies/test_acc_round_0_accuracy.pkl',
'SMDL Refresh Rate-25', 'm'],
[
'/home/vamshi/PycharmProjects/SMDL/final_Results/final_SMDL_CIFAR100_ResNet32_refresh40_0221_223728/accuracies/test_acc_round_0_accuracy.pkl',
'SMDL Refresh Rate-40', 'black'],
# [
# '/home/vamshi/PycharmProjects/SMDL/final_Results/final_SMDL_CIFAR_100_ResNet32_Refresh50_0212_123140/accuracies/test_acc_round_0_accuracy.pkl',
# 'SMDL Refresh Rate-50', 'black']
]
plot_accuracies(test_data, title='CIFAR 100 Test Error with RF Ablation', save_location='./final_plots/cifar100/Refresh/')
train_data = [[
'/home/vamshi/PycharmProjects/SMDL/final_Results/final_SGD_CIFAR_100_ResNet32_0211_152526/accuracies/train_acc_mean_accuracy.pkl',
'Random Selection', 'blue', '/home/vamshi/PycharmProjects/SMDL/final_Results/final_SGD_CIFAR_100_ResNet32_0211_152526/accuracies/train_acc_upper_limit_accuracy.pkl',
'/home/vamshi/PycharmProjects/SMDL/final_Results/final_SGD_CIFAR_100_ResNet32_0211_152526/accuracies/train_acc_lower_limit_accuracy.pkl'],
[
'/home/vamshi/PycharmProjects/SMDL/final_Results/fix_SMDL_CIFAR_100_ResNet32_0215_182025/accuracies/train_acc_round_0_accuracy.pkl',
'SMDL Refresh Rate-5', 'green'],
[
'/home/vamshi/PycharmProjects/SMDL/final_Results/final_SMDL_CIFAR_100_ResNet32_Refresh10_0212_123549/accuracies/train_acc_round_0_accuracy.pkl',
'SMDL Refresh Rate-10', 'orange'],
[
'/home/vamshi/PycharmProjects/SMDL/final_Results/final_SMDL_CIFAR_100_ResNet32_Refresh25_0212_123328/accuracies/train_acc_round_0_accuracy.pkl',
'SMDL Refresh Rate-25', 'm'],
[
'/home/vamshi/PycharmProjects/SMDL/final_Results/final_SMDL_CIFAR100_ResNet32_refresh40_0221_223728/accuracies/train_acc_round_0_accuracy.pkl',
'SMDL Refresh Rate-40', 'black'],
# [
# '/home/vamshi/PycharmProjects/SMDL/final_Results/final_SMDL_CIFAR_100_ResNet32_Refresh50_0212_123140/accuracies/train_acc_round_0_accuracy.pkl',
# 'SMDL Refresh Rate-50', 'black']
]
plot_accuracies(train_data, title='CIFAR 100 Train Error with RF Ablation', save_location='./final_plots/cifar100/Refresh/')
test_loss_data = [[
'/home/vamshi/PycharmProjects/SMDL/final_Results/final_SGD_CIFAR_100_ResNet32_0211_152526/accuracies/test_loss_mean_accuracy.pkl',
'Random Selection', 'blue', '/home/vamshi/PycharmProjects/SMDL/final_Results/final_SGD_CIFAR_100_ResNet32_0211_152526/accuracies/test_loss_upper_limit_accuracy.pkl',
'/home/vamshi/PycharmProjects/SMDL/final_Results/final_SGD_CIFAR_100_ResNet32_0211_152526/accuracies/test_loss_lower_limit_accuracy.pkl'],
[
'/home/vamshi/PycharmProjects/SMDL/final_Results/fix_SMDL_CIFAR_100_ResNet32_0215_182025/accuracies/test_loss_round_0_accuracy.pkl',
'SMDL Refresh Rate-5', 'green'],
[
'/home/vamshi/PycharmProjects/SMDL/final_Results/final_SMDL_CIFAR_100_ResNet32_Refresh10_0212_123549/accuracies/test_loss_round_0_accuracy.pkl',
'SMDL Refresh Rate-10', 'orange'],
[
'/home/vamshi/PycharmProjects/SMDL/final_Results/final_SMDL_CIFAR_100_ResNet32_Refresh25_0212_123328/accuracies/test_loss_round_0_accuracy.pkl',
'SMDL Refresh Rate-25', 'm'],
[
'/home/vamshi/PycharmProjects/SMDL/final_Results/final_SMDL_CIFAR100_ResNet32_refresh40_0221_223728/accuracies/test_loss_round_0_accuracy.pkl',
'SMDL Refresh Rate-40', 'black'],
# [
# '/home/vamshi/PycharmProjects/SMDL/final_Results/final_SMDL_CIFAR_100_ResNet32_Refresh50_0212_123140/accuracies/test_loss_round_0_accuracy.pkl',
# 'SMDL Refresh Rate-50', 'black']
]
plot_accuracies(test_loss_data, title='CIFAR 100 Test Loss with RF Ablation', plot_type='Loss', save_location='./final_plots/cifar100/Refresh/')
train_loss_data = [[
'/home/vamshi/PycharmProjects/SMDL/final_Results/final_SGD_CIFAR_100_ResNet32_0211_152526/accuracies/train_loss_mean_accuracy.pkl',
'Random Selection', 'blue', '/home/vamshi/PycharmProjects/SMDL/final_Results/final_SGD_CIFAR_100_ResNet32_0211_152526/accuracies/train_loss_upper_limit_accuracy.pkl',
'/home/vamshi/PycharmProjects/SMDL/final_Results/final_SGD_CIFAR_100_ResNet32_0211_152526/accuracies/train_loss_lower_limit_accuracy.pkl'],
[
'/home/vamshi/PycharmProjects/SMDL/final_Results/fix_SMDL_CIFAR_100_ResNet32_0215_182025/accuracies/test_loss_round_0_accuracy.pkl',
'SMDL Refresh Rate-5', 'green'],
[
'/home/vamshi/PycharmProjects/SMDL/final_Results/final_SMDL_CIFAR_100_ResNet32_Refresh10_0212_123549/accuracies/test_loss_round_0_accuracy.pkl',
'SMDL Refresh Rate-10', 'orange'],
[
'/home/vamshi/PycharmProjects/SMDL/final_Results/final_SMDL_CIFAR_100_ResNet32_Refresh25_0212_123328/accuracies/test_loss_round_0_accuracy.pkl',
'SMDL Refresh Rate-25', 'm'],
[
'/home/vamshi/PycharmProjects/SMDL/final_Results/final_SMDL_CIFAR100_ResNet32_refresh40_0221_223728/accuracies/test_loss_round_0_accuracy.pkl',
'SMDL Refresh Rate-40', 'black'],
# [
# '/home/vamshi/PycharmProjects/SMDL/final_Results/final_SMDL_CIFAR_100_ResNet32_Refresh50_0212_123140/accuracies/test_loss_round_0_accuracy.pkl',
# 'SMDL Refresh Rate-50', 'black']
]
plot_accuracies(train_loss_data, title='CIFAR 100 Train Loss with RF Ablation', plot_type='Loss', save_location='./final_plots/cifar100/Refresh/')