-
Notifications
You must be signed in to change notification settings - Fork 3
/
plot.py
512 lines (478 loc) · 28.3 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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
import matplotlib.pyplot as plt
import numpy as np
import pickle
def smoothing(arr):
newArr = []
smoothing_rate = 0.95
def diff_temperature_cifar100():
known = 20
init = 8
model = "resnet18"
seeds = [1]
max_min_temperature_acc = []
max_min_temperature_precision = []
max_min_temperature_recall = []
min_max_temperature_acc = []
min_max_temperature_precision = []
min_max_temperature_recall = []
max_max_temperature_acc = []
max_max_temperature_precision = []
max_max_temperature_recall = []
min_min_temperature_acc = []
min_min_temperature_precision = []
min_min_temperature_recall = []
min_min_temperature_acc2 = []
min_min_temperature_precision2 = []
min_min_temperature_recall2 = []
mid_mid_temperature_acc = []
mid_mid_temperature_precision = []
mid_mid_temperature_recall = []
min_min_modelB_temperature_acc = []
min_min_modelB_temperature_precision = []
min_min_modelB_temperature_recall = []
min_min_modelB_temperature_acc2 = []
min_min_modelB_temperature_precision2 = []
min_min_modelB_temperature_recall2 = []
for seed in seeds:
with open("log_AL/temperature_"+model+"_cifar100_known"+str(known)+"_init"+str(init)+"_batch1500_seed2_AV_temperature_unknown_T2.0_known_T0.5.pkl", 'rb') as f:
data = pickle.load(f)
max_min_temperature_acc.append([data['Acc'][i] for i in data['Acc']])
max_min_temperature_precision.append([data['Precision'][i] for i in data['Precision']])
max_min_temperature_recall.append([data['Recall'][i] for i in data['Recall']])
f.close()
with open("log_AL/temperature_"+model+"_cifar100_known"+str(known)+"_init"+str(init)+"_batch1500_seed1_AV_temperature_unknown_T0.5_known_T0.5_modelB_T1.0.pkl", 'rb') as f:
data = pickle.load(f)
min_min_temperature_acc.append([data['Acc'][i] for i in data['Acc']])
min_min_temperature_precision.append([data['Precision'][i] for i in data['Precision']])
min_min_temperature_recall.append([data['Recall'][i] for i in data['Recall']])
f.close()
with open("log_AL/temperature_"+model+"_cifar100_known"+str(known)+"_init"+str(init)+"_batch1500_seed1_AV_temperature_unknown_T0.2_known_T0.2.pkl", 'rb') as f:
data = pickle.load(f)
min_min_temperature_acc2.append([data['Acc'][i] for i in data['Acc']])
min_min_temperature_precision2.append([data['Precision'][i] for i in data['Precision']])
min_min_temperature_recall2.append([data['Recall'][i] for i in data['Recall']])
f.close()
with open("log_AL/temperature_"+model+"_cifar100_known"+str(known)+"_init"+str(init)+"_batch1500_seed1_AV_temperature_unknown_T1.0_known_T1.0.pkl", 'rb') as f:
data = pickle.load(f)
mid_mid_temperature_acc.append([data['Acc'][i] for i in data['Acc']])
mid_mid_temperature_precision.append([data['Precision'][i] for i in data['Precision']])
mid_mid_temperature_recall.append([data['Recall'][i] for i in data['Recall']])
f.close()
with open("log_AL/temperature_"+model+"_cifar100_known"+str(known)+"_init"+str(init)+"_batch1500_seed1_AV_temperature_unknown_T2.0_known_T2.0.pkl", 'rb') as f:
data = pickle.load(f)
max_max_temperature_acc.append([data['Acc'][i] for i in data['Acc']])
max_max_temperature_precision.append([data['Precision'][i] for i in data['Precision']])
max_max_temperature_recall.append([data['Recall'][i] for i in data['Recall']])
f.close()
with open("log_AL/temperature_"+model+"_cifar100_known"+str(known)+"_init"+str(init)+"_batch1500_seed1_AV_temperature_unknown_T0.5_known_T2.0.pkl", 'rb') as f:
data = pickle.load(f)
min_max_temperature_acc.append([data['Acc'][i] for i in data['Acc']])
min_max_temperature_precision.append([data['Precision'][i] for i in data['Precision']])
min_max_temperature_recall.append([data['Recall'][i] for i in data['Recall']])
f.close()
with open("log_AL/temperature_"+model+"_cifar100_known"+str(known)+"_init"+str(init)+"_batch1500_seed1_AV_temperature_unknown_T0.5_known_T0.5_modelB_T1.2.pkl", 'rb') as f:
data = pickle.load(f)
min_min_modelB_temperature_acc.append([data['Acc'][i] for i in data['Acc']])
min_min_modelB_temperature_precision.append([data['Precision'][i] for i in data['Precision']])
min_min_modelB_temperature_recall.append([data['Recall'][i] for i in data['Recall']])
f.close()
with open("log_AL/temperature_"+model+"_cifar100_known"+str(known)+"_init"+str(init)+"_batch1500_seed1_AV_temperature_unknown_T0.5_known_T0.5_modelB_T1.5.pkl", 'rb') as f:
data = pickle.load(f)
min_min_modelB_temperature_acc2.append([data['Acc'][i] for i in data['Acc']])
min_min_modelB_temperature_precision2.append([data['Precision'][i] for i in data['Precision']])
min_min_modelB_temperature_recall2.append([data['Recall'][i] for i in data['Recall']])
f.close()
x = list(range(10))
plt.figure()
plt.title("Recall")
plt.plot(x, np.array(max_min_temperature_recall).mean(0), label='unknown2.0_known0.5')
plt.plot(x, np.array(min_min_temperature_recall).mean(0), label='unknown0.5_known0.5')
plt.plot(x, np.array(min_min_modelB_temperature_recall).mean(0), label='unknown0.5_known0.5_modelB1.2')
plt.plot(x, np.array(min_min_modelB_temperature_recall2).mean(0), label='unknown0.5_known0.5_modelB1.5')
plt.plot(x, np.array(min_min_temperature_recall2).mean(0), label='unknown0.2_known0.2')
plt.plot(x, np.array(mid_mid_temperature_recall).mean(0), label='unknown1.0_known1.0')
plt.plot(x, np.array(max_max_temperature_recall).mean(0), label='unknown2.0_known2.0')
plt.plot(x, np.array(min_max_temperature_recall).mean(0), label='unknown0.5_known2.0')
plt.fill_between(x, np.array(max_min_temperature_recall).mean(0) - np.array(max_min_temperature_recall).std(0),
np.array(max_min_temperature_recall).mean(0) + np.array(max_min_temperature_recall).std(0),
color='r',
alpha=0.2)
plt.fill_between(x, np.array(min_min_temperature_recall).mean(0) - np.array(min_min_temperature_recall).std(0),
np.array(min_min_temperature_recall).mean(0) + np.array(min_min_temperature_recall).std(0),
color='b',
alpha=0.2)
plt.fill_between(x, np.array(min_min_temperature_recall2).mean(0) - np.array(min_min_temperature_recall2).std(0),
np.array(min_min_temperature_recall2).mean(0) + np.array(min_min_temperature_recall2).std(0),
color='m',
alpha=0.2)
plt.fill_between(x, np.array(mid_mid_temperature_recall).mean(0) - np.array(mid_mid_temperature_recall).std(0),
np.array(mid_mid_temperature_recall).mean(0) + np.array(mid_mid_temperature_recall).std(0),
color='k',
alpha=0.2)
plt.fill_between(x, np.array(max_max_temperature_recall).mean(0) - np.array(max_max_temperature_recall).std(0),
np.array(max_max_temperature_recall).mean(0) + np.array(max_max_temperature_recall).std(0),
color='g',
alpha=0.2)
plt.fill_between(x, np.array(min_max_temperature_recall).mean(0) - np.array(min_max_temperature_recall).std(0),
np.array(min_max_temperature_recall).mean(0) + np.array(min_max_temperature_recall).std(0),
color='y',
alpha=0.2)
plt.legend(loc='best')
plt.savefig("gifs/cifar100_diff_temperature_"+model+"_init"+str(init)+"_known"+str(known)+"_recall.png")
plt.show()
plt.figure()
plt.title("Precision")
plt.plot(x, np.array(max_min_temperature_precision).mean(0), label='unknown2.0_known0.5')
plt.plot(x, np.array(min_min_temperature_precision).mean(0), label='unknown0.5_known0.5')
plt.plot(x, np.array(min_min_modelB_temperature_precision).mean(0), label='unknown0.5_known0.5_modelB1.2')
plt.plot(x, np.array(min_min_modelB_temperature_precision2).mean(0), label='unknown0.5_known0.5_modelB1.5')
plt.plot(x, np.array(min_min_temperature_precision2).mean(0), label='unknown0.2_known0.2')
plt.plot(x, np.array(mid_mid_temperature_precision).mean(0), label='unknown1.0_known1.0')
plt.plot(x, np.array(max_max_temperature_precision).mean(0), label='unknown2.0_known2.0')
plt.plot(x, np.array(min_max_temperature_precision).mean(0), label='unknown0.5_known2.0')
plt.fill_between(x, np.array(max_min_temperature_precision).mean(0) - np.array(max_min_temperature_precision).std(0),
np.array(max_min_temperature_precision).mean(0) + np.array(max_min_temperature_precision).std(0),
color='r',
alpha=0.2)
plt.fill_between(x, np.array(min_min_temperature_precision).mean(0) - np.array(min_min_temperature_precision).std(0),
np.array(min_min_temperature_precision).mean(0) + np.array(min_min_temperature_precision).std(0),
color='b',
alpha=0.2)
plt.fill_between(x, np.array(min_min_temperature_precision2).mean(0) - np.array(min_min_temperature_precision2).std(0),
np.array(min_min_temperature_precision2).mean(0) + np.array(min_min_temperature_precision2).std(0),
color='m',
alpha=0.2)
plt.fill_between(x, np.array(mid_mid_temperature_precision).mean(0) - np.array(mid_mid_temperature_precision).std(0),
np.array(mid_mid_temperature_precision).mean(0) + np.array(mid_mid_temperature_precision).std(0),
color='k',
alpha=0.2)
plt.fill_between(x, np.array(max_max_temperature_precision).mean(0) - np.array(max_max_temperature_precision).std(0),
np.array(max_max_temperature_precision).mean(0) + np.array(max_max_temperature_precision).std(0),
color='g',
alpha=0.2)
plt.fill_between(x, np.array(min_max_temperature_precision).mean(0) - np.array(min_max_temperature_precision).std(0),
np.array(min_max_temperature_precision).mean(0) + np.array(min_max_temperature_precision).std(0),
color='y',
alpha=0.2)
plt.legend(loc='best')
plt.savefig("gifs/cifar100_diff_temperature_"+model+"_init"+str(init)+"_known"+str(known)+"_precision.png")
plt.show()
plt.figure()
plt.title("Acc")
plt.plot(x, np.array(max_min_temperature_acc).mean(0), label='unknown2.0_known0.5')
plt.plot(x, np.array(min_min_temperature_acc).mean(0), label='unknown0.5_known0.5')
plt.plot(x, np.array(min_min_modelB_temperature_acc).mean(0), label='unknown0.5_known0.5_modelB1.2')
plt.plot(x, np.array(min_min_modelB_temperature_acc2).mean(0), label='unknown0.5_known0.5_modelB1.5')
plt.plot(x, np.array(min_min_temperature_acc2).mean(0), label='unknown0.2_known0.2')
plt.plot(x, np.array(mid_mid_temperature_acc).mean(0), label='unknown1.0_known1.0')
plt.plot(x, np.array(max_max_temperature_acc).mean(0), label='unknown2.0_known2.0')
plt.plot(x, np.array(min_max_temperature_acc).mean(0), label='unknown0.5_known2.0')
plt.fill_between(x, np.array(max_min_temperature_acc).mean(0) - np.array(max_min_temperature_acc).std(0),
np.array(max_min_temperature_acc).mean(0) + np.array(max_min_temperature_acc).std(0),
color='r',
alpha=0.2)
plt.fill_between(x, np.array(min_min_temperature_acc).mean(0) - np.array(min_min_temperature_acc).std(0),
np.array(min_min_temperature_acc).mean(0) + np.array(min_min_temperature_acc).std(0),
color='b',
alpha=0.2)
plt.fill_between(x, np.array(min_min_temperature_acc2).mean(0) - np.array(min_min_temperature_acc2).std(0),
np.array(min_min_temperature_acc2).mean(0) + np.array(min_min_temperature_acc2).std(0),
color='m',
alpha=0.2)
plt.fill_between(x, np.array(mid_mid_temperature_acc).mean(0) - np.array(mid_mid_temperature_acc).std(0),
np.array(mid_mid_temperature_acc).mean(0) + np.array(mid_mid_temperature_acc).std(0),
color='k',
alpha=0.2)
plt.fill_between(x, np.array(max_max_temperature_acc).mean(0) - np.array(max_max_temperature_acc).std(0),
np.array(max_max_temperature_acc).mean(0) + np.array(max_max_temperature_acc).std(0),
color='g',
alpha=0.2)
plt.fill_between(x, np.array(min_max_temperature_acc).mean(0) - np.array(min_max_temperature_acc).std(0),
np.array(min_max_temperature_acc).mean(0) + np.array(min_max_temperature_acc).std(0),
color='y',
alpha=0.2)
plt.legend(loc='best')
plt.savefig("gifs/cifar100_diff_temperature_"+model+"_init"+str(init)+"_known"+str(known)+"_accuracy.png")
plt.show()
def plot_performance_cifar100():
known = 20
init = 8
model = "resnet18"
seeds = [1, 2, 3, 4]
random_acc = []
uncertainty_acc = []
AV_based_acc = []
max_av_acc = []
temperature_acc = []
random_precision = []
uncertainty_precision = []
AV_based_precision = []
max_av_precision = []
temperature_precision = []
random_recall = []
uncertainty_recall = []
AV_based_recall = []
max_av_recall = []
temperature_recall = []
for seed in seeds:
with open("log_AL/"+model+"_cifar100_known"+str(known)+"_init"+str(init)+"_batch1500_seed"+str(seed)+"_random.pkl", 'rb') as f:
data = pickle.load(f)
random_acc.append([data['Acc'][i] for i in data['Acc']])
random_precision.append([data['Precision'][i] for i in data['Precision']])
random_recall.append([data['Recall'][i] for i in data['Recall']])
f.close()
with open("log_AL/"+model+"_cifar100_known"+str(known)+"_init"+str(init)+"_batch1500_seed"+str(seed)+"_uncertainty.pkl", 'rb') as f:
data = pickle.load(f)
uncertainty_acc.append([data['Acc'][i] for i in data['Acc']])
uncertainty_precision.append([data['Precision'][i] for i in data['Precision']])
uncertainty_recall.append([data['Recall'][i] for i in data['Recall']])
f.close()
with open("log_AL/"+model+"_cifar100_known"+str(known)+"_init"+str(init)+"_batch1500_seed"+str(seed)+"_AV_based.pkl", 'rb') as f:
data = pickle.load(f)
AV_based_acc.append([data['Acc'][i] for i in data['Acc']])
AV_based_precision.append([data['Precision'][i] for i in data['Precision']])
AV_based_recall.append([data['Recall'][i] for i in data['Recall']])
f.close()
with open("log_AL/"+model+"_cifar100_known"+str(known)+"_init"+str(init)+"_batch1500_seed"+str(seed)+"_AV_uncertainty.pkl", 'rb') as f:
data = pickle.load(f)
max_av_acc.append([data['Acc'][i] for i in data['Acc']])
max_av_precision.append([data['Precision'][i] for i in data['Precision']])
max_av_recall.append([data['Recall'][i] for i in data['Recall']])
f.close()
with open("log_AL/temperature_"+model+"_cifar100_known"+str(known)+"_init"+str(init)+"_batch1500_seed"+str(seed)+"_AV_temperature_unknown_T0.5_known_T0.5_modelB_T1.0.pkl", 'rb') as f:
data = pickle.load(f)
temperature_acc.append([data['Acc'][i] for i in data['Acc']])
temperature_precision.append([data['Precision'][i] for i in data['Precision']])
temperature_recall.append([data['Recall'][i] for i in data['Recall']])
f.close()
x = list(range(10))
plt.figure()
plt.title("Recall")
plt.plot(x, np.array(random_recall).mean(0), label='random')
plt.plot(x, np.array(uncertainty_recall).mean(0), label='uncertainty')
plt.plot(x, np.array(AV_based_recall).mean(0), label='AV_based')
plt.plot(x, np.array(max_av_recall).mean(0), label='AV_uncertainty')
plt.plot(x, np.array(temperature_recall).mean(0), label='AV_temperature_framework')
plt.fill_between(x, np.array(random_recall).mean(0) - np.array(random_recall).std(0),
np.array(random_recall).mean(0) + np.array(random_recall).std(0),
color='b',
alpha=0.2)
plt.fill_between(x, np.array(uncertainty_recall).mean(0) - np.array(uncertainty_recall).std(0),
np.array(uncertainty_recall).mean(0) + np.array(uncertainty_recall).std(0),
color='r',
alpha=0.2)
plt.fill_between(x, np.array(AV_based_recall).mean(0) - np.array(AV_based_recall).std(0),
np.array(AV_based_recall).mean(0) + np.array(AV_based_recall).std(0),
color='g',
alpha=0.2)
plt.fill_between(x, np.array(max_av_recall).mean(0) - np.array(max_av_recall).std(0),
np.array(max_av_recall).mean(0) + np.array(max_av_recall).std(0),
color='y',
alpha=0.2)
plt.fill_between(x, np.array(temperature_recall).mean(0) - np.array(temperature_recall).std(0),
np.array(temperature_recall).mean(0) + np.array(temperature_recall).std(0),
color='k',
alpha=0.2)
plt.legend(loc='best')
plt.savefig("gifs/cifar100_"+model+"_init"+str(init)+"_known"+str(known)+"_recall.png")
plt.show()
plt.figure()
plt.title("Precision")
plt.plot(x, np.array(random_precision).mean(0), label='random')
plt.plot(x, np.array(uncertainty_precision).mean(0), label='uncertainty')
plt.plot(x, np.array(AV_based_precision).mean(0), label='AV_based')
plt.plot(x, np.array(max_av_precision).mean(0), label='AV_uncertainty')
plt.plot(x, np.array(temperature_precision).mean(0), label='AV_temperature_framework')
plt.fill_between(x, np.array(random_precision).mean(0) - np.array(random_precision).std(0),
np.array(random_precision).mean(0) + np.array(random_precision).std(0),
color='b',
alpha=0.2)
plt.fill_between(x, np.array(uncertainty_precision).mean(0) - np.array(uncertainty_precision).std(0),
np.array(uncertainty_precision).mean(0) + np.array(uncertainty_precision).std(0),
color='r',
alpha=0.2)
plt.fill_between(x, np.array(AV_based_precision).mean(0) - np.array(AV_based_precision).std(0),
np.array(AV_based_precision).mean(0) + np.array(AV_based_precision).std(0),
color='g',
alpha=0.2)
plt.fill_between(x, np.array(max_av_precision).mean(0) - np.array(max_av_precision).std(0),
np.array(max_av_precision).mean(0) + np.array(max_av_precision).std(0),
color='y',
alpha=0.2)
plt.fill_between(x, np.array(temperature_precision).mean(0) - np.array(temperature_precision).std(0),
np.array(temperature_precision).mean(0) + np.array(temperature_precision).std(0),
color='k',
alpha=0.2)
plt.legend(loc='best')
plt.savefig("gifs/cifar100_"+model+"_init"+str(init)+"_known"+str(known)+"_precision.png")
plt.show()
plt.figure()
plt.title("Acc")
plt.plot(x, np.array(random_acc).mean(0), label='random')
plt.plot(x, np.array(uncertainty_acc).mean(0), label='uncertainty')
plt.plot(x, np.array(AV_based_acc).mean(0), label='AV_based')
plt.plot(x, np.array(max_av_acc).mean(0), label='AV_uncertainty')
plt.plot(x, np.array(temperature_acc).mean(0), label='AV_temperature_framework')
plt.fill_between(x, np.array(random_acc).mean(0) - np.array(random_acc).std(0),
np.array(random_acc).mean(0) + np.array(random_acc).std(0),
color='b',
alpha=0.2)
plt.fill_between(x, np.array(uncertainty_acc).mean(0) - np.array(uncertainty_acc).std(0),
np.array(uncertainty_acc).mean(0) + np.array(uncertainty_acc).std(0),
color='r',
alpha=0.2)
plt.fill_between(x, np.array(AV_based_acc).mean(0) - np.array(AV_based_acc).std(0),
np.array(AV_based_acc).mean(0) + np.array(AV_based_acc).std(0),
color='g',
alpha=0.2)
plt.fill_between(x, np.array(max_av_acc).mean(0) - np.array(max_av_acc).std(0),
np.array(max_av_acc).mean(0) + np.array(max_av_acc).std(0),
color='y',
alpha=0.2)
plt.fill_between(x, np.array(temperature_acc).mean(0) - np.array(temperature_acc).std(0),
np.array(temperature_acc).mean(0) + np.array(temperature_acc).std(0),
color='k',
alpha=0.2)
plt.legend(loc='best')
plt.savefig("gifs/cifar100_"+model+"_init"+str(init)+"_known"+str(known)+"_accuracy.png")
plt.show()
def plot_performance_cifar10():
known = 8
init = 1
model = "resnet18"
seeds = [1, 2, 3, 4]
random_acc = []
uncertainty_acc = []
AV_based_acc = []
max_av_acc = []
temperature_acc = []
random_precision = []
uncertainty_precision = []
AV_based_precision = []
max_av_precision = []
temperature_precision = []
random_recall = []
uncertainty_recall = []
AV_based_recall = []
max_av_recall = []
temperature_recall = []
for seed in seeds:
with open("log_AL/"+model+"_cifar10_known"+str(known)+"_init"+str(init)+"_batch1500_seed"+str(seed)+"_random.pkl", 'rb') as f:
data = pickle.load(f)
random_acc.append([data['Acc'][i] for i in data['Acc']])
random_precision.append([data['Precision'][i] for i in data['Precision']])
random_recall.append([data['Recall'][i] for i in data['Recall']])
f.close()
with open("log_AL/"+model+"_cifar10_known"+str(known)+"_init"+str(init)+"_batch1500_seed"+str(seed)+"_uncertainty.pkl", 'rb') as f:
data = pickle.load(f)
uncertainty_acc.append([data['Acc'][i] for i in data['Acc']])
uncertainty_precision.append([data['Precision'][i] for i in data['Precision']])
uncertainty_recall.append([data['Recall'][i] for i in data['Recall']])
f.close()
with open("log_AL/temperature_"+model+"_cifar10_known"+str(known)+"_init"+str(init)+"_batch1500_seed"+str(seed)+"_AV_temperature_unknown_T0.5_known_T0.5_modelB_T1.0.pkl", 'rb') as f:
data = pickle.load(f)
temperature_acc.append([data['Acc'][i] for i in data['Acc']])
temperature_precision.append([data['Precision'][i] for i in data['Precision']])
temperature_recall.append([data['Recall'][i] for i in data['Recall']])
f.close()
with open("log_AL/"+model+"_cifar10_known"+str(known)+"_init"+str(init)+"_batch1500_seed"+str(seed)+"_AV_based.pkl", 'rb') as f:
data = pickle.load(f)
AV_based_acc.append([data['Acc'][i] for i in data['Acc']])
AV_based_precision.append([data['Precision'][i] for i in data['Precision']])
AV_based_recall.append([data['Recall'][i] for i in data['Recall']])
f.close()
x = list(range(10))
plt.figure()
plt.title("Recall")
plt.plot(x, np.array(random_recall).mean(0), label='random')
plt.plot(x, np.array(AV_based_recall).mean(0), label='AV_based')
plt.plot(x, np.array(uncertainty_recall).mean(0), label='uncertainty')
plt.plot(x, np.array(temperature_recall).mean(0), label='AV_temperature_framework')
plt.fill_between(x, np.array(random_recall).mean(0) - np.array(random_recall).std(0),
np.array(random_recall).mean(0) + np.array(random_recall).std(0),
color='b',
alpha=0.2)
plt.fill_between(x, np.array(AV_based_recall).mean(0) - np.array(AV_based_recall).std(0),
np.array(AV_based_recall).mean(0) + np.array(AV_based_recall).std(0),
color='g',
alpha=0.2)
plt.fill_between(x, np.array(uncertainty_recall).mean(0) - np.array(uncertainty_recall).std(0),
np.array(uncertainty_recall).mean(0) + np.array(uncertainty_recall).std(0),
color='r',
alpha=0.2)
plt.fill_between(x, np.array(temperature_recall).mean(0) - np.array(temperature_recall).std(0),
np.array(temperature_recall).mean(0) + np.array(temperature_recall).std(0),
color='k',
alpha=0.2)
plt.legend(loc='best')
plt.savefig("gifs/cifar10_"+model+"_init"+str(init)+"_known"+str(known)+"_recall.png")
plt.show()
plt.figure()
plt.title("Precision")
plt.plot(x, np.array(random_precision).mean(0), label='random')
plt.plot(x, np.array(AV_based_precision).mean(0), label='AV_based')
plt.plot(x, np.array(uncertainty_precision).mean(0), label='uncertainty')
plt.plot(x, np.array(temperature_precision).mean(0), label='AV_temperature_framework')
plt.fill_between(x, np.array(random_precision).mean(0) - np.array(random_precision).std(0),
np.array(random_precision).mean(0) + np.array(random_precision).std(0),
color='b',
alpha=0.2)
plt.fill_between(x, np.array(AV_based_precision).mean(0) - np.array(AV_based_precision).std(0),
np.array(AV_based_precision).mean(0) + np.array(AV_based_precision).std(0),
color='g',
alpha=0.2)
plt.fill_between(x, np.array(uncertainty_precision).mean(0) - np.array(uncertainty_precision).std(0),
np.array(uncertainty_precision).mean(0) + np.array(uncertainty_precision).std(0),
color='r',
alpha=0.2)
plt.fill_between(x, np.array(temperature_precision).mean(0) - np.array(temperature_precision).std(0),
np.array(temperature_precision).mean(0) + np.array(temperature_precision).std(0),
color='k',
alpha=0.2)
plt.legend(loc='best')
plt.savefig("gifs/cifar10_"+model+"_init"+str(init)+"_known"+str(known)+"_precision.png")
plt.show()
plt.figure()
plt.title("Acc")
plt.plot(x, np.array(random_acc).mean(0), label='random')
plt.plot(x, np.array(AV_based_acc).mean(0), label='AV_based')
plt.plot(x, np.array(uncertainty_acc).mean(0), label='uncertainty')
plt.plot(x, np.array(temperature_acc).mean(0), label='AV_temperature_framework')
plt.fill_between(x, np.array(random_acc).mean(0) - np.array(random_acc).std(0),
np.array(random_acc).mean(0) + np.array(random_acc).std(0),
color='b',
alpha=0.2)
plt.fill_between(x, np.array(AV_based_acc).mean(0) - np.array(AV_based_acc).std(0),
np.array(AV_based_acc).mean(0) + np.array(AV_based_acc).std(0),
color='g',
alpha=0.2)
plt.fill_between(x, np.array(uncertainty_acc).mean(0) - np.array(uncertainty_acc).std(0),
np.array(uncertainty_acc).mean(0) + np.array(uncertainty_acc).std(0),
color='r',
alpha=0.2)
plt.fill_between(x, np.array(temperature_acc).mean(0) - np.array(temperature_acc).std(0),
np.array(temperature_acc).mean(0) + np.array(temperature_acc).std(0),
color='k',
alpha=0.2)
plt.legend(loc='best')
plt.savefig("gifs/cifar10_"+model+"_init"+str(init)+"_known"+str(known)+"_accuracy.png")
plt.show()
def plot_distribution():
with open("pkl/center_result.pkl", 'rb') as f:
data = pickle.load(f)
f.close()
known_S_ij = data['known_S']
unknown_S_ij = data['unknown_S']
known_M_ij = data['known_M']
unknown_M_ij = data['unknown_M']
for i in range(7):
# i = 23
known_data = known_S_ij[i]
unknown_data = unknown_S_ij[i]
plt.hist(known_data, bins=40, color="#FF0000", alpha=.9)
plt.hist(unknown_data, bins=40, color="#C1F320", alpha=.5)
plt.savefig("log/AV_CentorLoss_result_mini/class_"+str(i)+".png")
plt.show()
# print(ca)
plot_performance_cifar100()
plot_performance_cifar10()