-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw_traincurve.py
65 lines (53 loc) · 2.66 KB
/
draw_traincurve.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
import matplotlib.pyplot as plt
import numpy as np
files = ['batch_size_32_epochs_30_lr_0.01_enable_cuda_True_L1norm_False_simpleNet_True_activation_relu_train_curve_True_optimization_SGD_exponent_6_mantissa_5.txt',
'batch_size_32_epochs_30_lr_0.01_enable_cuda_True_L1norm_False_simpleNet_True_activation_relu_train_curve_True_optimization_SGD_exponent_7_mantissa_4.txt',
'batch_size_32_epochs_30_lr_0.01_enable_cuda_True_L1norm_False_simpleNet_True_activation_relu_train_curve_True_optimization_SGD_exponent_8_mantissa_3.txt',
'batch_size_32_epochs_30_lr_0.01_enable_cuda_True_L1norm_False_simpleNet_True_activation_relu_train_curve_True_optimization_SGD_exponent_9_mantissa_2.txt',
'batch_size_32_epochs_30_lr_0.01_enable_cuda_True_L1norm_False_simpleNet_True_activation_relu_train_curve_True_optimization_SGD_exponent_10_mantissa_1.txt',
'batch_size_32_epochs_30_lr_0.01_enable_cuda_True_L1norm_False_simpleNet_True_activation_relu_train_curve_True_optimization_SGD_exponent_2_mantissa_3.txt',
'batch_size_32_epochs_30_lr_0.01_enable_cuda_True_L1norm_False_simpleNet_True_activation_relu_train_curve_True_optimization_SGD_exponent_3_mantissa_2.txt',
'batch_size_32_epochs_30_lr_0.01_enable_cuda_True_L1norm_False_simpleNet_True_activation_relu_train_curve_True_optimization_SGD_exponent_4_mantissa_1.txt']
for filename in files:
filename = 'result/' + filename
loss = []
train = []
test = []
with open(filename, 'r') as f:
args = f.readline()
loss = f.readline()
train = f.readline()
test = f.readline()
# print(args)
# print(loss)
# print(train)
# print(test)
e = args.split('exponent')[1].split(',')[0].strip().split()[1]
m = args.split('mantissa')[1].split(',')[0].strip().split()[1].split('}')[0]
ofilename = 'traincurve/' + e + '_' + m + '_FullBN'+'.png'
loss = loss.split('[')[1].split(']')[0].split(', ')
train = train.split('[')[1].split(']')[0].split(', ')
test = test.split('[')[1].split(']')[0].split(', ')
loss = [float(i) for i in loss]
train = [100.*float(i) for i in train]
test = [100.*float(i) for i in test]
x = np.arange(0, len(loss), 1, dtype=int)
# print(x)
fig, ax1 = plt.subplots()
ax2 = ax1.twinx()
ax1.plot(x, loss, 'r-', label='loss')
ax2.plot(x, train, 'b-', label='train')
ax2.plot(x, test, 'g-', label='test')
ax1.set_xlabel('epoch')
ax1.set_ylabel('loss')
ax2.set_ylabel('accuracy')
#ax1 y limit
ax1.set_ylim([0, 3])
plt.title('(1, ' + e + ', ' + m + ')')
#lengend
ax1.legend(loc='upper left')
ax2.legend(loc='upper right')
# plt.ylabel('loss')
plt.savefig(ofilename)
# plt.show()
# plt.close()