-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_curve.py
54 lines (42 loc) · 1.65 KB
/
plot_curve.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
#!/usr/bin/env python
import matplotlib.pyplot as plt
import numpy as np
import argparse
if __name__ == '__main__':
ap = argparse.ArgumentParser()
ap.add_argument("-file", "--file", required=True, help="path to the training log file")
args = vars(ap.parse_args())
file_path = args["file"]
fileptr = open(file_path,'r')
log = fileptr.readlines()
######################### Plot training error #########################
linesWithLoss = [x for x in log if x.find(': loss =') > 0]
#print linesWithLoss
loss = np.array([float(x.split()[10]) for x in linesWithLoss])
filt_size = 20
smooth_loss = np.convolve(loss, np.ones(filt_size)/filt_size,mode='valid')
each_step = 20 #iteration
iterations = each_step*np.arange(loss.size)
loss = loss[0:smooth_loss.size]
iterations = iterations[0:smooth_loss.size]
########################################################################
######################### Plot training accuracy #######################
lineswithacc = [y for y in log if y.find('#0: accuracy =') > 0]
acc = np.array([float(y.split()[10]) for y in lineswithacc])
smooth_acc = np.convolve(acc, np.ones(filt_size)/filt_size, mode = 'valid')
iters = each_step*np.arange(acc.size)
acc = acc[0: smooth_acc.size]
iters = iters[0:smooth_acc.size]
##########################################################################
plt.figure(1)
plt.plot(iterations,loss,hold=True)
#plt.plot(iterations,smooth_loss,hold=True)
plt.xlabel('Iterations')
plt.ylabel('Training error')
plt.show()
plt.figure(2)
plt.plot(iters, acc, hold = True)
plt.plot(iters, smooth_acc, hold= True)
plt.xlabel('Iterations')
plt.ylabel('Training Accuracy')
plt.show()