jie1 commited on
Commit
efa65be
·
1 Parent(s): a41df2a

Upload Plt.py

Browse files
Files changed (1) hide show
  1. Plt.py +35 -0
Plt.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from matplotlib import pyplot as plt
2
+
3
+
4
+ def Plt(file):
5
+ filereader = open(file.name, 'r')
6
+ # 可视化
7
+ Loss_list = []
8
+ Accuracy_list = []
9
+
10
+ for line in filereader.readlines():
11
+ if line[0:4] == "loss":
12
+ list = line.split()
13
+ # print(list[1])
14
+ Loss_list.append(float(list[1]))
15
+ Accuracy_list.append(float(list[3]))
16
+
17
+ print(Loss_list)
18
+ length = len(Loss_list)
19
+ x1 = range(0, length)
20
+ x2 = range(0, length)
21
+ y1 = Accuracy_list
22
+ # y2 = Loss_list[4:]
23
+ y2 = Loss_list
24
+ plt.subplot(2, 1, 1)
25
+ plt.plot(x1, y1)
26
+ plt.title('Test accuracy vs. epoches')
27
+ plt.ylabel('Test accuracy')
28
+ plt.subplot(2, 1, 2)
29
+ plt.plot(x2, y2)
30
+ plt.xlabel('Test loss vs. epoches')
31
+ plt.ylabel('Test loss')
32
+ plt.savefig("result.jpg")
33
+ # plt.show()
34
+ return "result.jpg"
35
+